Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 280d5b6

Browse files
committedDec 16, 2024
fixes & better logs
1 parent a41702f commit 280d5b6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed
 

‎sim/create.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ export function createWebXdc(
103103
const webXdc: Webxdc<any> = {
104104
sendUpdate: (update) => {
105105
transport.send({ type: "sendUpdate", update });
106-
log("send", { update });
106+
log("send update", { update });
107107
},
108108
setUpdateListener: (listener, serial = 0): Promise<void> => {
109109
transport.onMessage((message) => {
110110
if (isUpdatesMessage(message)) {
111-
log("recv", message.updates);
111+
log("recv update", message.updates);
112112
for (const update of message.updates) {
113113
listener(update);
114114
}
@@ -263,20 +263,33 @@ export function createWebXdc(
263263
}
264264
})
265265
}
266+
let should_create = false
266267
realtime = new RealtimeListener(
267268
() => { },
268269
() => {
269-
transport.send({ type: "setRealtimeListener" });
270+
should_create = true
270271
},
271272
() => {
272-
realtime = null;
273+
should_create = false
274+
realtime = null
273275
},
274276
);
275277
transport.onConnect(() => {
276-
realtime!.sendHook = (data) => {
278+
if (!realtime) {
279+
return
280+
}
281+
282+
if (should_create) {
283+
transport.send({ type: "setRealtimeListener" });
284+
}
285+
286+
realtime.sendHook = (data) => {
277287
transport.send({ type: "sendRealtime", data });
278288
log("send realtime", { data });
279289
};
290+
realtime.setListenerHook = () => {
291+
transport.send({ type: "setRealtimeListener" });
292+
}
280293
});
281294
return realtime;
282295
},

0 commit comments

Comments
 (0)
Please sign in to comment.