@futdevpro/nts-dynamo 1.6.50 → 1.6.51
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/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +2 -1
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +4 -9
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +1 -0
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +36 -27
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_models/control-models/socket-presence.control-model.ts +5 -1
- package/src/_services/base/db.service.ts +4 -9
- package/src/_services/socket/socket-server.service.ts +40 -21
|
@@ -53,6 +53,7 @@ export class DynamoNTS_SocketPresence {
|
|
|
53
53
|
if (!socket.connected) {
|
|
54
54
|
Dynamo_Log.error(`Emitting event '${event}' on socket(${index}) failed! socket[${socket.id}] is not connected!`);
|
|
55
55
|
anyFailed = true;
|
|
56
|
+
|
|
56
57
|
errors.push(
|
|
57
58
|
new Dynamo_Error({
|
|
58
59
|
status: 500,
|
|
@@ -62,7 +63,9 @@ export class DynamoNTS_SocketPresence {
|
|
|
62
63
|
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
63
64
|
})
|
|
64
65
|
);
|
|
66
|
+
|
|
65
67
|
inactiveSockets.push(socket);
|
|
68
|
+
socket.disconnect(true);
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
const success: boolean = socket.emit(event, content, error => {
|
|
@@ -70,6 +73,7 @@ export class DynamoNTS_SocketPresence {
|
|
|
70
73
|
errors.push(error);
|
|
71
74
|
anyFailed = true;
|
|
72
75
|
});
|
|
76
|
+
|
|
73
77
|
if (!success) {
|
|
74
78
|
Dynamo_Log.error(`Emitting event '${event}' on socket(${index}) failed! (1)`);
|
|
75
79
|
anyFailed = true;
|
|
@@ -77,7 +81,7 @@ export class DynamoNTS_SocketPresence {
|
|
|
77
81
|
});
|
|
78
82
|
|
|
79
83
|
if (anyFailed) {
|
|
80
|
-
|
|
84
|
+
this.sockets = this.sockets.filter(socket => !inactiveSockets.includes(socket) && socket?.connected);
|
|
81
85
|
|
|
82
86
|
throw new Dynamo_Error({
|
|
83
87
|
status: 500,
|
|
@@ -337,12 +337,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
337
337
|
|
|
338
338
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
339
339
|
dataList.forEach((data: T) => {
|
|
340
|
-
|
|
341
|
-
data._id = `${data._id}`;
|
|
342
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
343
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getAll)')
|
|
344
|
-
}
|
|
345
|
-
}
|
|
340
|
+
data = this.stringifyDataId(data, 'getAll');
|
|
346
341
|
});
|
|
347
342
|
}
|
|
348
343
|
|
|
@@ -533,7 +528,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
533
528
|
});
|
|
534
529
|
});
|
|
535
530
|
|
|
536
|
-
data = this.stringifyDataId(data);
|
|
531
|
+
data = this.stringifyDataId(data, 'findOne');
|
|
537
532
|
|
|
538
533
|
return data;
|
|
539
534
|
}
|
|
@@ -827,7 +822,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
827
822
|
// ----------------------------------------------------------------------------------
|
|
828
823
|
// PRIVATE FUNCTIONS
|
|
829
824
|
|
|
830
|
-
private stringifyDataId(data: T): T {
|
|
825
|
+
private stringifyDataId(data: T, fnName: string): T {
|
|
831
826
|
if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
|
|
832
827
|
data._id = `${data._id}`;
|
|
833
828
|
|
|
@@ -835,7 +830,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
835
830
|
data = JSON.parse(JSON.stringify(data));
|
|
836
831
|
|
|
837
832
|
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
838
|
-
Dynamo_Log.error(
|
|
833
|
+
Dynamo_Log.error(`data._id stringifying failed! Please notfiy the developers! (${fnName})`, new Error());
|
|
839
834
|
}
|
|
840
835
|
}
|
|
841
836
|
}
|
|
@@ -106,7 +106,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
106
106
|
this.subscriptionEvent = this.incomingEvents.splice(subscriptionEventIndex)[0];
|
|
107
107
|
Dynamo_Log.error(
|
|
108
108
|
`You should not set the subscription event, but the subscriptions tasks, ` +
|
|
109
|
-
`in case you need additional steps for your
|
|
109
|
+
`in case you need additional steps for your subscriptions.`,
|
|
110
110
|
`${this.params.name} (${this.params.port})`,
|
|
111
111
|
);
|
|
112
112
|
} else {
|
|
@@ -126,14 +126,14 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
126
126
|
const disconnectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.disconnect);
|
|
127
127
|
if (0 <= disconnectEventIndex) {
|
|
128
128
|
this.incomingEvents[disconnectEventIndex].serviceName = this.params.name;
|
|
129
|
-
this.incomingEvents[disconnectEventIndex].tasks.push(this.
|
|
129
|
+
this.incomingEvents[disconnectEventIndex].tasks.push(this.disconnectBaseTask);
|
|
130
130
|
} else {
|
|
131
131
|
this.incomingEvents.push(
|
|
132
132
|
new DynamoNTS_SocketEvent({
|
|
133
133
|
serviceName: this.params.name,
|
|
134
134
|
eventKey: DynamoNTS_SocketEventKey.disconnect,
|
|
135
135
|
tasks: [
|
|
136
|
-
this.
|
|
136
|
+
this.disconnectBaseTask
|
|
137
137
|
]
|
|
138
138
|
})
|
|
139
139
|
);
|
|
@@ -200,7 +200,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
200
200
|
Dynamo_Log.error(`Emitting subscriptionSuccessful event failed!\nerror:`, error);
|
|
201
201
|
});
|
|
202
202
|
|
|
203
|
-
Dynamo_Log.success(`<===> socket subscription successfull (${issuer})`);
|
|
203
|
+
Dynamo_Log.success(`<===> socket(${this.params.name}) subscription successfull (${issuer})`);
|
|
204
204
|
} catch (error) {
|
|
205
205
|
Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
206
206
|
socket.emit(DynamoNTS_SocketEventKey.error, error);
|
|
@@ -221,7 +221,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
221
221
|
});
|
|
222
222
|
|
|
223
223
|
if (dynamoNTS_globalSettings.logMainSocketEvents) {
|
|
224
|
-
Dynamo_Log.success(`< >
|
|
224
|
+
Dynamo_Log.success(`< > socket(${this.params.name}): new CONNECTION established`);
|
|
225
225
|
}
|
|
226
226
|
} catch (error) {
|
|
227
227
|
Dynamo_Log.error(`Socket Connection failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
@@ -267,6 +267,24 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
private async disconnectBaseTask(socket: SocketIO.Socket, issuer: string): Promise<void> {
|
|
271
|
+
try {
|
|
272
|
+
await this.removeSubscription(socket, issuer);
|
|
273
|
+
|
|
274
|
+
Dynamo_Log.info(`< x > socket(${this.params.name}) disconnected (${issuer})`);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
throw new Dynamo_Error({
|
|
277
|
+
...this._getDefaultErrorSettings(
|
|
278
|
+
'disconnectBaseTask',
|
|
279
|
+
error,
|
|
280
|
+
issuer,
|
|
281
|
+
),
|
|
282
|
+
|
|
283
|
+
errorCode: 'NTS-SSS-109'
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
270
288
|
private async removeSubscription(socket: SocketIO.Socket, issuer?: string): Promise<void> {
|
|
271
289
|
try {
|
|
272
290
|
const activePresenceIndex: number = this.presences.findIndex((pres: DynamoNTS_SocketPresence) => pres.sockets.includes(socket));
|
|
@@ -275,7 +293,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
275
293
|
throw new Dynamo_Error({
|
|
276
294
|
...this._getDefaultErrorSettings(
|
|
277
295
|
'sendEventForId',
|
|
278
|
-
new Error(`closing
|
|
296
|
+
new Error(`closing socket(${this.params.name}) does not match any in the activePresences`),
|
|
279
297
|
issuer
|
|
280
298
|
),
|
|
281
299
|
|
|
@@ -301,7 +319,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
301
319
|
throw new Dynamo_Error({
|
|
302
320
|
...this._getDefaultErrorSettings(
|
|
303
321
|
'sendEventForId',
|
|
304
|
-
new Error(`closing
|
|
322
|
+
new Error(`closing socket(${this.params.name}) does not match any in the activePresences`),
|
|
305
323
|
issuer
|
|
306
324
|
),
|
|
307
325
|
|
|
@@ -321,6 +339,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
321
339
|
}
|
|
322
340
|
|
|
323
341
|
socket.disconnect();
|
|
342
|
+
Dynamo_Log.info(`<=x=> socket(${this.params.name}) unsubscription successfull (${issuer})`);
|
|
324
343
|
} catch (error) {
|
|
325
344
|
throw new Dynamo_Error({
|
|
326
345
|
...this._getDefaultErrorSettings(
|
|
@@ -330,14 +349,14 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
330
349
|
),
|
|
331
350
|
|
|
332
351
|
errorCode: 'NTS-SSS-200',
|
|
333
|
-
message: `
|
|
352
|
+
message: `socket(${this.params.name}) Subscription Removal failed: ${this.params?.name}`,
|
|
334
353
|
});
|
|
335
354
|
}
|
|
336
355
|
}
|
|
337
356
|
|
|
338
357
|
emitServerEvent(event: string, content: any): void {
|
|
339
358
|
try {
|
|
340
|
-
Dynamo_Log.log(` <=-- emitting server socket
|
|
359
|
+
Dynamo_Log.log(` <=-- emitting server socket(${this.params.name}) event: ${event}`);
|
|
341
360
|
this.openSocketServer.emit(event, content, error => {
|
|
342
361
|
Dynamo_Log.error(`Emitting server event '${event}' failed!\nerror:`, error);
|
|
343
362
|
});
|
|
@@ -349,7 +368,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
349
368
|
),
|
|
350
369
|
|
|
351
370
|
errorCode: 'NTS-SSS-500',
|
|
352
|
-
message: `
|
|
371
|
+
message: `socket(${this.params.name}) Event Emit (${event}) failed: ${this.params?.name}`,
|
|
353
372
|
});
|
|
354
373
|
}
|
|
355
374
|
}
|
|
@@ -365,7 +384,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
365
384
|
),
|
|
366
385
|
|
|
367
386
|
errorCode: 'NTS-SSS-600',
|
|
368
|
-
message: `
|
|
387
|
+
message: `socket(${this.params.name}) ID Subscription Check (${id}) failed`,
|
|
369
388
|
});
|
|
370
389
|
}
|
|
371
390
|
}
|
|
@@ -382,7 +401,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
382
401
|
),
|
|
383
402
|
|
|
384
403
|
errorCode: 'NTS-SSS-700',
|
|
385
|
-
message: `
|
|
404
|
+
message: `socket(${this.params.name}) Error Emit (id: ${presenceIssuerId}) failed`,
|
|
386
405
|
});
|
|
387
406
|
}
|
|
388
407
|
}
|
|
@@ -407,9 +426,9 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
407
426
|
presence.emitEvent(event, content);
|
|
408
427
|
|
|
409
428
|
if (dynamoNTS_globalSettings.logSocketEventContent) {
|
|
410
|
-
Dynamo_Log.
|
|
429
|
+
Dynamo_Log.success(` <--- emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id}) \ncontent:`, content);
|
|
411
430
|
} else {
|
|
412
|
-
Dynamo_Log.
|
|
431
|
+
Dynamo_Log.success(` <--- emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id})`);
|
|
413
432
|
}
|
|
414
433
|
} catch (error) {
|
|
415
434
|
try {
|
|
@@ -425,7 +444,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
425
444
|
throw new Dynamo_Error({
|
|
426
445
|
...this._getDefaultErrorSettings(
|
|
427
446
|
'sendEventForId',
|
|
428
|
-
new Error(`No active socket with this specific ID: ${id}`),
|
|
447
|
+
new Error(`No active socket(${this.params.name}) with this specific ID: ${id}`),
|
|
429
448
|
content?.source
|
|
430
449
|
),
|
|
431
450
|
|
|
@@ -440,8 +459,8 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
440
459
|
|
|
441
460
|
errorCode: 'NTS-SSS-310',
|
|
442
461
|
message:
|
|
443
|
-
`Error handling of inactive sockets failed!` +
|
|
444
|
-
`\n(Socket Event Emit for id (${id}, ${event}) failed
|
|
462
|
+
`Error handling of inactive sockets(${this.params.name}) failed!` +
|
|
463
|
+
`\n(Socket Event Emit for id (${id}, ${event}) failed)`,
|
|
445
464
|
});
|
|
446
465
|
}
|
|
447
466
|
|
|
@@ -449,24 +468,24 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
449
468
|
...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
|
|
450
469
|
|
|
451
470
|
errorCode: 'NTS-SSS-310',
|
|
452
|
-
message: `
|
|
471
|
+
message: `socket(${this.params.name}) Event Emit for id (${id}, ${event}) failed`,
|
|
453
472
|
});
|
|
454
473
|
}
|
|
455
474
|
}
|
|
456
475
|
|
|
457
476
|
broadcastEvent(event: string, content: any): void {
|
|
458
477
|
try {
|
|
459
|
-
Dynamo_Log.log(` <==-- broadcasting socket
|
|
478
|
+
Dynamo_Log.log(` <==-- broadcasting socket(${this.params.name}) event: ${event}`);
|
|
460
479
|
this.presences.forEach((presence: DynamoNTS_SocketPresence) => {
|
|
461
480
|
presence.emitEvent(event, content);
|
|
462
481
|
});
|
|
463
482
|
} catch (error) {
|
|
464
|
-
Dynamo_Log.error(`
|
|
483
|
+
Dynamo_Log.error(`socket(${this.params.name}) Event Broadcast (${event}) failed`, error);
|
|
465
484
|
throw new Dynamo_Error({
|
|
466
485
|
...this._getDefaultErrorSettings('broadcastEvent', error),
|
|
467
486
|
|
|
468
487
|
errorCode: 'NTS-SSS-400',
|
|
469
|
-
message: `
|
|
488
|
+
message: `socket(${this.params.name}) Event Broadcast (${event}) failed`,
|
|
470
489
|
});
|
|
471
490
|
}
|
|
472
491
|
}
|