@futdevpro/nts-dynamo 1.6.49 → 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.
Files changed (30) hide show
  1. package/lib/_constants/global-settings.const.js +2 -2
  2. package/lib/_constants/global-settings.const.js.map +1 -1
  3. package/lib/_models/control-models/socket-event.control-model.d.ts +5 -0
  4. package/lib/_models/control-models/socket-event.control-model.d.ts.map +1 -1
  5. package/lib/_models/control-models/socket-event.control-model.js +9 -8
  6. package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
  7. package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
  8. package/lib/_models/control-models/socket-presence.control-model.js +2 -1
  9. package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
  10. package/lib/_models/interfaces/global-settings.interface.d.ts +2 -2
  11. package/lib/_models/interfaces/global-settings.interface.d.ts.map +1 -1
  12. package/lib/_services/base/db.service.d.ts.map +1 -1
  13. package/lib/_services/base/db.service.js +14 -19
  14. package/lib/_services/base/db.service.js.map +1 -1
  15. package/lib/_services/socket/socket-client.service.d.ts.map +1 -1
  16. package/lib/_services/socket/socket-client.service.js +9 -4
  17. package/lib/_services/socket/socket-client.service.js.map +1 -1
  18. package/lib/_services/socket/socket-server.service.d.ts +1 -0
  19. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  20. package/lib/_services/socket/socket-server.service.js +57 -37
  21. package/lib/_services/socket/socket-server.service.js.map +1 -1
  22. package/lib/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +1 -1
  24. package/src/_constants/global-settings.const.ts +2 -2
  25. package/src/_models/control-models/socket-event.control-model.ts +11 -5
  26. package/src/_models/control-models/socket-presence.control-model.ts +5 -1
  27. package/src/_models/interfaces/global-settings.interface.ts +2 -2
  28. package/src/_services/base/db.service.ts +14 -19
  29. package/src/_services/socket/socket-client.service.ts +14 -5
  30. package/src/_services/socket/socket-server.service.ts +73 -31
