@resolveio/client-lib-core 15.1.2 → 15.1.4
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.
- package/esm2020/lib/socket.service.mjs +49 -41
- package/fesm2015/resolveio-client-lib-core.mjs +48 -40
- package/fesm2015/resolveio-client-lib-core.mjs.map +1 -1
- package/fesm2020/resolveio-client-lib-core.mjs +48 -40
- package/fesm2020/resolveio-client-lib-core.mjs.map +1 -1
- package/lib/socket.service.d.ts +4 -0
- package/package.json +1 -1
|
@@ -232,6 +232,50 @@ class SocketService {
|
|
|
232
232
|
this.onconnecting = function () { };
|
|
233
233
|
this.onmessage = function (event) { };
|
|
234
234
|
this.onerror = function (event) { };
|
|
235
|
+
this.onOpenHandler = (event) => {
|
|
236
|
+
clearTimeout(this.timeout);
|
|
237
|
+
this.timeout = null;
|
|
238
|
+
this.log(new Date(), 'WS', 'onopen', this.url);
|
|
239
|
+
this.readyState = WebSocket.OPEN;
|
|
240
|
+
this.readyState$.next(this.readyState);
|
|
241
|
+
this.onopen(event);
|
|
242
|
+
this.startPinging();
|
|
243
|
+
};
|
|
244
|
+
this.onCloseHandler = (event) => {
|
|
245
|
+
if (this.timeout) {
|
|
246
|
+
clearTimeout(this.timeout);
|
|
247
|
+
}
|
|
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
|
+
};
|
|
263
|
+
this.onMessageHandler = (event) => {
|
|
264
|
+
if (event.data === 'pong') {
|
|
265
|
+
this.log(new Date(), 'WS', 'pong received');
|
|
266
|
+
clearTimeout(this.pongTimeout);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
let messageData = JSON.parse(event.data);
|
|
270
|
+
messageData = this.convertUTCDateToLocalDate(messageData);
|
|
271
|
+
this.onmessage(messageData);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
this.onErrorHandler = (event) => {
|
|
275
|
+
this.log(new Date(), 'WS', 'onerror', this, event);
|
|
276
|
+
this.onerror(event);
|
|
277
|
+
this.close();
|
|
278
|
+
};
|
|
235
279
|
document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
|
|
236
280
|
}
|
|
237
281
|
openSocket(environment, protocols) {
|
|
@@ -253,46 +297,10 @@ class SocketService {
|
|
|
253
297
|
this.log(new Date(), 'WS', 'connection-timeout', this.url);
|
|
254
298
|
this.close();
|
|
255
299
|
}, this.timeoutInterval);
|
|
256
|
-
this.ws.onopen =
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
this.readyState = WebSocket.OPEN;
|
|
261
|
-
this.readyState$.next(this.readyState);
|
|
262
|
-
this.onopen(event);
|
|
263
|
-
this.startPinging();
|
|
264
|
-
};
|
|
265
|
-
this.ws.onclose = (event) => {
|
|
266
|
-
if (this.timeout) {
|
|
267
|
-
clearTimeout(this.timeout);
|
|
268
|
-
}
|
|
269
|
-
this.timeout = null;
|
|
270
|
-
this.ws = null;
|
|
271
|
-
this.readyState = WebSocket.CLOSED;
|
|
272
|
-
this.readyState$.next(this.readyState);
|
|
273
|
-
this.log(new Date(), 'WS', 'onclose', this.url);
|
|
274
|
-
this.onclose(event);
|
|
275
|
-
setTimeout(() => {
|
|
276
|
-
this.reconnect();
|
|
277
|
-
}, this.reconnectInterval);
|
|
278
|
-
this.stopPinging();
|
|
279
|
-
};
|
|
280
|
-
this.ws.onmessage = (event) => {
|
|
281
|
-
if (event.data === 'pong') {
|
|
282
|
-
this.log(new Date(), 'WS', 'pong received');
|
|
283
|
-
clearTimeout(this.pongTimeout);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
let messageData = JSON.parse(event.data);
|
|
287
|
-
messageData = this.convertUTCDateToLocalDate(messageData);
|
|
288
|
-
this.onmessage(messageData);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
this.ws.onerror = (event) => {
|
|
292
|
-
this.log(new Date(), 'WS', 'onerror', this, event);
|
|
293
|
-
this.onerror(event);
|
|
294
|
-
this.close();
|
|
295
|
-
};
|
|
300
|
+
this.ws.onopen = this.onOpenHandler;
|
|
301
|
+
this.ws.onclose = this.onCloseHandler;
|
|
302
|
+
this.ws.onmessage = this.onMessageHandler;
|
|
303
|
+
this.ws.onerror = this.onErrorHandler;
|
|
296
304
|
}
|
|
297
305
|
}
|
|
298
306
|
convertUTCDateToLocalDate(data) {
|