@@ -23,6 +23,8 @@ const CLOSED = 3;
23
23
24
24
const CLOSE_NORMAL = 1000 ;
25
25
26
+ const openWebsockets = new Set < WebSocketPolyfill > ( ) ;
27
+
26
28
// const WEBSOCKET_EVENTS = ['close', 'error', 'message', 'open'];
27
29
28
30
// type WebSocketEventDefinitions = {
@@ -118,6 +120,7 @@ export class WebSocket implements WebSocketPolyfill {
118
120
// );
119
121
this . _registerEvents ( ) ;
120
122
this . nativeBridge . connect ( url , protocols , { headers } ) ;
123
+ openWebsockets . add ( this ) ;
121
124
// NativeWebSocketModule.connect(url, protocols, {headers}, this._socketId);
122
125
}
123
126
addEventListener ( type : string , callback : EventListenerOrEventListenerObject | null , options ?: boolean | AddEventListenerOptions ) : void {
@@ -265,6 +268,7 @@ export class WebSocket implements WebSocketPolyfill {
265
268
}
266
269
_websocketClosed ( code : number , reason : string , wasClean : boolean ) {
267
270
this . readyState = this . CLOSED ;
271
+ openWebsockets . delete ( this ) ;
268
272
this . dispatchEvent (
269
273
new WebSocketEvent ( 'close' , {
270
274
code : code ,
@@ -279,6 +283,7 @@ export class WebSocket implements WebSocketPolyfill {
279
283
// _websocketPong(pongPayload: NSData) {}
280
284
_websocketFailed ( error : string ) {
281
285
this . readyState = this . CLOSED ;
286
+ openWebsockets . delete ( this ) ;
282
287
this . dispatchEvent (
283
288
new WebSocketEvent ( 'error' , {
284
289
message : error ,
0 commit comments