@@ -13,6 +13,7 @@ export type DynamoNTS_SocketEventTask<T> = (content?: T, issuer?: string) => Pro
13
13
  export class DynamoNTS_SocketEvent<T>{
14
14
  socketName?: string;
15
15
  eventKey: DynamoNTS_SocketEventKey | string;
16
+ serviceName?: string;
16
17
 
17
18
  preProcessess?: DynamoNTS_SocketEventPreprocessTask<any, any>[];
18
19
  tasks?: DynamoNTS_SocketEventTask<T>[];
@@ -32,6 +33,10 @@ export class DynamoNTS_SocketEvent<T>{
32
33
  * connection, connect, disconnect, message, error, or anything else
33
34
  */
34
35
  eventKey: DynamoNTS_SocketEventKey | string,
36
+ /**
37
+ * serviceName is the name of the service that will be used for logging
38
+ */
39
+ serviceName?: string,
35
40
  /**
36
41
  * preprocesses are the functions the service needs to run before the actual function,
37
42
  * these can be used for authentications, or translating data
@@ -56,6 +61,7 @@ export class DynamoNTS_SocketEvent<T>{
56
61
  try {
57
62
  this.socketName = set.name ?? set.eventKey;
58
63
  this.eventKey = set.eventKey;
64
+ this.serviceName = set.serviceName ?? 'UnkwownSocketService';
59
65
 
60
66
  this.preProcessess = set.preProcessess ?? [];
61
67
  this.tasks = set.tasks ?? [];
@@ -78,7 +84,7 @@ export class DynamoNTS_SocketEvent<T>{
78
84
  this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.logSocketEventContent;
79
85
  } catch (error) {
80
86
  Dynamo_Log.error(
81
- `\nSocket Event params setup failed (${this.socketName}): ${set.eventKey}`, error);
87
+ `\nSocket Event params setup failed (${this.serviceName}): ${set.eventKey}`, error);
82
88
  throw error;
83
89
  }
84
90
  }
@@ -90,12 +96,12 @@ export class DynamoNTS_SocketEvent<T>{
90
96
  private async getPreLog(content: T, issuer?: string): Promise<void> {
91
97
  try {
92
98
  if (this.logEventContent && this.eventKey !== DynamoNTS_SocketEventKey.connection) {
93
- Dynamo_Log.log(`---> incoming socket(${this.socketName}) event: ${this.eventKey};\ncontent:`, content);
99
+ Dynamo_Log.log(`---> incoming socket(${this.serviceName}) event: ${this.eventKey};\ncontent:`, content);
94
100
  } else {
95
- Dynamo_Log.log(`---> incoming socket(${this.socketName}) event: ${this.eventKey}...`);
101
+ Dynamo_Log.log(`---> incoming socket(${this.serviceName}) event: ${this.eventKey}...`);
96
102
  }
97
103
  } catch (error) {
98
- Dynamo_Log.error(`PreLog failed... (socket: ${this.socketName})`, error);
104
+ Dynamo_Log.error(`PreLog failed... (socket: ${this.serviceName})`, error);
99
105
  }
100
106
  }
101
107
 
@@ -117,7 +123,7 @@ export class DynamoNTS_SocketEvent<T>{
117
123
  await task(content, issuer);
118
124
  });
119
125
  } catch (error) {
120
- Dynamo_Log.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.eventKey})`, error, 'content:', content);
126
+ Dynamo_Log.error(`Socket Event tasks failed to execute on ${this.serviceName}.... (${this.eventKey})`, error, 'content:', content);
121
127
  }
122
128
  }
123
129
  }
@@ -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
- /* this.sockets = this.sockets.filter(socket => !inactiveSockets.includes(socket)); */
84
+ this.sockets = this.sockets.filter(socket => !inactiveSockets.includes(socket) && socket?.connected);
81
85
 
82
86
  throw new Dynamo_Error({
83
87
  status: 500,
@@ -45,11 +45,11 @@ export interface DynamoNTS_GlobalSettings {
45
45
  /**
46
46
  * this is an application wide default setting for socket debug logs
47
47
  */
48
- logMainSocketEvents?: boolean;
48
+ logAllSocketEvent?: boolean;
49
49
  /**
50
50
  * this is an application wide default setting for socket debug logs
51
51
  */
52
- logAllSocketEvent?: boolean;
52
+ logMainSocketEvents?: boolean;
53
53
  /**
54
54
  * this is an application wide default setting for socket debug logs
55
55
  */
@@ -103,7 +103,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
103
103
  if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
104
104
  newData._id = `${newData._id}`;
105
105
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
106
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
106
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.createData)')
107
107
  }
108
108
  }
109
109
  data._id = newData._id;
@@ -151,7 +151,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
151
151
  if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
152
152
  newData._id = `${newData._id}`;
153
153
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
154
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
154
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.modifyData)')
155
155
  }
156
156
  }
157
157
  data._id = newData._id;
@@ -180,7 +180,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
180
180
  if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
181
181
  data._id = `${data._id}`;
182
182
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
183
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
183
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataById)')
184
184
  }
185
185
  }
186
186
  return data;
@@ -220,7 +220,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
220
220
  if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
221
221
  data._id = `${data._id}`;
222
222
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
223
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
223
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataByDependencyId)')
224
224
  }
225
225
  }
226
226
  return data;
@@ -262,7 +262,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
262
262
  if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
263
263
  data._id = `${data._id}`;
264
264
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
265
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
265
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataListByDependencyId)')
266
266
  }
267
267
  }
268
268
  });
@@ -307,7 +307,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
307
307
  if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
308
308
  data._id = `${data._id}`;
309
309
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
310
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
310
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataListByDependencyIds)')
311
311
  }
312
312
  }
313
313
  });
@@ -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
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
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.findOne)')
344
- }
345
- }
340
+ data = this.stringifyDataId(data, 'getAll');
346
341
  });
347
342
  }
348
343
 
@@ -481,7 +476,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
481
476
  if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
482
477
  data._id = `${data._id}`;
483
478
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
484
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
479
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.searchData)')
485
480
  }
486
481
  }
487
482
  });
@@ -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
  }
@@ -583,7 +578,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
583
578
  if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
584
579
  data._id = `${data._id}`;
585
580
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
586
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
581
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.find)')
587
582
  }
588
583
  }
589
584
  });
@@ -645,7 +640,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
645
640
  if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
646
641
  data._id = `${data._id}`;
647
642
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
648
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
643
+ Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findWithPaging)')
649
644
  }
650
645
  }
