@resolveio/client-lib-core 15.1.4 → 15.1.6

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') {
@@ -284,13 +286,13 @@ class SocketService {
284
286
  this.connect();
285
287
  }
286
288
  connect() {
287
- if (!this.ws && this._storage.get('accessToken')) {
289
+ if (!this.ws && this.readyState !== WebSocket.CONNECTING && this._storage.get('accessToken')) {
290
+ this.readyState = WebSocket.CONNECTING;
291
+ this.readyState$.next(this.readyState);
288
292
  if (this.timeout) {
289
293
  clearTimeout(this.timeout);
290
294
  }
291
295
  this.ws = new WebSocket(this.url, this.protocols);
292
- this.readyState = WebSocket.CONNECTING;
293
- this.readyState$.next(this.readyState);
294
296
  this.onconnecting();
295
297
  this.log(new Date(), 'WS', 'attempt-connect', this.url);
296
298
  this.timeout = setTimeout(() => {