@resolveio/client-lib-core 1.5.1 → 1.6.0
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-manager.service.mjs +46 -44
- package/esm2020/lib/socket.service.mjs +40 -3
- package/fesm2015/resolveio-client-lib-core.mjs +83 -44
- package/fesm2015/resolveio-client-lib-core.mjs.map +1 -1
- package/fesm2020/resolveio-client-lib-core.mjs +83 -44
- package/fesm2020/resolveio-client-lib-core.mjs.map +1 -1
- package/lib/socket-manager.service.d.ts +1 -0
- package/lib/socket.service.d.ts +2 -0
- package/package.json +1 -1
|
@@ -282,7 +282,9 @@ class SocketService {
|
|
|
282
282
|
clearTimeout(this.pongTimeout);
|
|
283
283
|
}
|
|
284
284
|
else {
|
|
285
|
-
|
|
285
|
+
let messageData = JSON.parse(event.data);
|
|
286
|
+
messageData = this.convertUTCDateToLocalDate(messageData);
|
|
287
|
+
this.onmessage(messageData);
|
|
286
288
|
}
|
|
287
289
|
};
|
|
288
290
|
this.ws.onerror = (event) => {
|
|
@@ -292,10 +294,30 @@ class SocketService {
|
|
|
292
294
|
};
|
|
293
295
|
}
|
|
294
296
|
}
|
|
297
|
+
convertUTCDateToLocalDate(data) {
|
|
298
|
+
if (Array.isArray(data)) {
|
|
299
|
+
return data.map(item => this.convertUTCDateToLocalDate(item));
|
|
300
|
+
}
|
|
301
|
+
else if (typeof data === 'object' && data !== null) {
|
|
302
|
+
const keys = Object.keys(data);
|
|
303
|
+
keys.forEach((key) => {
|
|
304
|
+
data[key] = this.convertUTCDateToLocalDate(data[key]);
|
|
305
|
+
});
|
|
306
|
+
return data;
|
|
307
|
+
}
|
|
308
|
+
else if (typeof data === 'string') {
|
|
309
|
+
// Check if the string is an ISO date format
|
|
310
|
+
const datePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
|
|
311
|
+
if (datePattern.test(data)) {
|
|
312
|
+
return new Date(data);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return data;
|
|
316
|
+
}
|
|
295
317
|
startPinging() {
|
|
296
318
|
this.pingInterval = setInterval(() => {
|
|
297
319
|
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
298
|
-
this.
|
|
320
|
+
this.send('ping');
|
|
299
321
|
this.pongTimeout = setTimeout(() => {
|
|
300
322
|
this.log(new Date(), 'WS', 'pong not received, closing connection');
|
|
301
323
|
this.close();
|
|
@@ -311,8 +333,23 @@ class SocketService {
|
|
|
311
333
|
clearTimeout(this.pongTimeout);
|
|
312
334
|
}
|
|
313
335
|
}
|
|
336
|
+
convertDatesToUTC(obj) {
|
|
337
|
+
for (let key in obj) {
|
|
338
|
+
if (obj.hasOwnProperty(key)) {
|
|
339
|
+
if (obj[key] instanceof Date) {
|
|
340
|
+
// Convert Date to UTC ISO String
|
|
341
|
+
obj[key] = obj[key].toISOString();
|
|
342
|
+
}
|
|
343
|
+
else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
344
|
+
// Recursively look for Date objects within arrays or nested objects
|
|
345
|
+
this.convertDatesToUTC(obj[key]);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
314
350
|
send(...data) {
|
|
315
351
|
if (this.ws && this.ws.readyState === this.ws.OPEN) {
|
|
352
|
+
data.forEach(item => this.convertDatesToUTC(item));
|
|
316
353
|
this.ws.send(JSON.stringify(data));
|
|
317
354
|
return true;
|
|
318
355
|
}
|
|
@@ -1135,48 +1172,7 @@ class SocketManagerService {
|
|
|
1135
1172
|
this.socketStatus = socketStatus;
|
|
1136
1173
|
});
|
|
1137
1174
|
this._socket.onmessage = (event) => {
|
|
1138
|
-
|
|
1139
|
-
if (resData.data === 'reloadWSCommand') {
|
|
1140
|
-
window.location.href = window.location.href + '?forceReload=true';
|
|
1141
|
-
}
|
|
1142
|
-
else if (resData.data === 'reconnectWSCommand') {
|
|
1143
|
-
this._socket.reconnect();
|
|
1144
|
-
}
|
|
1145
|
-
else if (resData.data === 'disconnectWSCommand') {
|
|
1146
|
-
this.closeSocket();
|
|
1147
|
-
}
|
|
1148
|
-
let offlineIndex = this._offlineUpdates.findIndex(a => a.messageId === resData.messageId);
|
|
1149
|
-
if (offlineIndex >= 0) {
|
|
1150
|
-
this._offline.removeDocument(this._offlineUpdates[offlineIndex].type, this._offlineUpdates[offlineIndex].id_offline_doc);
|
|
1151
|
-
this._offlineUpdates.splice(offlineIndex, 1);
|
|
1152
|
-
}
|
|
1153
|
-
if (resData.data !== 'ACK' && resData.data !== 'NACK') {
|
|
1154
|
-
if (this._cbArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1155
|
-
let index = this._cbArray.findIndex(a => a.messageId === resData.messageId);
|
|
1156
|
-
if (index >= 0) {
|
|
1157
|
-
clearInterval(this._cbArray[index].timerId);
|
|
1158
|
-
if (this._cbArray[index].cb) {
|
|
1159
|
-
this._cbArray[index].cb(resData.hasError ? resData.data : null, resData.hasError ? null : resData.data);
|
|
1160
|
-
this._cbArray[index].resolveFn(resData.hasError ? resData.data : null);
|
|
1161
|
-
}
|
|
1162
|
-
else {
|
|
1163
|
-
if (resData.hasError) {
|
|
1164
|
-
this._cbArray[index].rejectFn(resData.data);
|
|
1165
|
-
}
|
|
1166
|
-
else {
|
|
1167
|
-
this._cbArray[index].resolveFn(resData.data);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
this._cbArray.splice(index, 1);
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
else if (this._subArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1174
|
-
let index = this._subArray.findIndex(a => a.messageId === resData.messageId);
|
|
1175
|
-
if (index >= 0) {
|
|
1176
|
-
this._subArray[index].subject.next(resData.data);
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1175
|
+
this.handleMessage(event);
|
|
1180
1176
|
};
|
|
1181
1177
|
this._socket.onopen = (event) => {
|
|
1182
1178
|
this._connectionDelayTimeout = setTimeout(() => {
|
|
@@ -1242,6 +1238,49 @@ class SocketManagerService {
|
|
|
1242
1238
|
}
|
|
1243
1239
|
}, 25);
|
|
1244
1240
|
}
|
|
1241
|
+
handleMessage(resData) {
|
|
1242
|
+
if (resData.data === 'reloadWSCommand') {
|
|
1243
|
+
window.location.href = window.location.href + '?forceReload=true';
|
|
1244
|
+
}
|
|
1245
|
+
else if (resData.data === 'reconnectWSCommand') {
|
|
1246
|
+
this._socket.reconnect();
|
|
1247
|
+
}
|
|
1248
|
+
else if (resData.data === 'disconnectWSCommand') {
|
|
1249
|
+
this.closeSocket();
|
|
1250
|
+
}
|
|
1251
|
+
let offlineIndex = this._offlineUpdates.findIndex(a => a.messageId === resData.messageId);
|
|
1252
|
+
if (offlineIndex >= 0) {
|
|
1253
|
+
this._offline.removeDocument(this._offlineUpdates[offlineIndex].type, this._offlineUpdates[offlineIndex].id_offline_doc);
|
|
1254
|
+
this._offlineUpdates.splice(offlineIndex, 1);
|
|
1255
|
+
}
|
|
1256
|
+
if (resData.data !== 'ACK' && resData.data !== 'NACK') {
|
|
1257
|
+
if (this._cbArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1258
|
+
let index = this._cbArray.findIndex(a => a.messageId === resData.messageId);
|
|
1259
|
+
if (index >= 0) {
|
|
1260
|
+
clearInterval(this._cbArray[index].timerId);
|
|
1261
|
+
if (this._cbArray[index].cb) {
|
|
1262
|
+
this._cbArray[index].cb(resData.hasError ? resData.data : null, resData.hasError ? null : resData.data);
|
|
1263
|
+
this._cbArray[index].resolveFn(resData.hasError ? resData.data : null);
|
|
1264
|
+
}
|
|
1265
|
+
else {
|
|
1266
|
+
if (resData.hasError) {
|
|
1267
|
+
this._cbArray[index].rejectFn(resData.data);
|
|
1268
|
+
}
|
|
1269
|
+
else {
|
|
1270
|
+
this._cbArray[index].resolveFn(resData.data);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
this._cbArray.splice(index, 1);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
else if (this._subArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1277
|
+
let index = this._subArray.findIndex(a => a.messageId === resData.messageId);
|
|
1278
|
+
if (index >= 0) {
|
|
1279
|
+
this._subArray[index].subject.next(resData.data);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1245
1284
|
openSocket(environment, protocols) {
|
|
1246
1285
|
this._socket.openSocket(environment, protocols);
|
|
1247
1286
|
}
|