651
646
  });
@@ -682,7 +677,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
682
677
  if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
683
678
  newData._id = `${newData._id}`;
684
679
  if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
685
- Dynamo_Log.error('newData._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findOne)')
680
+ Dynamo_Log.error('newData._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findByIdAndUpdate)')
686
681
  }
687
682
  }
688
683
 
@@ -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('data._id stringifying failed! Please notfiy the developers!', new Error());
833
+ Dynamo_Log.error(`data._id stringifying failed! Please notfiy the developers! (${fnName})`, new Error());
839
834
  }
840
835
  }
841
836
  }
@@ -29,7 +29,6 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
29
29
 
30
30
  private defaultEvents: DynamoNTS_SocketEvent<any>[] = [
31
31
  new DynamoNTS_SocketEvent<any>({
32
- name: 'connect',
33
32
  eventKey: DynamoNTS_SocketEventKey.connect,
34
33
  tasks: [
35
34
  async () => {
@@ -38,8 +37,8 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
38
37
  }
39
38
  ]
40
39
  }),
40
+
41
41
  new DynamoNTS_SocketEvent<any>({
42
- name: 'disconnect',
43
42
  eventKey: DynamoNTS_SocketEventKey.disconnect,
44
43
  tasks: [
45
44
  async () => {
@@ -53,8 +52,17 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
53
52
  }
54
53
  ]
55
54
  }),
55
+
56
+ new DynamoNTS_SocketEvent<any>({
57
+ eventKey: DynamoNTS_SocketEventKey.subscriptionSuccessful,
58
+ tasks: [
59
+ async () => {
60
+ Dynamo_Log.success(`Socket Client subscription successful: ${this.params.name}`);
61
+ }
62
+ ]
63
+ }),
64
+
56
65
  new DynamoNTS_SocketEvent<any>({
57
- name: 'error',
58
66
  eventKey: DynamoNTS_SocketEventKey.error,
59
67
  tasks: [
60
68
  async (content: any) => {
@@ -96,7 +104,8 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
96
104
 
97
105
  private async setupDefaultEvents(): Promise<void> {
98
106
  try {
99
- if (this.logFn) console.log('\nFn:. setupDefaultEvents')
107
+ if (this.logFn) console.log('\nFn:. setupDefaultEvents');
108
+
100
109
  this.defaultEvents.forEach((defaultEvent: DynamoNTS_SocketEvent<any>) => {
101
110
  const eventDeclared = this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.eventKey === defaultEvent.eventKey);
102
111
  if (!eventDeclared) {
@@ -170,7 +179,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
170
179
  */
171
180
  protected async emitEvent(eventType: string, content: any): Promise<void> {
172
181
  try {
173
- Dynamo_Log.log(`\n<-=- outgoing ${this.name} socket event: ${eventType}`);
182
+ Dynamo_Log.log(`<-=- outgoing ${this.name} socket event: ${eventType}`);
174
183
  this.socket.emit(eventType, content);
175
184
  } catch (error) {
176
185
  Dynamo_Log.error(`Socket Client Service Emit Event failed: ${this.params?.name} (${this.params?.port})`, error);
@@ -88,6 +88,7 @@ export abstract class DynamoNTS_SocketServerService<
88
88
  */
89
89
  private async prepareEvents(): Promise<void> {
90
90
  try {
91
+ /** Setup connect event */
91
92
  const connectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.connection);
92
93
  if (0 <= connectEventIndex) {
93
94
  this.connectEvent = this.incomingEvents.splice(connectEventIndex)[0];
@@ -96,15 +97,16 @@ export abstract class DynamoNTS_SocketServerService<
96
97
  eventKey: DynamoNTS_SocketEventKey.connection,
97
98
  });
98
99
  }
99
- this.connectEvent.socketName = this.params.name;
100
+ this.connectEvent.serviceName = this.params.name;
100
101
 
102
+ /** Setup subscription event */
101
103
  if (this.getPresenceFromSubscrioptionEventContent) {
102
104
  const subscriptionEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.subscribe);
103
105
  if (0 <= subscriptionEventIndex) {
104
106
  this.subscriptionEvent = this.incomingEvents.splice(subscriptionEventIndex)[0];
105
107
  Dynamo_Log.error(
106
108
  `You should not set the subscription event, but the subscriptions tasks, ` +
107
- `in case you need additional steps for your subscripotions.`,
109
+ `in case you need additional steps for your subscriptions.`,
108
110
  `${this.params.name} (${this.params.port})`,
109
111
  );
110
112
  } else {
@@ -118,24 +120,30 @@ export abstract class DynamoNTS_SocketServerService<
118
120
  if (this.getSubscriptionTasks) {
119
121
  this.subscriptionEvent.tasks.push(...this.getSubscriptionTasks());
120
122
  }
123
+ this.subscriptionEvent.serviceName = this.params.name;
121
124
 
125
+ /** Setup disconnect event */
122
126
  const disconnectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.disconnect);
123
127
  if (0 <= disconnectEventIndex) {
124
- this.incomingEvents[disconnectEventIndex].tasks.push(this.removeSubscription);
128
+ this.incomingEvents[disconnectEventIndex].serviceName = this.params.name;
129
+ this.incomingEvents[disconnectEventIndex].tasks.push(this.disconnectBaseTask);
125
130
  } else {
126
131
  this.incomingEvents.push(
127
132
  new DynamoNTS_SocketEvent({
133
+ serviceName: this.params.name,
128
134
  eventKey: DynamoNTS_SocketEventKey.disconnect,
129
135
  tasks: [
130
- this.removeSubscription
136
+ this.disconnectBaseTask
131
137
  ]
132
138
  })
133
139
  );
134
140
  }
135
141
 
142
+ /** Setup error event */
136
143
  const errorEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.error);
137
144
  if (errorEventIndex == -1 && this.errorHandling) {
138
145
  this.incomingEvents.push(new DynamoNTS_SocketEvent<T_ErrorContent>({
146
+ serviceName: this.params.name,
139
147
  eventKey: DynamoNTS_SocketEventKey.error,
140
148
  tasks: [
141
149
  this.errorHandling
@@ -148,8 +156,9 @@ export abstract class DynamoNTS_SocketServerService<
148
156
  Dynamo_Log.error('getPresenceFromSubscrioptionEventContent is not set', `${this.params.name} (${this.params.port})`);
149
157
  }
150
158
 
159
+ /** Set incoming events serviceName */
151
160
  this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
152
- event.socketName = this.params.name;
161
+ event.serviceName = this.params.name;
153
162
  });
154
163
  } catch (error) {
155
164
  Dynamo_Log.error(`Socket Server Service - Event Preparation setup failed: ${this.params?.name} (${this.params?.port})`, error);
@@ -176,9 +185,9 @@ export abstract class DynamoNTS_SocketServerService<
176
185
  * to be able to check content before getPresenceFromSubscrioptionEventContent
177
186
  */
178
187
  if (dynamoNTS_globalSettings.logMainSocketEvents || dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
179
- Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe};\ncontent:`, content);
188
+ Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe};\ncontent:`, content);
180
189
  } else {
181
- Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe}`);
190
+ Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe}`);
182
191
  }
183
192
 
184
193
  const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
@@ -191,7 +200,7 @@ export abstract class DynamoNTS_SocketServerService<
191
200
  Dynamo_Log.error(`Emitting subscriptionSuccessful event failed!\nerror:`, error);
192
201
  });
193
202
 
194
- Dynamo_Log.success(`<===> socket subscription successfull (${issuer})`);
203
+ Dynamo_Log.success(`<===> socket(${this.params.name}) subscription successfull (${issuer})`);
195
204
  } catch (error) {
196
205
  Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
197
206
  socket.emit(DynamoNTS_SocketEventKey.error, error);
@@ -212,7 +221,7 @@ export abstract class DynamoNTS_SocketServerService<
212
221
  });
213
222
 
214
223
  if (dynamoNTS_globalSettings.logMainSocketEvents) {
215
- Dynamo_Log.success(`< > Socket (${this.params.name}): new CONNECTION established`);
224
+ Dynamo_Log.success(`< > socket(${this.params.name}): new CONNECTION established`);
216
225
  }
217
226
  } catch (error) {
218
227
  Dynamo_Log.error(`Socket Connection failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
@@ -258,6 +267,24 @@ export abstract class DynamoNTS_SocketServerService<
258
267
  }
259
268
  }
260
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
+
261
288
  private async removeSubscription(socket: SocketIO.Socket, issuer?: string): Promise<void> {
262
289
  try {
263
290
  const activePresenceIndex: number = this.presences.findIndex((pres: DynamoNTS_SocketPresence) => pres.sockets.includes(socket));
@@ -266,7 +293,7 @@ export abstract class DynamoNTS_SocketServerService<
266
293
  throw new Dynamo_Error({
267
294
  ...this._getDefaultErrorSettings(
268
295
  'sendEventForId',
269
- new Error(`closing Socket does not match any in the activePresences`),
296
+ new Error(`closing socket(${this.params.name}) does not match any in the activePresences`),
270
297
  issuer
271
298
  ),
272
299
 
@@ -292,7 +319,7 @@ export abstract class DynamoNTS_SocketServerService<
292
319
  throw new Dynamo_Error({
293
320
  ...this._getDefaultErrorSettings(
294
321
  'sendEventForId',
295
- new Error(`closing Socket does not match any in the activePresences`),
322
+ new Error(`closing socket(${this.params.name}) does not match any in the activePresences`),
296
323
  issuer
297
324
  ),
298
325
 
@@ -312,6 +339,7 @@ export abstract class DynamoNTS_SocketServerService<
312
339
  }
313
340
 
314
341
  socket.disconnect();
342
+ Dynamo_Log.info(`<=x=> socket(${this.params.name}) unsubscription successfull (${issuer})`);
315
343
  } catch (error) {
316
344
  throw new Dynamo_Error({
317
345
  ...this._getDefaultErrorSettings(
@@ -321,14 +349,14 @@ export abstract class DynamoNTS_SocketServerService<
321
349
  ),
322
350
 
323
351
  errorCode: 'NTS-SSS-200',
324
- message: `Socket Subscription Removal failed: ${this.params?.name} (${this.params?.port})`,
352
+ message: `socket(${this.params.name}) Subscription Removal failed: ${this.params?.name}`,
325
353
  });
326
354
  }
327
355
  }
328
356
 
329
357
  emitServerEvent(event: string, content: any): void {
330
358
  try {
331
- Dynamo_Log.log(` <=-- emitting server socket event: ${event} (${this.params.name})`);
359
+ Dynamo_Log.log(` <=-- emitting server socket(${this.params.name}) event: ${event}`);
332
360
  this.openSocketServer.emit(event, content, error => {
333
361
  Dynamo_Log.error(`Emitting server event '${event}' failed!\nerror:`, error);
334
362
  });
@@ -340,7 +368,7 @@ export abstract class DynamoNTS_SocketServerService<
340
368
  ),
341
369
 
342
370
  errorCode: 'NTS-SSS-500',
343
- message: `Socket Event Emit (${event}) failed: ${this.params?.name} (${this.params?.port})`,
371
+ message: `socket(${this.params.name}) Event Emit (${event}) failed: ${this.params?.name}`,
344
372
  });
345
373
  }
346
374
  }
@@ -356,7 +384,7 @@ export abstract class DynamoNTS_SocketServerService<
356
384
  ),
357
385
 
358
386
  errorCode: 'NTS-SSS-600',
359
- message: `Socket ID Subscription Check (${id}) failed: ${this.params?.name} (${this.params?.port})`,
387
+ message: `socket(${this.params.name}) ID Subscription Check (${id}) failed`,
360
388
  });
361
389
  }
362
390
  }
@@ -373,7 +401,7 @@ export abstract class DynamoNTS_SocketServerService<
373
401
  ),
374
402
 
375
403
  errorCode: 'NTS-SSS-700',
376
- message: `Socket Error Emit (id: ${presenceIssuerId}) failed: ${this.params?.name} (${this.params?.port})`,
404
+ message: `socket(${this.params.name}) Error Emit (id: ${presenceIssuerId}) failed`,
377
405
  });
378
406
  }
379
407
  }
@@ -382,14 +410,7 @@ export abstract class DynamoNTS_SocketServerService<
382
410
  try {
383
411
  const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
384
412
 
385
- if (presence) {
386
- presence.emitEvent(event, content);
387
- if (dynamoNTS_globalSettings.logSocketEventContent) {
388
- Dynamo_Log.log(` <--- emitted socket event for presence: ${event} (${this.params.name}, presenceId: ${id}) \ncontent:`, content);
389
- } else {
390
- Dynamo_Log.log(` <--- emitted socket event for presence: ${event} (${this.params.name}, presenceId: ${id})`);
391
- }
392
- } else {
413
+ if (!presence) {
393
414
  throw new Dynamo_Error({
394
415
  ...this._getDefaultErrorSettings(
395
416
  'sendEventForId',
@@ -401,8 +422,15 @@ export abstract class DynamoNTS_SocketServerService<
401
422
  errorCode: 'NTS-SSS-301',
402
423
  });
403
424
  }
404
- } catch (error) {
405
425
 
426
+ presence.emitEvent(event, content);
427
+
428
+ if (dynamoNTS_globalSettings.logSocketEventContent) {
429
+ Dynamo_Log.success(` <--- emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id}) \ncontent:`, content);
430
+ } else {
431
+ Dynamo_Log.success(` <--- emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id})`);
432
+ }
433
+ } catch (error) {
406
434
  try {
407
435
  if (error.flag.includes('DYNAMO') && error?.accitionalInfo?.inactiveSockets) {
408
436
  const sockets: SocketIO.Socket[] = error.accitionalInfo.inactiveSockets;
@@ -410,6 +438,20 @@ export abstract class DynamoNTS_SocketServerService<
410
438
  await Dynamo_Array.asyncForEach(sockets, async (socket: SocketIO.Socket) => {
411
439
  await this.removeSubscription(socket);
412
440
  });
441
+
442
+ const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
443
+ if (!presence) {
444
+ throw new Dynamo_Error({
445
+ ...this._getDefaultErrorSettings(
446
+ 'sendEventForId',
447
+ new Error(`No active socket(${this.params.name}) with this specific ID: ${id}`),
448
+ content?.source
449
+ ),
450
+
451
+ status: 404,
452
+ errorCode: 'NTS-SSS-302',
453
+ });
454
+ }
413
455
  }
414
456
  } catch (error) {
415
457
  throw new Dynamo_Error({
@@ -417,8 +459,8 @@ export abstract class DynamoNTS_SocketServerService<
417
459
 
418
460
  errorCode: 'NTS-SSS-310',
419
461
  message:
420
- `Error handling of inactive sockets failed!` +
421
- `\n(Socket Event Emit for id (${id}, ${event}) failed: ${this.params?.name} (${this.params?.port}))`,
462
+ `Error handling of inactive sockets(${this.params.name}) failed!` +
463
+ `\n(Socket Event Emit for id (${id}, ${event}) failed)`,
422
464
  });
423
465
  }
424
466
 
@@ -426,24 +468,24 @@ export abstract class DynamoNTS_SocketServerService<
426
468
  ...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
427
469
 
428
470
  errorCode: 'NTS-SSS-310',
429
- message: `Socket Event Emit for id (${id}, ${event}) failed: ${this.params?.name} (${this.params?.port})`,
471
+ message: `socket(${this.params.name}) Event Emit for id (${id}, ${event}) failed`,
430
472
  });
431
473
  }
432
474
  }
433
475
 
434
476
  broadcastEvent(event: string, content: any): void {
435
477
  try {
436
- Dynamo_Log.log(` <==-- broadcasting socket event: ${event} (${this.params.name})`);
478
+ Dynamo_Log.log(` <==-- broadcasting socket(${this.params.name}) event: ${event}`);
437
479
  this.presences.forEach((presence: DynamoNTS_SocketPresence) => {
438
480
  presence.emitEvent(event, content);
439
481
  });
440
482
  } catch (error) {
441
- Dynamo_Log.error(`Socket Event Broadcast (${event}) failed: ${this.params?.name} (${this.params?.port})`, error);
483
+ Dynamo_Log.error(`socket(${this.params.name}) Event Broadcast (${event}) failed`, error);
442
484
  throw new Dynamo_Error({
443
485
  ...this._getDefaultErrorSettings('broadcastEvent', error),
444
486
 
445
487
  errorCode: 'NTS-SSS-400',
446
- message: `Socket Event Broadcast (${event}) failed: ${this.params?.name} (${this.params?.port})`,
488
+ message: `socket(${this.params.name}) Event Broadcast (${event}) failed`,
447
489
  });
448
490
  }
449
491
  }