Skip to content

Commit 2a041ec

Browse files
committed
prettier
1 parent e99f835 commit 2a041ec

File tree

6 files changed

+59
-51
lines changed

6 files changed

+59
-51
lines changed

backend/instance.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ export class Instances {
134134
instance.webXdc.sendRealtimeData(parsed.data);
135135
} else if (isSetRealtimeListenerMessage(parsed)) {
136136
instance.webXdc.connectRealtime((data) => {
137-
return broadcast(
138-
wss,
139-
JSON.stringify({ type: "realtime", data }),
140-
);
137+
return broadcast(wss, JSON.stringify({ type: "realtime", data }));
141138
});
142139
} else if (isSetUpdateListenerMessage(parsed)) {
143140
instance.webXdc.connect(

backend/message.test.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,22 @@ test("Send realtime", () => {
6262
const client0Heard: string[] = [];
6363
const client1Heard: string[] = [];
6464

65-
const decoder = new TextDecoder()
66-
client0.connectRealtime((data) => { client0Heard.push(decoder.decode(data)); return true })
67-
client1.connectRealtime((data) => { client1Heard.push(decoder.decode(data)); return true })
65+
const decoder = new TextDecoder();
66+
client0.connectRealtime((data) => {
67+
client0Heard.push(decoder.decode(data));
68+
return true;
69+
});
70+
client1.connectRealtime((data) => {
71+
client1Heard.push(decoder.decode(data));
72+
return true;
73+
});
6874

69-
const encoder = new TextEncoder()
75+
const encoder = new TextEncoder();
7076

71-
client0.sendRealtimeData(new Uint8Array(encoder.encode("hi")))
77+
client0.sendRealtimeData(new Uint8Array(encoder.encode("hi")));
7278

73-
expect(client1Heard).toMatchObject([
74-
"hi"
75-
])
76-
expect(client0Heard).toMatchObject([])
79+
expect(client1Heard).toMatchObject(["hi"]);
80+
expect(client0Heard).toMatchObject([]);
7781
});
7882

7983
test("distribute to self and other", () => {

backend/message.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Client implements WebXdcMulti {
5151
this.processor.distribute(this.id, update);
5252
}
5353

54-
sendRealtimeData(data: Uint8Array){
54+
sendRealtimeData(data: Uint8Array) {
5555
this.processor.distributeRealtime(this.id, data);
5656
}
5757

sim/create.ts

+33-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { Webxdc, ReceivedStatusUpdate, RealtimeListener as WebxdcRealtimeListener } from "@webxdc/types";
1+
import {
2+
Webxdc,
3+
ReceivedStatusUpdate,
4+
RealtimeListener as WebxdcRealtimeListener,
5+
} from "@webxdc/types";
26
type UpdatesMessage = {
37
type: "updates";
48
updates: ReceivedStatusUpdate<any>[];
@@ -54,13 +58,13 @@ type Log = (...args: any[]) => void;
5458

5559
export 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

96100
export 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
},

sim/webxdc.test.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ class FakeTransport implements Transport {
3333
this.client.sendRealtimeData(data.data);
3434
} else if (data.type === "setRealtimeListener") {
3535
this.client.connectRealtime((data) => {
36-
if (this.messageCallback != null) {
37-
this.messageCallback({
38-
type: "realtime",
39-
data
40-
});
41-
}
42-
return true;
43-
})
44-
36+
if (this.messageCallback != null) {
37+
this.messageCallback({
38+
type: "realtime",
39+
data,
40+
});
41+
}
42+
return true;
43+
});
4544
} else if (data.type === "setUpdateListener") {
4645
this.client.connect(
4746
(updates) => {

sim/webxdc.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export class DevServerTransport implements Transport {
4040

4141
this.socket.addEventListener("message", listener);
4242
}
43-
44-
hasMessageListener(){
45-
return this.messageListener !== null
43+
44+
hasMessageListener() {
45+
return this.messageListener !== null;
4646
}
4747

4848
onConnect(callback: TransportConnectCallback): void {

0 commit comments

Comments
 (0)