Skip to content

Commit ace305d

Browse files
authored
fix: window.addEventListener breaks node compatibility (#148)
* fix: window.addEventListener breaks node compatibility * more concise check
1 parent 7dd849e commit ace305d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

source/simple_socketio.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,11 @@ export default class SimpleSocketIOClient {
250250
this.reconnecting = false;
251251
this.webSocket?.close();
252252
this.webSocket = undefined;
253-
window.addEventListener("online", this.attemptReconnect.bind(this), {
254-
once: true,
255-
});
253+
if (window?.addEventListener) {
254+
window.addEventListener("online", this.attemptReconnect.bind(this), {
255+
once: true,
256+
});
257+
}
256258
this.reconnect();
257259
}
258260
/**

0 commit comments

Comments
 (0)