@resolveio/client-lib-core 15.1.4 → 15.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -242,23 +242,25 @@ class SocketService {
242
242
  this.startPinging();
243
243
  };
244
244
  this.onCloseHandler = (event) => {
245
- if (this.timeout) {
246
- clearTimeout(this.timeout);
245
+ if (this.ws && this.readyState !== WebSocket.CLOSED) {
246
+ if (this.timeout) {
247
+ clearTimeout(this.timeout);
248
+ }
249
+ this.timeout = null;
250
+ this.ws.removeEventListener('open', this.onOpenHandler);
251
+ this.ws.removeEventListener('close', this.onCloseHandler);
252
+ this.ws.removeEventListener('message', this.onMessageHandler);
253
+ this.ws.removeEventListener('error', this.onErrorHandler);
254
+ this.ws = null;
255
+ this.readyState = WebSocket.CLOSED;
256
+ this.readyState$.next(this.readyState);
257
+ this.log(new Date(), 'WS', 'onclose', this.url);
258
+ this.onclose(event);
259
+ setTimeout(() => {
260
+ this.connect();
261
+ }, this.reconnectInterval);
262
+ this.stopPinging();
247
263
  }
248
- this.timeout = null;
249
- this.ws.removeEventListener('open', this.onOpenHandler);
250
- this.ws.removeEventListener('close', this.onCloseHandler);
251
- this.ws.removeEventListener('message', this.onMessageHandler);
252
- this.ws.removeEventListener('error', this.onErrorHandler);
253
- this.ws = null;
254
- this.readyState = WebSocket.CLOSED;
255
- this.readyState$.next(this.readyState);
256
- this.log(new Date(), 'WS', 'onclose', this.url);
257
- this.onclose(event);
258
- setTimeout(() => {
259
- this.connect();
260
- }, this.reconnectInterval);
261
- this.stopPinging();
262
264
  };
263
265
  this.onMessageHandler = (event) => {
264
266
  if (event.data === 'pong') {