Skip to content

Commit 1b23a8e

Browse files
committed
Fix WebSocket race condition by adding readyState check before send()
Signed-off-by: Benjamin Frueh <[email protected]>
1 parent 18a4bc2 commit 1b23a8e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function listen(name: string, handler: (string, any) => void, options: No
5757
}
5858

5959
window._notify_push_listeners[name].push(handler);
60-
if (window._notify_push_ws !== null && typeof window._notify_push_ws === "object") {
60+
if (window._notify_push_ws !== null && typeof window._notify_push_ws === "object" && window._notify_push_ws.readyState === WebSocket.OPEN) {
6161
window._notify_push_ws.send('listen ' + name);
6262
} else {
6363
setupSocket(options);

0 commit comments

Comments
 (0)