Skip to content

Commit a5e4c51

Browse files
committed
fix(websockets): persist websockets until they're closed
1 parent f6e7ba3 commit a5e4c51

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/nativescript-websockets/websocket.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const CLOSED = 3;
2323

2424
const CLOSE_NORMAL = 1000;
2525

26+
const openWebsockets = new Set<WebSocketPolyfill>();
27+
2628
// const WEBSOCKET_EVENTS = ['close', 'error', 'message', 'open'];
2729

2830
// type WebSocketEventDefinitions = {
@@ -118,6 +120,7 @@ export class WebSocket implements WebSocketPolyfill {
118120
// );
119121
this._registerEvents();
120122
this.nativeBridge.connect(url, protocols, { headers });
123+
openWebsockets.add(this);
121124
// NativeWebSocketModule.connect(url, protocols, {headers}, this._socketId);
122125
}
123126
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void {
@@ -265,6 +268,7 @@ export class WebSocket implements WebSocketPolyfill {
265268
}
266269
_websocketClosed(code: number, reason: string, wasClean: boolean) {
267270
this.readyState = this.CLOSED;
271+
openWebsockets.delete(this);
268272
this.dispatchEvent(
269273
new WebSocketEvent('close', {
270274
code: code,
@@ -279,6 +283,7 @@ export class WebSocket implements WebSocketPolyfill {
279283
// _websocketPong(pongPayload: NSData) {}
280284
_websocketFailed(error: string) {
281285
this.readyState = this.CLOSED;
286+
openWebsockets.delete(this);
282287
this.dispatchEvent(
283288
new WebSocketEvent('error', {
284289
message: error,

0 commit comments

Comments
 (0)