1
- import { Webxdc , ReceivedStatusUpdate , RealtimeListener as WebxdcRealtimeListener } from "@webxdc/types" ;
1
+ import {
2
+ Webxdc ,
3
+ ReceivedStatusUpdate ,
4
+ RealtimeListener as WebxdcRealtimeListener ,
5
+ } from "@webxdc/types" ;
2
6
type UpdatesMessage = {
3
7
type : "updates" ;
4
8
updates : ReceivedStatusUpdate < any > [ ] ;
@@ -54,13 +58,13 @@ type Log = (...args: any[]) => void;
54
58
55
59
export class RealtimeListener implements WebxdcRealtimeListener {
56
60
private trashed = false ;
57
- private listener : ( data : Uint8Array ) => void = ( ) => { } ;
61
+ private listener : ( data : Uint8Array ) => void = ( ) => { } ;
58
62
59
63
constructor (
60
- public sendHook : ( data : Uint8Array ) => void = ( ) => { } ,
61
- public setListenerHook : ( ) => void = ( ) => { } ,
62
- private leaveHook : ( ) => void = ( ) => { } ,
63
- ) { }
64
+ public sendHook : ( data : Uint8Array ) => void = ( ) => { } ,
65
+ public setListenerHook : ( ) => void = ( ) => { } ,
66
+ private leaveHook : ( ) => void = ( ) => { } ,
67
+ ) { }
64
68
65
69
is_trashed ( ) : boolean {
66
70
return this . trashed ;
@@ -95,7 +99,7 @@ export class RealtimeListener implements WebxdcRealtimeListener {
95
99
96
100
export function createWebXdc (
97
101
transport : Transport ,
98
- log : Log = ( ) => { } ,
102
+ log : Log = ( ) => { } ,
99
103
) : Webxdc < any > {
100
104
let resolveUpdateListenerPromise : ( ( ) => void ) | null = null ;
101
105
let realtime : RealtimeListener | null = null ;
@@ -118,7 +122,7 @@ export function createWebXdc(
118
122
}
119
123
} else if ( isRealtimeMessage ( message ) ) {
120
124
if ( realtime === null ) {
121
- return
125
+ return ;
122
126
}
123
127
// Conversion to any because the actual data is a dict representation of Uint8Array
124
128
// This is due to JSON.stringify conversion.
@@ -201,11 +205,13 @@ export function createWebXdc(
201
205
) ;
202
206
}
203
207
}
204
- const msg = `The app would now close and the user would select a chat to send this message:\nText: ${ content . text ? `"${ content . text } "` : "No Text"
205
- } \nFile: ${ content . file
208
+ const msg = `The app would now close and the user would select a chat to send this message:\nText: ${
209
+ content . text ? `"${ content . text } "` : "No Text"
210
+ } \nFile: ${
211
+ content . file
206
212
? `${ content . file . name } - ${ base64Content . length } bytes`
207
213
: "No File"
208
- } `;
214
+ } `;
209
215
if ( content . file ) {
210
216
const confirmed = confirm (
211
217
msg + "\n\nDownload the file in the browser instead?" ,
@@ -250,46 +256,48 @@ export function createWebXdc(
250
256
251
257
joinRealtimeChannel : ( ) => {
252
258
if ( ! transport . hasMessageListener ( ) ) {
253
- // we can only have one message listener with the current implementation,
259
+ // we can only have one message listener with the current implementation,
254
260
// so we need to set it here to receive realtime data. When `setUpdateListener`
255
- // is called, the callback is overwritten but the new value also looks for
261
+ // is called, the callback is overwritten but the new value also looks for
256
262
// realtime data.
257
263
transport . onMessage ( ( message ) => {
258
264
if ( isRealtimeMessage ( message ) ) {
259
265
if ( realtime === null ) {
260
- return
266
+ return ;
261
267
}
262
- realtime ! . receive ( new Uint8Array ( Object . values ( message . data as any ) ) ) ;
268
+ realtime ! . receive (
269
+ new Uint8Array ( Object . values ( message . data as any ) ) ,
270
+ ) ;
263
271
}
264
- } )
272
+ } ) ;
265
273
}
266
- let should_create = false
274
+ let should_create = false ;
267
275
realtime = new RealtimeListener (
268
- ( ) => { } ,
276
+ ( ) => { } ,
269
277
( ) => {
270
- should_create = true
278
+ should_create = true ;
271
279
} ,
272
280
( ) => {
273
- should_create = false
274
- realtime = null
281
+ should_create = false ;
282
+ realtime = null ;
275
283
} ,
276
284
) ;
277
285
transport . onConnect ( ( ) => {
278
286
if ( ! realtime ) {
279
- return
287
+ return ;
280
288
}
281
-
289
+
282
290
if ( should_create ) {
283
291
transport . send ( { type : "setRealtimeListener" } ) ;
284
292
}
285
-
293
+
286
294
realtime . sendHook = ( data ) => {
287
295
transport . send ( { type : "sendRealtime" , data } ) ;
288
296
log ( "send realtime" , { data } ) ;
289
297
} ;
290
298
realtime . setListenerHook = ( ) => {
291
299
transport . send ( { type : "setRealtimeListener" } ) ;
292
- }
300
+ } ;
293
301
} ) ;
294
302
return realtime ;
295
303
} ,
0 commit comments