@resolveio/client-lib-core 1.5.0 → 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/auth/auth.service.mjs +4 -4
- package/esm2020/lib/socket-manager.service.mjs +46 -44
- package/esm2020/lib/socket.service.mjs +40 -3
- package/fesm2015/resolveio-client-lib-core.mjs +86 -47
- package/fesm2015/resolveio-client-lib-core.mjs.map +1 -1
- package/fesm2020/resolveio-client-lib-core.mjs +86 -47
- 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
|
@@ -321,7 +321,9 @@ class SocketService {
|
|
|
321
321
|
clearTimeout(this.pongTimeout);
|
|
322
322
|
}
|
|
323
323
|
else {
|
|
324
|
-
|
|
324
|
+
let messageData = JSON.parse(event.data);
|
|
325
|
+
messageData = this.convertUTCDateToLocalDate(messageData);
|
|
326
|
+
this.onmessage(messageData);
|
|
325
327
|
}
|
|
326
328
|
};
|
|
327
329
|
this.ws.onerror = (event) => {
|
|
@@ -331,10 +333,30 @@ class SocketService {
|
|
|
331
333
|
};
|
|
332
334
|
}
|
|
333
335
|
}
|
|
336
|
+
convertUTCDateToLocalDate(data) {
|
|
337
|
+
if (Array.isArray(data)) {
|
|
338
|
+
return data.map(item => this.convertUTCDateToLocalDate(item));
|
|
339
|
+
}
|
|
340
|
+
else if (typeof data === 'object' && data !== null) {
|
|
341
|
+
const keys = Object.keys(data);
|
|
342
|
+
keys.forEach((key) => {
|
|
343
|
+
data[key] = this.convertUTCDateToLocalDate(data[key]);
|
|
344
|
+
});
|
|
345
|
+
return data;
|
|
346
|
+
}
|
|
347
|
+
else if (typeof data === 'string') {
|
|
348
|
+
// Check if the string is an ISO date format
|
|
349
|
+
const datePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
|
|
350
|
+
if (datePattern.test(data)) {
|
|
351
|
+
return new Date(data);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return data;
|
|
355
|
+
}
|
|
334
356
|
startPinging() {
|
|
335
357
|
this.pingInterval = setInterval(() => {
|
|
336
358
|
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
337
|
-
this.
|
|
359
|
+
this.send('ping');
|
|
338
360
|
this.pongTimeout = setTimeout(() => {
|
|
339
361
|
this.log(new Date(), 'WS', 'pong not received, closing connection');
|
|
340
362
|
this.close();
|
|
@@ -350,8 +372,23 @@ class SocketService {
|
|
|
350
372
|
clearTimeout(this.pongTimeout);
|
|
351
373
|
}
|
|
352
374
|
}
|
|
375
|
+
convertDatesToUTC(obj) {
|
|
376
|
+
for (let key in obj) {
|
|
377
|
+
if (obj.hasOwnProperty(key)) {
|
|
378
|
+
if (obj[key] instanceof Date) {
|
|
379
|
+
// Convert Date to UTC ISO String
|
|
380
|
+
obj[key] = obj[key].toISOString();
|
|
381
|
+
}
|
|
382
|
+
else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
383
|
+
// Recursively look for Date objects within arrays or nested objects
|
|
384
|
+
this.convertDatesToUTC(obj[key]);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
353
389
|
send(...data) {
|
|
354
390
|
if (this.ws && this.ws.readyState === this.ws.OPEN) {
|
|
391
|
+
data.forEach(item => this.convertDatesToUTC(item));
|
|
355
392
|
this.ws.send(JSON.stringify(data));
|
|
356
393
|
return true;
|
|
357
394
|
}
|
|
@@ -1117,48 +1154,7 @@ class SocketManagerService {
|
|
|
1117
1154
|
this.socketStatus = socketStatus;
|
|
1118
1155
|
});
|
|
1119
1156
|
this._socket.onmessage = (event) => {
|
|
1120
|
-
|
|
1121
|
-
if (resData.data === 'reloadWSCommand') {
|
|
1122
|
-
window.location.href = window.location.href + '?forceReload=true';
|
|
1123
|
-
}
|
|
1124
|
-
else if (resData.data === 'reconnectWSCommand') {
|
|
1125
|
-
this._socket.reconnect();
|
|
1126
|
-
}
|
|
1127
|
-
else if (resData.data === 'disconnectWSCommand') {
|
|
1128
|
-
this.closeSocket();
|
|
1129
|
-
}
|
|
1130
|
-
let offlineIndex = this._offlineUpdates.findIndex(a => a.messageId === resData.messageId);
|
|
1131
|
-
if (offlineIndex >= 0) {
|
|
1132
|
-
this._offline.removeDocument(this._offlineUpdates[offlineIndex].type, this._offlineUpdates[offlineIndex].id_offline_doc);
|
|
1133
|
-
this._offlineUpdates.splice(offlineIndex, 1);
|
|
1134
|
-
}
|
|
1135
|
-
if (resData.data !== 'ACK' && resData.data !== 'NACK') {
|
|
1136
|
-
if (this._cbArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1137
|
-
let index = this._cbArray.findIndex(a => a.messageId === resData.messageId);
|
|
1138
|
-
if (index >= 0) {
|
|
1139
|
-
clearInterval(this._cbArray[index].timerId);
|
|
1140
|
-
if (this._cbArray[index].cb) {
|
|
1141
|
-
this._cbArray[index].cb(resData.hasError ? resData.data : null, resData.hasError ? null : resData.data);
|
|
1142
|
-
this._cbArray[index].resolveFn(resData.hasError ? resData.data : null);
|
|
1143
|
-
}
|
|
1144
|
-
else {
|
|
1145
|
-
if (resData.hasError) {
|
|
1146
|
-
this._cbArray[index].rejectFn(resData.data);
|
|
1147
|
-
}
|
|
1148
|
-
else {
|
|
1149
|
-
this._cbArray[index].resolveFn(resData.data);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
this._cbArray.splice(index, 1);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
else if (this._subArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1156
|
-
let index = this._subArray.findIndex(a => a.messageId === resData.messageId);
|
|
1157
|
-
if (index >= 0) {
|
|
1158
|
-
this._subArray[index].subject.next(resData.data);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1157
|
+
this.handleMessage(event);
|
|
1162
1158
|
};
|
|
1163
1159
|
this._socket.onopen = (event) => {
|
|
1164
1160
|
this._connectionDelayTimeout = setTimeout(() => {
|
|
@@ -1224,6 +1220,49 @@ class SocketManagerService {
|
|
|
1224
1220
|
}
|
|
1225
1221
|
}, 25);
|
|
1226
1222
|
}
|
|
1223
|
+
handleMessage(resData) {
|
|
1224
|
+
if (resData.data === 'reloadWSCommand') {
|
|
1225
|
+
window.location.href = window.location.href + '?forceReload=true';
|
|
1226
|
+
}
|
|
1227
|
+
else if (resData.data === 'reconnectWSCommand') {
|
|
1228
|
+
this._socket.reconnect();
|
|
1229
|
+
}
|
|
1230
|
+
else if (resData.data === 'disconnectWSCommand') {
|
|
1231
|
+
this.closeSocket();
|
|
1232
|
+
}
|
|
1233
|
+
let offlineIndex = this._offlineUpdates.findIndex(a => a.messageId === resData.messageId);
|
|
1234
|
+
if (offlineIndex >= 0) {
|
|
1235
|
+
this._offline.removeDocument(this._offlineUpdates[offlineIndex].type, this._offlineUpdates[offlineIndex].id_offline_doc);
|
|
1236
|
+
this._offlineUpdates.splice(offlineIndex, 1);
|
|
1237
|
+
}
|
|
1238
|
+
if (resData.data !== 'ACK' && resData.data !== 'NACK') {
|
|
1239
|
+
if (this._cbArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1240
|
+
let index = this._cbArray.findIndex(a => a.messageId === resData.messageId);
|
|
1241
|
+
if (index >= 0) {
|
|
1242
|
+
clearInterval(this._cbArray[index].timerId);
|
|
1243
|
+
if (this._cbArray[index].cb) {
|
|
1244
|
+
this._cbArray[index].cb(resData.hasError ? resData.data : null, resData.hasError ? null : resData.data);
|
|
1245
|
+
this._cbArray[index].resolveFn(resData.hasError ? resData.data : null);
|
|
1246
|
+
}
|
|
1247
|
+
else {
|
|
1248
|
+
if (resData.hasError) {
|
|
1249
|
+
this._cbArray[index].rejectFn(resData.data);
|
|
1250
|
+
}
|
|
1251
|
+
else {
|
|
1252
|
+
this._cbArray[index].resolveFn(resData.data);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
this._cbArray.splice(index, 1);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
else if (this._subArray.map(a => a.messageId).includes(resData.messageId)) {
|
|
1259
|
+
let index = this._subArray.findIndex(a => a.messageId === resData.messageId);
|
|
1260
|
+
if (index >= 0) {
|
|
1261
|
+
this._subArray[index].subject.next(resData.data);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1227
1266
|
openSocket(environment, protocols) {
|
|
1228
1267
|
this._socket.openSocket(environment, protocols);
|
|
1229
1268
|
}
|
|
@@ -4328,8 +4367,8 @@ class AuthService {
|
|
|
4328
4367
|
}
|
|
4329
4368
|
this._ds.input('Register New User', inputProps).then(close => {
|
|
4330
4369
|
let user = {
|
|
4331
|
-
username: close.username.value.trim(),
|
|
4332
|
-
email: close.email.value.trim(),
|
|
4370
|
+
username: close.username.value.trim().toLowerCase(),
|
|
4371
|
+
email: close.email.value.trim().toLowerCase(),
|
|
4333
4372
|
fullname: close.fullname.value.trim(),
|
|
4334
4373
|
roles: {
|
|
4335
4374
|
super_admin: false,
|
|
@@ -4411,7 +4450,7 @@ class AuthService {
|
|
|
4411
4450
|
user['phonenumber'] = '';
|
|
4412
4451
|
}
|
|
4413
4452
|
user.email = close.email.value.trim();
|
|
4414
|
-
this._socket.call('editUser', user._id, close.username.value.trim(), close.fullname.value.trim(), close.email.value.trim(), user['phonenumber'], (err, res) => {
|
|
4453
|
+
this._socket.call('editUser', user._id, close.username.value.trim().toLowerCase(), close.fullname.value.trim(), close.email.value.trim().toLowerCase(), user['phonenumber'], (err, res) => {
|
|
4415
4454
|
if (err) {
|
|
4416
4455
|
this._socket.call('insertErrorLog', 'AuthService - edituser', [
|
|
4417
4456
|
user,
|