Skip to content

Commit 44677da

Browse files
committed
🐛 Caused errors to console when immediately disconnecting sockets
1 parent ec533e1 commit 44677da

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

socket.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@ const version = "4.2.0";
2121

2222
export async function socketIO() {
2323
const io = await importSocketIO();
24-
return io("https://scrapbox.io", {
24+
const socket = io("https://scrapbox.io", {
2525
reconnectionDelay: 5000,
2626
transports: ["websocket"],
2727
});
28+
29+
await new Promise<void>((resolve, reject) => {
30+
const onDisconnect = (reason: Socket.DisconnectReason) => reject(reason);
31+
socket.once("connect", () => {
32+
socket.off("disconnect", onDisconnect);
33+
resolve();
34+
});
35+
socket.once("disconnect", onDisconnect);
36+
});
37+
return socket;
2838
}
2939

3040
function importSocketIO(): Promise<Window["io"]> {

0 commit comments

Comments
 (0)