@futdevpro/nts-dynamo 1.6.43 → 1.6.45
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/_enums/http/socket-event-type.enum.d.ts.map +1 -1
- package/lib/_enums/http/socket-event-type.enum.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +2 -2
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_services/core/api.service.js +9 -9
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +2 -2
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +42 -36
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_enums/http/socket-event-type.enum.ts +1 -0
- package/src/_models/control-models/socket-presence.control-model.ts +2 -2
- package/src/_services/core/api.service.ts +9 -9
- package/src/_services/socket/socket-server.service.ts +101 -35
|
@@ -62,8 +62,8 @@ export class DynamoNTS_SocketPresence {
|
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
const success: boolean = socket.emit(event, content,
|
|
66
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${index}) failed! (0)
|
|
65
|
+
const success: boolean = socket.emit(event, content, error => {
|
|
66
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${index}) failed! (0)\nerror:`, error);
|
|
67
67
|
errors.push(error);
|
|
68
68
|
anyFailed = true;
|
|
69
69
|
});
|
|
@@ -55,7 +55,7 @@ export class DynamoNTS_ApiService {
|
|
|
55
55
|
if (callParams.httpOptions.headers[headerKey]) {
|
|
56
56
|
privateAxiosInstance.defaults.headers.common[headerKey] = callParams.httpOptions.headers[headerKey];
|
|
57
57
|
} else {
|
|
58
|
-
Dynamo_Log.error('DYNAMOBE ERROR: \n missing header:', headerKey, '\n\n', new Error());
|
|
58
|
+
Dynamo_Log.error('DYNAMOBE ERROR: \n missing header:', headerKey/* , '\n\n', new Error() */);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -76,7 +76,7 @@ export class DynamoNTS_ApiService {
|
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
78
|
} else {
|
|
79
|
-
Dynamo_Log.error('DYNAMOBE ERROR: \n missing pathParam:', pathParamKey, '\n\n', new Error());
|
|
79
|
+
Dynamo_Log.error('DYNAMOBE ERROR: \n missing pathParam:', pathParamKey/* , '\n\n', new Error() */);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -160,7 +160,7 @@ export class DynamoNTS_ApiService {
|
|
|
160
160
|
});
|
|
161
161
|
break;
|
|
162
162
|
default:
|
|
163
|
-
Dynamo_Log.error('DYNAMOBE ERROR: \n wrong api call type', '\n\n', new Error());
|
|
163
|
+
Dynamo_Log.error('DYNAMOBE ERROR: \n wrong api call type'/* , '\n\n', new Error() */);
|
|
164
164
|
break;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -171,14 +171,14 @@ export class DynamoNTS_ApiService {
|
|
|
171
171
|
}
|
|
172
172
|
} catch (error) {
|
|
173
173
|
Dynamo_Log.error(`\nAPI ERROR: ${callParams?.name} failed...` +
|
|
174
|
-
`\n${callParams?.baseUrl}${callParams?.endPoint}\
|
|
174
|
+
`\n${callParams?.baseUrl}${callParams?.endPoint}\ncallParams:`, callParams);
|
|
175
175
|
|
|
176
176
|
if (callParams?.httpOptions?.responseType === DynamoNTS_HttpResponseType.text) {
|
|
177
177
|
error.error = JSON.parse(error.error);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
if (error?.response?.data?.flag?.includes('DYNAMO')) {
|
|
181
|
-
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL
|
|
181
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`/* , new Error() */);
|
|
182
182
|
|
|
183
183
|
throw new Dynamo_Error({
|
|
184
184
|
errorCode: 'NTS-API-002',
|
|
@@ -190,7 +190,7 @@ export class DynamoNTS_ApiService {
|
|
|
190
190
|
});
|
|
191
191
|
|
|
192
192
|
} else if (error.code === 'ENOTFOUND') {
|
|
193
|
-
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL
|
|
193
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`/* , new Error() */);
|
|
194
194
|
|
|
195
195
|
throw new Dynamo_Error({
|
|
196
196
|
status: 404,
|
|
@@ -203,7 +203,7 @@ export class DynamoNTS_ApiService {
|
|
|
203
203
|
});
|
|
204
204
|
|
|
205
205
|
} else if (error.code === 'ECONNREFUSED') {
|
|
206
|
-
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL
|
|
206
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`/* , new Error() */);
|
|
207
207
|
|
|
208
208
|
throw new Dynamo_Error({
|
|
209
209
|
status: 404,
|
|
@@ -222,11 +222,11 @@ export class DynamoNTS_ApiService {
|
|
|
222
222
|
errorCode: 'NTS-API-005',
|
|
223
223
|
addECToUserMsg: true,
|
|
224
224
|
userMessage: this.defaultErrorUserMsg,
|
|
225
|
-
issuerService: this.name,
|
|
225
|
+
issuerService: this/* .constructor */.name,
|
|
226
226
|
error
|
|
227
227
|
});
|
|
228
228
|
} else {
|
|
229
|
-
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`, error
|
|
229
|
+
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`, error/*, '\n\n' , new Error() */);
|
|
230
230
|
|
|
231
231
|
throw error;
|
|
232
232
|
}
|
|
@@ -188,9 +188,13 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
188
188
|
const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
189
189
|
issuer = presence.issuerId;
|
|
190
190
|
|
|
191
|
-
this.
|
|
191
|
+
this.addSocketToPresence(presence);
|
|
192
192
|
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
193
193
|
|
|
194
|
+
socket.emit(DynamoNTS_SocketEventType.subscriptionSuccessful, 'subscribe was successful', error => {
|
|
195
|
+
Dynamo_Log.error(`Emitting subscriptionSuccessful event failed!\nerror:`, error);
|
|
196
|
+
});
|
|
197
|
+
|
|
194
198
|
Dynamo_Log.success(`<===> socket subscription successfull (${issuer})`);
|
|
195
199
|
} catch (error) {
|
|
196
200
|
Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
@@ -243,7 +247,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
243
247
|
}
|
|
244
248
|
}
|
|
245
249
|
|
|
246
|
-
protected async
|
|
250
|
+
protected async addSocketToPresence(newPresence: T_Presence): Promise<void> {
|
|
247
251
|
try {
|
|
248
252
|
const activePresence: T_Presence = this.presences.find((pres: T_Presence) => pres.issuerId === newPresence.issuerId);
|
|
249
253
|
|
|
@@ -261,41 +265,85 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
261
265
|
private async removeSubscriptionOnDisconnect(socket: SocketIO.Socket, issuer?: string): Promise<void> {
|
|
262
266
|
try {
|
|
263
267
|
const activePresenceIndex: number = this.presences.findIndex((pres: DynamoNTS_SocketPresence) => pres.sockets.includes(socket));
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
268
|
+
|
|
269
|
+
if (activePresenceIndex === -1) {
|
|
270
|
+
throw new Dynamo_Error({
|
|
271
|
+
...this._getDefaultErrorSettings(
|
|
272
|
+
'sendEventForId',
|
|
273
|
+
new Error(`closing Socket does not match any in the activePresences`),
|
|
274
|
+
issuer
|
|
275
|
+
),
|
|
269
276
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (this.getSubscriptionCloseTasks) {
|
|
274
|
-
await Dynamo_Array.asyncForEach(this.getSubscriptionCloseTasks(), async (task: DynamoNTS_SocketEventTask<null>) => {
|
|
275
|
-
await task(null, issuer);
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
Dynamo_Log.error(`Socket does not match present in presence.`);
|
|
280
|
-
}
|
|
277
|
+
errorCode: 'NTS-SSS-203',
|
|
278
|
+
});
|
|
279
|
+
}
|
|
281
280
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
281
|
+
const activePresence: DynamoNTS_SocketPresence = this.presences[activePresenceIndex];
|
|
282
|
+
if (activePresence.issuerId !== issuer) {
|
|
283
|
+
throw new Dynamo_Error({
|
|
284
|
+
...this._getDefaultErrorSettings(
|
|
285
|
+
'sendEventForId',
|
|
286
|
+
new Error(`socket subscription for ${issuer} and ${activePresence.issuerId} does not match.`),
|
|
287
|
+
issuer
|
|
288
|
+
),
|
|
289
|
+
|
|
290
|
+
errorCode: 'NTS-SSS-201',
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const socketIndex = activePresence.sockets.findIndex((s: SocketIO.Socket) => s === socket);
|
|
295
|
+
if (socketIndex === -1) {
|
|
296
|
+
throw new Dynamo_Error({
|
|
297
|
+
...this._getDefaultErrorSettings(
|
|
298
|
+
'sendEventForId',
|
|
299
|
+
new Error(`closing Socket does not match any in the activePresences`),
|
|
300
|
+
issuer
|
|
301
|
+
),
|
|
302
|
+
|
|
303
|
+
errorCode: 'NTS-SSS-202',
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
activePresence.sockets.splice(socketIndex);
|
|
308
|
+
if (this.getSubscriptionCloseTasks) {
|
|
309
|
+
await Dynamo_Array.asyncForEach(this.getSubscriptionCloseTasks(), async (task: DynamoNTS_SocketEventTask<null>) => {
|
|
310
|
+
await task(null, issuer);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (activePresence.sockets.length === 0) {
|
|
315
|
+
this.presences.splice(activePresenceIndex);
|
|
285
316
|
}
|
|
286
317
|
} catch (error) {
|
|
287
|
-
|
|
288
|
-
|
|
318
|
+
throw new Dynamo_Error({
|
|
319
|
+
...this._getDefaultErrorSettings(
|
|
320
|
+
'sendEventForId',
|
|
321
|
+
error,
|
|
322
|
+
issuer
|
|
323
|
+
),
|
|
324
|
+
|
|
325
|
+
errorCode: 'NTS-SSS-200',
|
|
326
|
+
message: `Socket Subscription Removal failed: ${this.params?.name} (${this.params?.port})`,
|
|
327
|
+
});
|
|
289
328
|
}
|
|
290
329
|
}
|
|
291
330
|
|
|
292
|
-
|
|
331
|
+
emitServerEvent(event: string, content: any): void {
|
|
293
332
|
try {
|
|
294
|
-
Dynamo_Log.log(`
|
|
295
|
-
this.openSocketServer.emit(event, content
|
|
333
|
+
Dynamo_Log.log(` <=-- emitting server socket event: ${event} (${this.params.name})`);
|
|
334
|
+
this.openSocketServer.emit(event, content, error => {
|
|
335
|
+
Dynamo_Log.error(`Emitting server event '${event}' failed!\nerror:`, error);
|
|
336
|
+
});
|
|
296
337
|
} catch (error) {
|
|
297
|
-
|
|
298
|
-
|
|
338
|
+
throw new Dynamo_Error({
|
|
339
|
+
...this._getDefaultErrorSettings(
|
|
340
|
+
'emitEvent',
|
|
341
|
+
error
|
|
342
|
+
),
|
|
343
|
+
|
|
344
|
+
errorCode: 'NTS-SSS-500',
|
|
345
|
+
message: `Socket Event Emit (${event}) failed: ${this.params?.name} (${this.params?.port})`,
|
|
346
|
+
});
|
|
299
347
|
}
|
|
300
348
|
}
|
|
301
349
|
|
|
@@ -303,8 +351,15 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
303
351
|
try {
|
|
304
352
|
return !!this.presences.find((presence: DynamoNTS_SocketPresence) => presence.issuerId === id);
|
|
305
353
|
} catch (error) {
|
|
306
|
-
|
|
307
|
-
|
|
354
|
+
throw new Dynamo_Error({
|
|
355
|
+
...this._getDefaultErrorSettings(
|
|
356
|
+
'idIsSubscribed',
|
|
357
|
+
error
|
|
358
|
+
),
|
|
359
|
+
|
|
360
|
+
errorCode: 'NTS-SSS-600',
|
|
361
|
+
message: `Socket ID Subscription Check (${id}) failed: ${this.params?.name} (${this.params?.port})`,
|
|
362
|
+
});
|
|
308
363
|
}
|
|
309
364
|
}
|
|
310
365
|
|
|
@@ -312,8 +367,16 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
312
367
|
try {
|
|
313
368
|
this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventType.error, error);
|
|
314
369
|
} catch (error) {
|
|
315
|
-
|
|
316
|
-
|
|
370
|
+
throw new Dynamo_Error({
|
|
371
|
+
...this._getDefaultErrorSettings(
|
|
372
|
+
'emitError',
|
|
373
|
+
error,
|
|
374
|
+
presenceIssuerId
|
|
375
|
+
),
|
|
376
|
+
|
|
377
|
+
errorCode: 'NTS-SSS-700',
|
|
378
|
+
message: `Socket Error Emit (id: ${presenceIssuerId}) failed: ${this.params?.name} (${this.params?.port})`,
|
|
379
|
+
});
|
|
317
380
|
}
|
|
318
381
|
}
|
|
319
382
|
|
|
@@ -322,8 +385,12 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
322
385
|
const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
|
|
323
386
|
|
|
324
387
|
if (presence) {
|
|
325
|
-
Dynamo_Log.log(` <--- emitting socket event for presence: ${event} (${this.params.name}, presenceId: ${id})`);
|
|
326
388
|
presence.emitEvent(event, content);
|
|
389
|
+
if (dynamoNTS_globalSettings.logSocketEventContent) {
|
|
390
|
+
Dynamo_Log.log(` <--- emitted socket event for presence: ${event} (${this.params.name}, presenceId: ${id}) \ncontent:`, content);
|
|
391
|
+
} else {
|
|
392
|
+
Dynamo_Log.log(` <--- emitted socket event for presence: ${event} (${this.params.name}, presenceId: ${id})`);
|
|
393
|
+
}
|
|
327
394
|
} else {
|
|
328
395
|
throw new Dynamo_Error({
|
|
329
396
|
...this._getDefaultErrorSettings(
|
|
@@ -342,13 +409,13 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
342
409
|
|
|
343
410
|
errorCode: 'NTS-SSS-300',
|
|
344
411
|
message: `Socket Event Emit for id (${id}, ${event}) failed: ${this.params?.name} (${this.params?.port})`,
|
|
345
|
-
error
|
|
346
412
|
});
|
|
347
413
|
}
|
|
348
414
|
}
|
|
349
415
|
|
|
350
416
|
broadcastEvent(event: string, content: any): void {
|
|
351
417
|
try {
|
|
418
|
+
Dynamo_Log.log(` <==-- broadcasting socket event: ${event} (${this.params.name})`);
|
|
352
419
|
this.presences.forEach((presence: DynamoNTS_SocketPresence) => {
|
|
353
420
|
presence.emitEvent(event, content);
|
|
354
421
|
});
|
|
@@ -359,7 +426,6 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
359
426
|
|
|
360
427
|
errorCode: 'NTS-SSS-400',
|
|
361
428
|
message: `Socket Event Broadcast (${event}) failed: ${this.params?.name} (${this.params?.port})`,
|
|
362
|
-
error
|
|
363
429
|
});
|
|
364
430
|
}
|
|
365
431
|
}
|