@futdevpro/nts-dynamo 1.10.7 → 1.10.9
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/build/_collections/stack.util.d.ts +7 -0
- package/build/_collections/stack.util.d.ts.map +1 -0
- package/build/_collections/stack.util.js +31 -0
- package/build/_collections/stack.util.js.map +1 -0
- package/build/_collections/stack.util.test.d.ts +2 -0
- package/build/_collections/stack.util.test.d.ts.map +1 -0
- package/build/_collections/stack.util.test.js +96 -0
- package/build/_collections/stack.util.test.js.map +1 -0
- package/build/_models/control-models/api-call-params.control-model.d.ts +1 -0
- package/build/_models/control-models/api-call-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/api-call-params.control-model.js +7 -3
- package/build/_models/control-models/api-call-params.control-model.js.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.d.ts +0 -1
- package/build/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js +26 -13
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_modules/mock/data-model.mock.d.ts.map +1 -1
- package/build/_modules/mock/data-model.mock.js +2 -3
- package/build/_modules/mock/data-model.mock.js.map +1 -1
- package/build/_modules/mock/data-model.mock.spec.js +0 -1
- package/build/_modules/mock/data-model.mock.spec.js.map +1 -1
- package/build/_modules/mock/socket-client.mock.js +1 -1
- package/build/_modules/mock/socket-client.mock.js.map +1 -1
- package/build/_modules/mock/socket-client.mock.spec.js +1 -1
- package/build/_modules/mock/socket-client.mock.spec.js.map +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.d.ts.map +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.js +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.js.map +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.js +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.js.map +1 -1
- package/build/_modules/socket/_services/socket-client.service.d.ts +2 -2
- package/build/_modules/socket/_services/socket-client.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-client.service.js +7 -2
- package/build/_modules/socket/_services/socket-client.service.js.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.d.ts +9 -11
- package/build/_modules/socket/_services/socket-server.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.js +243 -109
- package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
- package/build/_modules/socket/app-extended.server.d.ts.map +1 -1
- package/build/_modules/socket/app-extended.server.js +11 -2
- package/build/_modules/socket/app-extended.server.js.map +1 -1
- package/build/_modules/test/test.controller.js +6 -6
- package/build/_modules/test/test.controller.js.map +1 -1
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +9 -1
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +42 -39
- package/build/_services/base/db.service.js.map +1 -1
- package/build/_services/core/api.service.d.ts.map +1 -1
- package/build/_services/core/api.service.js +15 -8
- package/build/_services/core/api.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +2 -1
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.js +5 -5
- package/build/_services/server/app.server.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/package.json +4 -4
- package/src/_collections/stack.util.test.ts +111 -0
- package/src/_collections/stack.util.ts +33 -0
- package/src/_models/control-models/api-call-params.control-model.ts +17 -3
- package/src/_models/control-models/endpoint-params.control-model.ts +26 -19
- package/src/_modules/mock/data-model.mock.spec.ts +0 -1
- package/src/_modules/mock/data-model.mock.ts +2 -3
- package/src/_modules/mock/socket-client.mock.spec.ts +1 -1
- package/src/_modules/mock/socket-client.mock.ts +1 -1
- package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +1 -2
- package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +2 -1
- package/src/_modules/socket/_services/socket-client.service.ts +8 -4
- package/src/_modules/socket/_services/socket-server.service.ts +335 -145
- package/src/_modules/socket/app-extended.server.ts +21 -6
- package/src/_modules/test/test.controller.ts +7 -7
- package/src/_services/base/data.service.ts +21 -1
- package/src/_services/base/db.service.ts +47 -39
- package/src/_services/core/api.service.ts +18 -10
- package/src/_services/core/global.service.ts +4 -1
- package/src/_services/server/app.server.ts +7 -7
- package/src/index.ts +2 -0
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
DyNTS_SocketServerService_Params
|
|
22
22
|
} from '../_models/socket-server-service-params.control-model';
|
|
23
|
+
import { DyNTS_getStackLocation } from '../../../_collections/stack.util';
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* You need to define the following functions:
|
|
@@ -49,11 +50,11 @@ export abstract class DyNTS_SocketServerService<
|
|
|
49
50
|
protected openSocketServer: SocketIO.Server;
|
|
50
51
|
protected secureSocketServer: SocketIO.Server;
|
|
51
52
|
|
|
52
|
-
private connectEvent: DyFM_SocketEvent<SocketIO.Socket>;
|
|
53
|
+
/* private connectEvent: DyFM_SocketEvent<SocketIO.Socket>; */
|
|
53
54
|
protected incomingEvents: DyFM_SocketEvent<any>[];
|
|
54
55
|
|
|
55
|
-
private subscriptionEvent: DyFM_SocketEvent<any>;
|
|
56
|
-
private unsubscribeEvent: DyFM_SocketEvent<any>;
|
|
56
|
+
/* private subscriptionEvent: DyFM_SocketEvent<any>; */
|
|
57
|
+
/* private unsubscribeEvent: DyFM_SocketEvent<any>; */
|
|
57
58
|
|
|
58
59
|
protected presences: T_Presence[] = [];
|
|
59
60
|
|
|
@@ -64,9 +65,13 @@ export abstract class DyNTS_SocketServerService<
|
|
|
64
65
|
`We encountered an unhandled Socket Server Error, ` +
|
|
65
66
|
`\nplease contact the responsible development team.`;
|
|
66
67
|
|
|
68
|
+
/* readonly thisLocationStack: string; */
|
|
69
|
+
|
|
67
70
|
protected constructor(){
|
|
68
71
|
super();
|
|
69
72
|
|
|
73
|
+
/* this.thisLocationStack = DyNTS_getStackLocation(); */
|
|
74
|
+
|
|
70
75
|
this.asyncConstructor().catch((error: any) => {
|
|
71
76
|
DyFM_Log.error(
|
|
72
77
|
`Socket Server Service setup failed: "${this.params?.name}" (${this.params?.port})`,
|
|
@@ -114,7 +119,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
114
119
|
private async prepareEvents(): Promise<void> {
|
|
115
120
|
try {
|
|
116
121
|
/** Setup connect event */
|
|
117
|
-
const connectEventIndex = this.incomingEvents.findIndex(
|
|
122
|
+
/* const connectEventIndex = this.incomingEvents.findIndex(
|
|
118
123
|
(event: DyFM_SocketEvent<any>) =>
|
|
119
124
|
event.eventKey === DyFM_SocketEvent_Key.connection
|
|
120
125
|
);
|
|
@@ -126,111 +131,128 @@ export abstract class DyNTS_SocketServerService<
|
|
|
126
131
|
eventKey: DyFM_SocketEvent_Key.connection,
|
|
127
132
|
});
|
|
128
133
|
}
|
|
129
|
-
this.connectEvent.serviceName = this.params.name;
|
|
130
|
-
|
|
131
|
-
/** Setup subscriptions events */
|
|
132
|
-
if (this.getPresenceFromSubscriptionEventContent) {
|
|
133
|
-
/** Setup subscription event */
|
|
134
|
-
const subscriptionEventIndex = this.incomingEvents.findIndex(
|
|
135
|
-
(event: DyFM_SocketEvent<any>) =>
|
|
136
|
-
event.eventKey === DyFM_SocketEvent_Key.subscribe
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
if (0 <= subscriptionEventIndex) {
|
|
140
|
-
this.subscriptionEvent = this.incomingEvents.splice(subscriptionEventIndex)[0];
|
|
141
|
-
DyFM_Log.error(
|
|
142
|
-
`You should not set the subscription event, but the subscriptions tasks, ` +
|
|
143
|
-
`in case you need additional steps for your subscriptions.`,
|
|
144
|
-
`${this.params.name} (${this.params.port})`
|
|
145
|
-
);
|
|
146
|
-
} else {
|
|
147
|
-
this.subscriptionEvent = new DyFM_SocketEvent<T_SubscriptionContent>({
|
|
148
|
-
eventKey: DyFM_SocketEvent_Key.subscribe,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
134
|
+
this.connectEvent.serviceName = this.params.name; */
|
|
151
135
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
136
|
+
if (!this.getPresenceFromSubscriptionEventContent) {
|
|
137
|
+
throw new DyFM_Error({
|
|
138
|
+
error: new Error('getPresenceFromSubscriptionEventContent must be set'),
|
|
139
|
+
errorCode: 'NTS-SSS-PPE1',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
155
142
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
/** Setup subscription event */
|
|
162
|
-
const unsubscribeEventIndex = this.incomingEvents.findIndex(
|
|
163
|
-
(event: DyFM_SocketEvent<any>) =>
|
|
164
|
-
event.eventKey === DyFM_SocketEvent_Key.unsubscribe
|
|
143
|
+
if (!this.getSubscriptionTasks) {
|
|
144
|
+
DyFM_Log.warn(
|
|
145
|
+
`You should not set the subscription event, ` +
|
|
146
|
+
`in case you need additional steps for your subscriptions.`,
|
|
147
|
+
`${this.params.name} (${this.params.port})`
|
|
165
148
|
);
|
|
149
|
+
}
|
|
166
150
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (this.getUnsubscribePreProcesses) {
|
|
181
|
-
this.unsubscribeEvent.preProcesses.push(...this.getUnsubscribePreProcesses());
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (this.getUnsubscribeTasks) {
|
|
185
|
-
this.unsubscribeEvent.tasks.push(...this.getUnsubscribeTasks());
|
|
186
|
-
}
|
|
187
|
-
this.unsubscribeEvent.serviceName = this.params.name;
|
|
151
|
+
if (this.incomingEvents.find(
|
|
152
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
153
|
+
event.eventKey === DyFM_SocketEvent_Key.subscribe
|
|
154
|
+
)) {
|
|
155
|
+
DyFM_Log.warn(
|
|
156
|
+
`You need to use getSubscriptionTasks() ` +
|
|
157
|
+
`instead of setting the subscribe event in getIncomingEvents().`,
|
|
158
|
+
`${this.params.name} (${this.params.port})`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
188
161
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
162
|
+
if (!this.incomingEvents.find(
|
|
163
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
164
|
+
event.eventKey === DyFM_SocketEvent_Key.unsubscribe
|
|
165
|
+
)) {
|
|
166
|
+
DyFM_Log.warn(
|
|
167
|
+
`You should not set the unsubscribe event, ` +
|
|
168
|
+
`in case you need additional steps for your unsubscribe.`,
|
|
169
|
+
`${this.params.name} (${this.params.port})`
|
|
193
170
|
);
|
|
171
|
+
}
|
|
194
172
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
tasks: [
|
|
204
|
-
this.disconnectBaseTask,
|
|
205
|
-
],
|
|
206
|
-
})
|
|
207
|
-
);
|
|
208
|
-
}
|
|
173
|
+
if (this.incomingEvents.find(
|
|
174
|
+
(event: DyFM_SocketEvent<any>) => !event.eventKey
|
|
175
|
+
)) {
|
|
176
|
+
throw new DyFM_Error({
|
|
177
|
+
error: new Error('eventKey must be set'),
|
|
178
|
+
errorCode: 'NTS-SSS-PPE2',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
209
181
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
182
|
+
this.incomingEvents.push(
|
|
183
|
+
new DyFM_SocketEvent({
|
|
184
|
+
eventKey: DyFM_SocketEvent_Key.disconnect,
|
|
185
|
+
tasks: [
|
|
186
|
+
async (socket: SocketIO.Socket, issuer: string) =>
|
|
187
|
+
this.disconnectBaseTask(socket, issuer),
|
|
188
|
+
],
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (this.errorHandling) {
|
|
193
|
+
this.incomingEvents.push(new DyFM_SocketEvent<T_ErrorContent>({
|
|
194
|
+
serviceName: this.params.name,
|
|
195
|
+
eventKey: DyFM_SocketEvent_Key.error,
|
|
196
|
+
tasks: [
|
|
197
|
+
async (content: any) => this.errorHandling(content),
|
|
198
|
+
],
|
|
199
|
+
}));
|
|
200
|
+
} else {
|
|
201
|
+
DyFM_Log.warn(
|
|
202
|
+
`You should not set the error event, ` +
|
|
203
|
+
`in case you need additional steps for your error.`,
|
|
204
|
+
`${this.params.name} (${this.params.port})`
|
|
213
205
|
);
|
|
214
206
|
|
|
215
|
-
|
|
216
|
-
this.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
207
|
+
this.incomingEvents.push(new DyFM_SocketEvent<T_ErrorContent>({
|
|
208
|
+
serviceName: this.params.name,
|
|
209
|
+
eventKey: DyFM_SocketEvent_Key.error,
|
|
210
|
+
tasks: [
|
|
211
|
+
async (content: any) => {
|
|
212
|
+
if (content instanceof DyFM_Error) {
|
|
213
|
+
content.logSimple(`=--> socket-client(${this.params.name}) ERROR`);
|
|
214
|
+
} else {
|
|
215
|
+
DyFM_Log.error(`=--> socket-client(${this.params.name}) ERROR:`, content);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Merge incoming events of the same eventKey
|
|
223
|
+
const eventKeys = this.incomingEvents.map(
|
|
224
|
+
(event: DyFM_SocketEvent<any>) => event.eventKey
|
|
225
|
+
).filter(
|
|
226
|
+
(eventKey: string, index: number, self: string[]) =>
|
|
227
|
+
self.indexOf(eventKey) === index
|
|
228
|
+
);
|
|
229
|
+
const mergedEvents: DyFM_SocketEvent<any>[] = [];
|
|
230
|
+
eventKeys.forEach((eventKey: string) => {
|
|
231
|
+
const events = this.incomingEvents.filter(
|
|
232
|
+
(event: DyFM_SocketEvent<any>) => event.eventKey === eventKey
|
|
233
|
+
);
|
|
224
234
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
235
|
+
mergedEvents.push(new DyFM_SocketEvent({
|
|
236
|
+
eventKey: eventKey,
|
|
237
|
+
preProcesses: events.map((event: DyFM_SocketEvent<any>) => event.preProcesses).flat(),
|
|
238
|
+
tasks: events.map((event: DyFM_SocketEvent<any>) => event.tasks).flat(),
|
|
239
|
+
}));
|
|
240
|
+
});
|
|
241
|
+
this.incomingEvents = mergedEvents;
|
|
242
|
+
|
|
243
|
+
if (DyNTS_global_settings.log_settings.setup) {
|
|
244
|
+
DyFM_Log.log(
|
|
245
|
+
`Socket Server Service - Event Preparation setup done: ` +
|
|
246
|
+
`"${this.params?.name}" (${this.params?.port})` +
|
|
247
|
+
`\nincomingEvents:`, this.incomingEvents.map(
|
|
248
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
249
|
+
`\n\t"${event.eventKey}": preProcesses: ${event.preProcesses?.length} ` +
|
|
250
|
+
`tasks: ${event.tasks?.length}`
|
|
251
|
+
)
|
|
230
252
|
);
|
|
231
253
|
}
|
|
232
254
|
|
|
233
|
-
|
|
255
|
+
// Set incoming events serviceName
|
|
234
256
|
this.incomingEvents.forEach((event: DyFM_SocketEvent<any>) => {
|
|
235
257
|
event.serviceName = this.params.name;
|
|
236
258
|
});
|
|
@@ -254,16 +276,29 @@ export abstract class DyNTS_SocketServerService<
|
|
|
254
276
|
try {
|
|
255
277
|
if (this.highDetailedLogs) console.log('\nfn:. setupSocketServer');
|
|
256
278
|
|
|
257
|
-
newSocketServer.on(DyFM_SocketEvent_Key.
|
|
279
|
+
newSocketServer.on(DyFM_SocketEvent_Key.incomingNewConnection, async (socket: SocketIO.Socket) => {
|
|
258
280
|
try {
|
|
259
281
|
let issuer: string;
|
|
260
282
|
|
|
261
|
-
await this.connectEvent.executeEventTasks(socket);
|
|
283
|
+
/* await this.connectEvent.executeEventTasks(socket); */
|
|
284
|
+
|
|
285
|
+
await DyFM_Array.asyncForEach(
|
|
286
|
+
this.incomingEvents.filter(
|
|
287
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
288
|
+
event.eventKey === DyFM_SocketEvent_Key.incomingNewConnection
|
|
289
|
+
),
|
|
290
|
+
async (event: DyFM_SocketEvent<any>) => {
|
|
291
|
+
await event.executeEventTasks(socket);
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
|
|
262
295
|
|
|
263
296
|
if (this.getPresenceFromSubscriptionEventContent) {
|
|
264
297
|
socket.on(
|
|
265
298
|
DyFM_SocketEvent_Key.subscribe,
|
|
266
299
|
async (content: any) => {
|
|
300
|
+
let presence: T_Presence;
|
|
301
|
+
|
|
267
302
|
try {
|
|
268
303
|
/**
|
|
269
304
|
* usually socket logs are in event.executeEventTasks(),
|
|
@@ -283,7 +318,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
283
318
|
);
|
|
284
319
|
}
|
|
285
320
|
|
|
286
|
-
|
|
321
|
+
presence = await this.getPresenceFromSubscriptionEventContent(
|
|
287
322
|
content, socket
|
|
288
323
|
);
|
|
289
324
|
|
|
@@ -291,7 +326,16 @@ export abstract class DyNTS_SocketServerService<
|
|
|
291
326
|
issuer = presence.issuerLocalId;
|
|
292
327
|
|
|
293
328
|
this.addSocketToPresence(presence);
|
|
294
|
-
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
329
|
+
/* await this.subscriptionEvent.executeEventTasks(content, issuer); */
|
|
330
|
+
|
|
331
|
+
if (this.getSubscriptionTasks) {
|
|
332
|
+
await DyFM_Array.asyncForEach(
|
|
333
|
+
this.getSubscriptionTasks(),
|
|
334
|
+
async (task: DyFM_SocketEventTask<T_SubscriptionContent>) => {
|
|
335
|
+
await task(content, issuer);
|
|
336
|
+
}
|
|
337
|
+
);
|
|
338
|
+
}
|
|
295
339
|
|
|
296
340
|
socket.emit(
|
|
297
341
|
DyFM_SocketEvent_Key.subscriptionSuccessful,
|
|
@@ -308,20 +352,26 @@ export abstract class DyNTS_SocketServerService<
|
|
|
308
352
|
`<-==> socket(${this.params.name}) subscription successful (${issuer})`
|
|
309
353
|
);
|
|
310
354
|
} catch (error) {
|
|
311
|
-
if (
|
|
355
|
+
if (error instanceof DyFM_Error) {
|
|
356
|
+
error.logSimple(
|
|
357
|
+
`Socket Subscription failed: "${this.params.name}" ` +
|
|
358
|
+
`(${this.params.port}) will disconnect now...`
|
|
359
|
+
)
|
|
360
|
+
} else if (DyNTS_global_settings.log_settings.socket_eventContent) {
|
|
312
361
|
DyFM_Log.error(
|
|
313
|
-
`Socket Subscription failed: "${this.params.name}" `
|
|
362
|
+
`Socket Subscription failed: "${this.params.name}" ` +
|
|
314
363
|
`(${this.params.port}) will disconnect now...`,
|
|
364
|
+
/* `${this.thisLocationStack}`, */
|
|
315
365
|
error
|
|
316
366
|
);
|
|
317
367
|
} else {
|
|
318
368
|
DyFM_Log.error(
|
|
319
369
|
`Socket Subscription failed: "${this.params.name}" ` ,
|
|
320
|
-
`(${this.params.port}) will disconnect now
|
|
370
|
+
`(${this.params.port}) will disconnect now...`,
|
|
371
|
+
/* `${this.thisLocationStack}` */
|
|
321
372
|
);
|
|
322
373
|
}
|
|
323
|
-
|
|
324
|
-
socket.disconnect();
|
|
374
|
+
await this.closeSocket(socket, issuer, error);
|
|
325
375
|
}
|
|
326
376
|
}
|
|
327
377
|
);
|
|
@@ -347,11 +397,20 @@ export abstract class DyNTS_SocketServerService<
|
|
|
347
397
|
`event: ${DyFM_SocketEvent_Key.unsubscribe}`
|
|
348
398
|
);
|
|
349
399
|
}
|
|
400
|
+
|
|
401
|
+
/* await this.unsubscribeEvent.executeEventTasks(null, issuer); */
|
|
402
|
+
await DyFM_Array.asyncForEach(
|
|
403
|
+
this.incomingEvents.filter(
|
|
404
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
405
|
+
event.eventKey === DyFM_SocketEvent_Key.unsubscribe
|
|
406
|
+
),
|
|
407
|
+
async (event: DyFM_SocketEvent<any>) => {
|
|
408
|
+
await event.executeEventTasks(null, issuer);
|
|
409
|
+
}
|
|
410
|
+
);
|
|
350
411
|
|
|
351
412
|
this.removeSubscription(socket, issuer);
|
|
352
413
|
|
|
353
|
-
await this.unsubscribeEvent.executeEventTasks(issuer, issuer);
|
|
354
|
-
|
|
355
414
|
socket.emit(
|
|
356
415
|
DyFM_SocketEvent_Key.unsubscribeSuccessful,
|
|
357
416
|
'unsubscribe was successful',
|
|
@@ -367,7 +426,12 @@ export abstract class DyNTS_SocketServerService<
|
|
|
367
426
|
`< x > socket(${this.params.name}) unsubscribe successful (${issuer})`
|
|
368
427
|
);
|
|
369
428
|
} catch (error) {
|
|
370
|
-
if (
|
|
429
|
+
if (error instanceof DyFM_Error) {
|
|
430
|
+
error.logSimple(
|
|
431
|
+
`Socket Unsubscription failed: "${this.params.name}" ` +
|
|
432
|
+
`(${this.params.port}) will disconnect now...`
|
|
433
|
+
)
|
|
434
|
+
} else if (DyNTS_global_settings.log_settings.socket_eventContent) {
|
|
371
435
|
DyFM_Log.error(
|
|
372
436
|
`Socket unsubscribe failed: "${this.params.name}" ` ,
|
|
373
437
|
`(${this.params.port}) will disconnect now...`,
|
|
@@ -380,22 +444,34 @@ export abstract class DyNTS_SocketServerService<
|
|
|
380
444
|
);
|
|
381
445
|
}
|
|
382
446
|
socket.emit(DyFM_SocketEvent_Key.error, error);
|
|
447
|
+
this.removeSubscription(socket, issuer);
|
|
383
448
|
}
|
|
384
449
|
}
|
|
385
450
|
);
|
|
386
451
|
}
|
|
387
452
|
|
|
388
|
-
this.incomingEvents.
|
|
453
|
+
this.incomingEvents.filter(
|
|
454
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
455
|
+
event.eventKey !== DyFM_SocketEvent_Key.incomingNewConnection &&
|
|
456
|
+
event.eventKey !== DyFM_SocketEvent_Key.subscribe &&
|
|
457
|
+
event.eventKey !== DyFM_SocketEvent_Key.unsubscribe
|
|
458
|
+
).forEach((event: DyFM_SocketEvent<any>) => {
|
|
389
459
|
socket.on(
|
|
390
460
|
event.eventKey,
|
|
391
461
|
async (content: any) => {
|
|
392
462
|
try {
|
|
393
463
|
await event.executeEventTasks(content, issuer);
|
|
394
464
|
} catch (error) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
465
|
+
if (error instanceof DyFM_Error) {
|
|
466
|
+
error.logSimple(
|
|
467
|
+
`Socket Event failed: "${this.params.name}" (${this.params.port})`
|
|
468
|
+
)
|
|
469
|
+
} else {
|
|
470
|
+
DyFM_Log.error(
|
|
471
|
+
`Socket Event failed: "${this.params.name}" (${this.params.port})`,
|
|
472
|
+
error
|
|
473
|
+
);
|
|
474
|
+
}
|
|
399
475
|
socket.emit(DyFM_SocketEvent_Key.error, error);
|
|
400
476
|
}
|
|
401
477
|
}
|
|
@@ -406,13 +482,20 @@ export abstract class DyNTS_SocketServerService<
|
|
|
406
482
|
DyFM_Log.success(`< > socket(${this.params.name}): new CONNECTION established`);
|
|
407
483
|
}
|
|
408
484
|
} catch (error) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
485
|
+
if (error instanceof DyFM_Error) {
|
|
486
|
+
error.logSimple(
|
|
487
|
+
`Socket Connection failed: "${this.params.name}" ` +
|
|
488
|
+
`(${this.params.port}) will disconnect now...`
|
|
489
|
+
)
|
|
490
|
+
} else {
|
|
491
|
+
DyFM_Log.error(
|
|
492
|
+
`Socket Connection failed: "${this.params.name}" ` +
|
|
493
|
+
`(${this.params.port}) will disconnect now...`,
|
|
494
|
+
error
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
await this.closeSocket(socket, `${this.params.name} on connection error`, error);
|
|
416
499
|
}
|
|
417
500
|
});
|
|
418
501
|
|
|
@@ -435,11 +518,18 @@ export abstract class DyNTS_SocketServerService<
|
|
|
435
518
|
return this.secureSocketServer;
|
|
436
519
|
}
|
|
437
520
|
} catch (error) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
521
|
+
if (error instanceof DyFM_Error) {
|
|
522
|
+
error.logSimple(
|
|
523
|
+
`Socket Server Service - Deep Setup failed: "${this.params?.name}" ` +
|
|
524
|
+
`(${this.params?.port})`
|
|
525
|
+
)
|
|
526
|
+
} else {
|
|
527
|
+
DyFM_Log.error(
|
|
528
|
+
`Socket Server Service - Deep Setup failed: "${this.params?.name}" ` +
|
|
529
|
+
`(${this.params?.port})`,
|
|
530
|
+
error
|
|
531
|
+
);
|
|
532
|
+
}
|
|
443
533
|
|
|
444
534
|
throw error;
|
|
445
535
|
}
|
|
@@ -457,14 +547,20 @@ export abstract class DyNTS_SocketServerService<
|
|
|
457
547
|
this.presences.push(newPresence);
|
|
458
548
|
}
|
|
459
549
|
} catch (error) {
|
|
460
|
-
if (
|
|
550
|
+
if (error instanceof DyFM_Error) {
|
|
551
|
+
error.logSimple(
|
|
552
|
+
`Socket Subscription failed: "${this.params?.name}" (${this.params?.port})`
|
|
553
|
+
)
|
|
554
|
+
} else if (DyNTS_global_settings.log_settings.socket_eventContent) {
|
|
461
555
|
DyFM_Log.error(
|
|
462
|
-
`Socket Subscription failed: "${this.params?.name}" (${this.params?.port})`,
|
|
556
|
+
`Socket Subscription failed: "${this.params?.name}" (${this.params?.port})`,
|
|
557
|
+
/* `${this.thisLocationStack}`, */
|
|
463
558
|
error
|
|
464
559
|
);
|
|
465
560
|
} else {
|
|
466
561
|
DyFM_Log.error(
|
|
467
|
-
`Socket Subscription failed: "${this.params?.name}" (${this.params?.port})
|
|
562
|
+
`Socket Subscription failed: "${this.params?.name}" (${this.params?.port})`,
|
|
563
|
+
/* `${this.thisLocationStack}` */
|
|
468
564
|
);
|
|
469
565
|
}
|
|
470
566
|
|
|
@@ -472,8 +568,83 @@ export abstract class DyNTS_SocketServerService<
|
|
|
472
568
|
}
|
|
473
569
|
}
|
|
474
570
|
|
|
571
|
+
protected async closeSocket(socket: SocketIO.Socket, issuer: string, withError?: DyFM_AnyError): Promise<void> {
|
|
572
|
+
try {
|
|
573
|
+
if (withError) {
|
|
574
|
+
socket.emit(DyFM_SocketEvent_Key.error, withError);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
await DyFM_Array.asyncForEach(
|
|
578
|
+
this.incomingEvents.filter(
|
|
579
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
580
|
+
event.eventKey === DyFM_SocketEvent_Key.disconnect
|
|
581
|
+
),
|
|
582
|
+
async (event: DyFM_SocketEvent<any>) => {
|
|
583
|
+
await event.executeEventTasks(null, issuer);
|
|
584
|
+
}
|
|
585
|
+
);
|
|
586
|
+
|
|
587
|
+
/* if (this.getSubscriptionCloseTasks) {
|
|
588
|
+
await DyFM_Array.asyncForEach(
|
|
589
|
+
this.getSubscriptionCloseTasks(),
|
|
590
|
+
async (task: DyFM_SocketEventTask<null>) => {
|
|
591
|
+
await task(null, issuer);
|
|
592
|
+
}
|
|
593
|
+
);
|
|
594
|
+
} */
|
|
595
|
+
|
|
596
|
+
socket.emit(DyFM_SocketEvent_Key.disconnect);
|
|
597
|
+
socket.disconnect();
|
|
598
|
+
|
|
599
|
+
await this.removeSocketFromPresence(socket);
|
|
600
|
+
} catch (error) {
|
|
601
|
+
throw new DyFM_Error({
|
|
602
|
+
...this._getDefaultErrorSettings('closeSocket', error),
|
|
603
|
+
errorCode: 'NTS-SSS-CS0',
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
protected async removeSocketFromPresence(socket: SocketIO.Socket): Promise<void> {
|
|
609
|
+
try {
|
|
610
|
+
const presence: T_Presence = this.presences.find(
|
|
611
|
+
(pres: T_Presence) => pres.sockets.includes(socket)
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
if (presence) {
|
|
615
|
+
const socketIndex: number = presence.sockets.indexOf(socket);
|
|
616
|
+
|
|
617
|
+
if (socketIndex !== -1) {
|
|
618
|
+
presence.sockets.splice(socketIndex, 1);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (presence.sockets.length === 0) {
|
|
622
|
+
const presenceIndex: number = this.presences.indexOf(presence);
|
|
623
|
+
|
|
624
|
+
if (presenceIndex !== -1) {
|
|
625
|
+
this.presences.splice(presenceIndex, 1);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
} catch (error) {
|
|
630
|
+
throw new DyFM_Error({
|
|
631
|
+
...this._getDefaultErrorSettings('removeSocketFromPresence', error),
|
|
632
|
+
errorCode: 'NTS-SSS-RSO0',
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
475
637
|
private async disconnectBaseTask(socket: SocketIO.Socket, issuer: string): Promise<void> {
|
|
476
638
|
try {
|
|
639
|
+
if (!(socket instanceof SocketIO.Socket)) {
|
|
640
|
+
throw new DyFM_Error({
|
|
641
|
+
...this._getDefaultErrorSettings(
|
|
642
|
+
'disconnectBaseTask',
|
|
643
|
+
new Error('Socket is not a SocketIO.Socket'),
|
|
644
|
+
),
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
|
|
477
648
|
await this.removeSubscription(socket, issuer);
|
|
478
649
|
|
|
479
650
|
DyFM_Log.info(`< x > socket(${this.params.name}) disconnected (${issuer})`);
|
|
@@ -503,7 +674,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
503
674
|
new Error(
|
|
504
675
|
`closing socket(${this.params.name}) does not match any in the activePresences`
|
|
505
676
|
),
|
|
506
|
-
issuer
|
|
677
|
+
issuer ?? 'unknown issuer'
|
|
507
678
|
),
|
|
508
679
|
|
|
509
680
|
errorCode: 'NTS-SSS-RS1',
|
|
@@ -512,12 +683,12 @@ export abstract class DyNTS_SocketServerService<
|
|
|
512
683
|
|
|
513
684
|
const activePresence: DyNTS_SocketPresence = this.presences[activePresenceIndex];
|
|
514
685
|
|
|
515
|
-
if (activePresence.issuerLocalId !== issuer) {
|
|
686
|
+
if (issuer && activePresence.issuerLocalId !== issuer) {
|
|
516
687
|
throw new DyFM_Error({
|
|
517
688
|
...this._getDefaultErrorSettings(
|
|
518
689
|
'sendEventForId',
|
|
519
690
|
new Error(
|
|
520
|
-
`socket
|
|
691
|
+
`socket unsubscription for "${issuer}" and ` +
|
|
521
692
|
`"${activePresence.issuerLocalId}" does not match.`
|
|
522
693
|
),
|
|
523
694
|
issuer
|
|
@@ -536,7 +707,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
536
707
|
new Error(
|
|
537
708
|
`closing socket(${this.params.name}) does not match any in the activePresences`
|
|
538
709
|
),
|
|
539
|
-
|
|
710
|
+
activePresence.issuerLocalId
|
|
540
711
|
),
|
|
541
712
|
|
|
542
713
|
errorCode: 'NTS-SSS-RS3',
|
|
@@ -544,20 +715,31 @@ export abstract class DyNTS_SocketServerService<
|
|
|
544
715
|
}
|
|
545
716
|
|
|
546
717
|
activePresence.sockets.splice(socketIndex);
|
|
718
|
+
|
|
719
|
+
await DyFM_Array.asyncForEach(
|
|
720
|
+
this.incomingEvents.filter(
|
|
721
|
+
(event: DyFM_SocketEvent<any>) =>
|
|
722
|
+
event.eventKey === DyFM_SocketEvent_Key.unsubscribeSuccessful
|
|
723
|
+
),
|
|
724
|
+
async (event: DyFM_SocketEvent<any>) => {
|
|
725
|
+
await event.executeEventTasks(null, issuer);
|
|
726
|
+
}
|
|
727
|
+
);
|
|
547
728
|
|
|
548
|
-
if (this.getSubscriptionCloseTasks) {
|
|
729
|
+
/* if (this.getSubscriptionCloseTasks) {
|
|
549
730
|
await DyFM_Array.asyncForEach(
|
|
550
731
|
this.getSubscriptionCloseTasks(),
|
|
551
732
|
async (task: DyFM_SocketEventTask<null>) => {
|
|
552
733
|
await task(null, issuer);
|
|
553
734
|
}
|
|
554
735
|
);
|
|
555
|
-
}
|
|
736
|
+
} */
|
|
556
737
|
|
|
557
738
|
if (activePresence.sockets.length === 0) {
|
|
558
739
|
this.presences.splice(activePresenceIndex);
|
|
559
740
|
}
|
|
560
741
|
|
|
742
|
+
socket.emit(DyFM_SocketEvent_Key.unsubscribeSuccessful, 'unsubscribe was successful');
|
|
561
743
|
socket.disconnect();
|
|
562
744
|
DyFM_Log.info(`<x==> socket(${this.params.name}) unsubscription successful (${issuer})`);
|
|
563
745
|
} catch (error) {
|
|
@@ -565,7 +747,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
565
747
|
...this._getDefaultErrorSettings(
|
|
566
748
|
'sendEventForId',
|
|
567
749
|
error,
|
|
568
|
-
issuer
|
|
750
|
+
issuer ?? 'unknown issuer'
|
|
569
751
|
),
|
|
570
752
|
|
|
571
753
|
errorCode: 'NTS-SSS-RS0',
|
|
@@ -731,8 +913,14 @@ export abstract class DyNTS_SocketServerService<
|
|
|
731
913
|
presence.emitEvent(event, content, issuer);
|
|
732
914
|
});
|
|
733
915
|
} catch (error) {
|
|
734
|
-
|
|
735
|
-
|
|
916
|
+
if (DyNTS_global_settings.log_settings.detailedErrors) {
|
|
917
|
+
if (error instanceof DyFM_Error) {
|
|
918
|
+
error.logSimple(`socket(${this.params.name}) Event Broadcast (${event}) failed`);
|
|
919
|
+
} else {
|
|
920
|
+
DyFM_Log.error(`socket(${this.params.name}) Event Broadcast (${event}) failed`, error);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
736
924
|
throw new DyFM_Error({
|
|
737
925
|
...this._getDefaultErrorSettings('broadcastEvent', error),
|
|
738
926
|
|
|
@@ -769,31 +957,33 @@ export abstract class DyNTS_SocketServerService<
|
|
|
769
957
|
* You must setup events and required services in this function
|
|
770
958
|
*/
|
|
771
959
|
protected abstract getIncomingEvents(): DyFM_SocketEvent<any>[];
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* You can setup tasks for the subscription event in this function
|
|
775
|
-
*/
|
|
776
|
-
protected getSubscriptionTasks?(): DyFM_SocketEventTask<T_SubscriptionContent>[];
|
|
777
960
|
|
|
778
961
|
/**
|
|
779
962
|
* You can setup tasks for the subscription event in this function
|
|
780
963
|
*/
|
|
781
|
-
protected getSubscriptionCloseTasks?(): DyFM_SocketEventTask<null>[];
|
|
964
|
+
/* protected getSubscriptionCloseTasks?(): DyFM_SocketEventTask<null>[]; */
|
|
782
965
|
|
|
783
966
|
/**
|
|
784
967
|
* You can setup preprocesses for the subscription event in this function
|
|
785
968
|
*/
|
|
786
|
-
protected getSubscriptionPreProcesses?(): DyFM_SocketEventPreprocessTask[];
|
|
969
|
+
/* protected getSubscriptionPreProcesses?(): DyFM_SocketEventPreprocessTask[]; */
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* You can setup tasks for the subscription event in this function
|
|
973
|
+
* This will happen after the presence is created
|
|
974
|
+
* If this throws an error, the socket will be closed
|
|
975
|
+
*/
|
|
976
|
+
protected getSubscriptionTasks?(): DyFM_SocketEventTask<T_SubscriptionContent>[];
|
|
787
977
|
|
|
788
978
|
/**
|
|
789
979
|
* You can setup tasks for the unsubscribe event in this function
|
|
790
980
|
*/
|
|
791
|
-
protected getUnsubscribeTasks?(): DyFM_SocketEventTask<T_SubscriptionContent>[];
|
|
981
|
+
/* protected getUnsubscribeTasks?(): DyFM_SocketEventTask<T_SubscriptionContent>[]; */
|
|
792
982
|
|
|
793
983
|
/**
|
|
794
984
|
* You can setup preprocesses for the unsubscribe event in this function
|
|
795
985
|
*/
|
|
796
|
-
protected getUnsubscribePreProcesses?(): DyFM_SocketEventPreprocessTask[];
|
|
986
|
+
/* protected getUnsubscribePreProcesses?(): DyFM_SocketEventPreprocessTask[]; */
|
|
797
987
|
|
|
798
988
|
/**
|
|
799
989
|
* You can setup tasks for the error event in this function
|