1- import { Webxdc , ReceivedStatusUpdate , RealtimeListener as WebxdcRealtimeListener } from "@webxdc/types" ;
1+ import {
2+ Webxdc ,
3+ ReceivedStatusUpdate ,
4+ RealtimeListener as WebxdcRealtimeListener ,
5+ } from "@webxdc/types" ;
26type UpdatesMessage = {
37 type : "updates" ;
48 updates : ReceivedStatusUpdate < any > [ ] ;
@@ -54,13 +58,13 @@ type Log = (...args: any[]) => void;
5458
5559export class RealtimeListener implements WebxdcRealtimeListener {
5660 private trashed = false ;
57- private listener : ( data : Uint8Array ) => void = ( ) => { } ;
61+ private listener : ( data : Uint8Array ) => void = ( ) => { } ;
5862
5963 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+ ) { }
6468
6569 is_trashed ( ) : boolean {
6670 return this . trashed ;
@@ -95,7 +99,7 @@ export class RealtimeListener implements WebxdcRealtimeListener {
9599
96100export function createWebXdc (
97101 transport : Transport ,
98- log : Log = ( ) => { } ,
102+ log : Log = ( ) => { } ,
99103) : Webxdc < any > {
100104 let resolveUpdateListenerPromise : ( ( ) => void ) | null = null ;
101105 let realtime : RealtimeListener | null = null ;
@@ -118,7 +122,7 @@ export function createWebXdc(
118122 }
119123 } else if ( isRealtimeMessage ( message ) ) {
120124 if ( realtime === null ) {
121- return
125+ return ;
122126 }
123127 // Conversion to any because the actual data is a dict representation of Uint8Array
124128 // This is due to JSON.stringify conversion.
@@ -201,11 +205,13 @@ export function createWebXdc(
201205 ) ;
202206 }
203207 }
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
206212 ? `${ content . file . name } - ${ base64Content . length } bytes`
207213 : "No File"
208- } `;
214+ } `;
209215 if ( content . file ) {
210216 const confirmed = confirm (
211217 msg + "\n\nDownload the file in the browser instead?" ,
@@ -250,46 +256,48 @@ export function createWebXdc(
250256
251257 joinRealtimeChannel : ( ) => {
252258 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,
254260 // 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
256262 // realtime data.
257263 transport . onMessage ( ( message ) => {
258264 if ( isRealtimeMessage ( message ) ) {
259265 if ( realtime === null ) {
260- return
266+ return ;
261267 }
262- realtime ! . receive ( new Uint8Array ( Object . values ( message . data as any ) ) ) ;
268+ realtime ! . receive (
269+ new Uint8Array ( Object . values ( message . data as any ) ) ,
270+ ) ;
263271 }
264- } )
272+ } ) ;
265273 }
266- let should_create = false
274+ let should_create = false ;
267275 realtime = new RealtimeListener (
268- ( ) => { } ,
276+ ( ) => { } ,
269277 ( ) => {
270- should_create = true
278+ should_create = true ;
271279 } ,
272280 ( ) => {
273- should_create = false
274- realtime = null
281+ should_create = false ;
282+ realtime = null ;
275283 } ,
276284 ) ;
277285 transport . onConnect ( ( ) => {
278286 if ( ! realtime ) {
279- return
287+ return ;
280288 }
281-
289+
282290 if ( should_create ) {
283291 transport . send ( { type : "setRealtimeListener" } ) ;
284292 }
285-
293+
286294 realtime . sendHook = ( data ) => {
287295 transport . send ( { type : "sendRealtime" , data } ) ;
288296 log ( "send realtime" , { data } ) ;
289297 } ;
290298 realtime . setListenerHook = ( ) => {
291299 transport . send ( { type : "setRealtimeListener" } ) ;
292- }
300+ } ;
293301 } ) ;
294302 return realtime ;
295303 } ,
0 commit comments