@resolveio/client-lib-core 15.1.2 → 15.1.3
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 +45 -41
- package/fesm2015/resolveio-client-lib-core.mjs +44 -40
- package/fesm2015/resolveio-client-lib-core.mjs.map +1 -1
- package/fesm2020/resolveio-client-lib-core.mjs +44 -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,46 @@ 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 = null;
|
|
250
|
+
this.readyState = WebSocket.CLOSED;
|
|
251
|
+
this.readyState$.next(this.readyState);
|
|
252
|
+
this.log(new Date(), 'WS', 'onclose', this.url);
|
|
253
|
+
this.onclose(event);
|
|
254
|
+
setTimeout(() => {
|
|
255
|
+
this.connect();
|
|
256
|
+
}, this.reconnectInterval);
|
|
257
|
+
this.stopPinging();
|
|
258
|
+
};
|
|
259
|
+
this.onMessageHandler = (event) => {
|
|
260
|
+
if (event.data === 'pong') {
|
|
261
|
+
this.log(new Date(), 'WS', 'pong received');
|
|
262
|
+
clearTimeout(this.pongTimeout);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
let messageData = JSON.parse(event.data);
|
|
266
|
+
messageData = this.convertUTCDateToLocalDate(messageData);
|
|
267
|
+
this.onmessage(messageData);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
this.onErrorHandler = (event) => {
|
|
271
|
+
this.log(new Date(), 'WS', 'onerror', this, event);
|
|
272
|
+
this.onerror(event);
|
|
273
|
+
this.close();
|
|
274
|
+
};
|
|
235
275
|
document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
|
|
236
276
|
}
|
|
237
277
|
openSocket(environment, protocols) {
|
|
@@ -253,46 +293,10 @@ class SocketService {
|
|
|
253
293
|
this.log(new Date(), 'WS', 'connection-timeout', this.url);
|
|
254
294
|
this.close();
|
|
255
295
|
}, 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
|
-
};
|
|
296
|
+
this.ws.onopen = this.onOpenHandler;
|
|
297
|
+
this.ws.onclose = this.onCloseHandler;
|
|
298
|
+
this.ws.onmessage = this.onMessageHandler;
|
|
299
|
+
this.ws.onerror = this.onErrorHandler;
|
|
296
300
|
}
|
|
297
301
|
}
|
|
298
302
|
convertUTCDateToLocalDate(data) {
|