@futdevpro/nts-dynamo 1.10.8 → 1.10.10
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/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/app-params.control-model.js +11 -0
- package/build/_models/control-models/app-params.control-model.js.map +1 -1
- package/build/_modules/mock/data-model.mock.js +2 -2
- package/build/_modules/mock/data-model.mock.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 +1 -1
- 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 +198 -100
- package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
- package/build/_services/base/data.service.d.ts +17 -10
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +137 -107
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/base/db.service.d.ts +20 -10
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +66 -47
- 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 +18 -2
- package/build/_services/core/api.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +8 -1
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +3 -3
- package/src/_models/control-models/app-params.control-model.ts +17 -0
- package/src/_modules/mock/data-model.mock.ts +2 -2
- 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 +7 -3
- package/src/_modules/socket/_services/socket-server.service.ts +271 -125
- package/src/_services/base/data.service.ts +216 -165
- package/src/_services/base/db.service.ts +86 -60
- package/src/_services/core/api.service.ts +23 -2
- package/src/_services/server/app.server.ts +13 -4
|
@@ -50,11 +50,11 @@ export abstract class DyNTS_SocketServerService<
|
|
|
50
50
|
protected openSocketServer: SocketIO.Server;
|
|
51
51
|
protected secureSocketServer: SocketIO.Server;
|
|
52
52
|
|
|
53
|
-
private connectEvent: DyFM_SocketEvent<SocketIO.Socket>;
|
|
53
|
+
/* private connectEvent: DyFM_SocketEvent<SocketIO.Socket>; */
|
|
54
54
|
protected incomingEvents: DyFM_SocketEvent<any>[];
|
|
55
55
|
|
|
56
|
-
private subscriptionEvent: DyFM_SocketEvent<any>;
|
|
57
|
-
private unsubscribeEvent: DyFM_SocketEvent<any>;
|
|
56
|
+
/* private subscriptionEvent: DyFM_SocketEvent<any>; */
|
|
57
|
+
/* private unsubscribeEvent: DyFM_SocketEvent<any>; */
|
|
58
58
|
|
|
59
59
|
protected presences: T_Presence[] = [];
|
|
60
60
|
|
|
@@ -119,7 +119,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
119
119
|
private async prepareEvents(): Promise<void> {
|
|
120
120
|
try {
|
|
121
121
|
/** Setup connect event */
|
|
122
|
-
const connectEventIndex = this.incomingEvents.findIndex(
|
|
122
|
+
/* const connectEventIndex = this.incomingEvents.findIndex(
|
|
123
123
|
(event: DyFM_SocketEvent<any>) =>
|
|
124
124
|
event.eventKey === DyFM_SocketEvent_Key.connection
|
|
125
125
|
);
|
|
@@ -131,111 +131,128 @@ export abstract class DyNTS_SocketServerService<
|
|
|
131
131
|
eventKey: DyFM_SocketEvent_Key.connection,
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
-
this.connectEvent.serviceName = this.params.name;
|
|
134
|
+
this.connectEvent.serviceName = this.params.name; */
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
if (0 <= subscriptionEventIndex) {
|
|
145
|
-
this.subscriptionEvent = this.incomingEvents.splice(subscriptionEventIndex)[0];
|
|
146
|
-
DyFM_Log.error(
|
|
147
|
-
`You should not set the subscription event, but the subscriptions tasks, ` +
|
|
148
|
-
`in case you need additional steps for your subscriptions.`,
|
|
149
|
-
`${this.params.name} (${this.params.port})`
|
|
150
|
-
);
|
|
151
|
-
} else {
|
|
152
|
-
this.subscriptionEvent = new DyFM_SocketEvent<T_SubscriptionContent>({
|
|
153
|
-
eventKey: DyFM_SocketEvent_Key.subscribe,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (this.getSubscriptionPreProcesses) {
|
|
158
|
-
this.subscriptionEvent.preProcesses.push(...this.getSubscriptionPreProcesses());
|
|
159
|
-
}
|
|
136
|
+
if (!this.getPresenceFromSubscriptionEventContent) {
|
|
137
|
+
throw new DyFM_Error({
|
|
138
|
+
error: new Error('getPresenceFromSubscriptionEventContent must be set'),
|
|
139
|
+
errorCode: 'NTS-SSS-PPE1',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
160
142
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
/** Setup subscription event */
|
|
167
|
-
const unsubscribeEventIndex = this.incomingEvents.findIndex(
|
|
168
|
-
(event: DyFM_SocketEvent<any>) =>
|
|
169
|
-
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})`
|
|
170
148
|
);
|
|
149
|
+
}
|
|
171
150
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (this.getUnsubscribePreProcesses) {
|
|
186
|
-
this.unsubscribeEvent.preProcesses.push(...this.getUnsubscribePreProcesses());
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (this.getUnsubscribeTasks) {
|
|
190
|
-
this.unsubscribeEvent.tasks.push(...this.getUnsubscribeTasks());
|
|
191
|
-
}
|
|
192
|
-
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
|
+
}
|
|
193
161
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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})`
|
|
198
170
|
);
|
|
171
|
+
}
|
|
199
172
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
tasks: [
|
|
209
|
-
this.disconnectBaseTask,
|
|
210
|
-
],
|
|
211
|
-
})
|
|
212
|
-
);
|
|
213
|
-
}
|
|
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
|
+
}
|
|
214
181
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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})`
|
|
218
205
|
);
|
|
219
206
|
|
|
220
|
-
|
|
221
|
-
this.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
+
);
|
|
229
234
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
)
|
|
235
252
|
);
|
|
236
253
|
}
|
|
237
254
|
|
|
238
|
-
|
|
255
|
+
// Set incoming events serviceName
|
|
239
256
|
this.incomingEvents.forEach((event: DyFM_SocketEvent<any>) => {
|
|
240
257
|
event.serviceName = this.params.name;
|
|
241
258
|
});
|
|
@@ -259,16 +276,29 @@ export abstract class DyNTS_SocketServerService<
|
|
|
259
276
|
try {
|
|
260
277
|
if (this.highDetailedLogs) console.log('\nfn:. setupSocketServer');
|
|
261
278
|
|
|
262
|
-
newSocketServer.on(DyFM_SocketEvent_Key.
|
|
279
|
+
newSocketServer.on(DyFM_SocketEvent_Key.incomingNewConnection, async (socket: SocketIO.Socket) => {
|
|
263
280
|
try {
|
|
264
281
|
let issuer: string;
|
|
265
282
|
|
|
266
|
-
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
|
+
|
|
267
295
|
|
|
268
296
|
if (this.getPresenceFromSubscriptionEventContent) {
|
|
269
297
|
socket.on(
|
|
270
298
|
DyFM_SocketEvent_Key.subscribe,
|
|
271
299
|
async (content: any) => {
|
|
300
|
+
let presence: T_Presence;
|
|
301
|
+
|
|
272
302
|
try {
|
|
273
303
|
/**
|
|
274
304
|
* usually socket logs are in event.executeEventTasks(),
|
|
@@ -288,7 +318,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
288
318
|
);
|
|
289
319
|
}
|
|
290
320
|
|
|
291
|
-
|
|
321
|
+
presence = await this.getPresenceFromSubscriptionEventContent(
|
|
292
322
|
content, socket
|
|
293
323
|
);
|
|
294
324
|
|
|
@@ -296,7 +326,16 @@ export abstract class DyNTS_SocketServerService<
|
|
|
296
326
|
issuer = presence.issuerLocalId;
|
|
297
327
|
|
|
298
328
|
this.addSocketToPresence(presence);
|
|
299
|
-
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
|
+
}
|
|
300
339
|
|
|
301
340
|
socket.emit(
|
|
302
341
|
DyFM_SocketEvent_Key.subscriptionSuccessful,
|
|
@@ -332,9 +371,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
332
371
|
/* `${this.thisLocationStack}` */
|
|
333
372
|
);
|
|
334
373
|
}
|
|
335
|
-
|
|
336
|
-
socket.emit(DyFM_SocketEvent_Key.disconnect);
|
|
337
|
-
socket.disconnect();
|
|
374
|
+
await this.closeSocket(socket, issuer, error);
|
|
338
375
|
}
|
|
339
376
|
}
|
|
340
377
|
);
|
|
@@ -360,11 +397,20 @@ export abstract class DyNTS_SocketServerService<
|
|
|
360
397
|
`event: ${DyFM_SocketEvent_Key.unsubscribe}`
|
|
361
398
|
);
|
|
362
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
|
+
);
|
|
363
411
|
|
|
364
412
|
this.removeSubscription(socket, issuer);
|
|
365
413
|
|
|
366
|
-
await this.unsubscribeEvent.executeEventTasks(issuer, issuer);
|
|
367
|
-
|
|
368
414
|
socket.emit(
|
|
369
415
|
DyFM_SocketEvent_Key.unsubscribeSuccessful,
|
|
370
416
|
'unsubscribe was successful',
|
|
@@ -398,12 +444,18 @@ export abstract class DyNTS_SocketServerService<
|
|
|
398
444
|
);
|
|
399
445
|
}
|
|
400
446
|
socket.emit(DyFM_SocketEvent_Key.error, error);
|
|
447
|
+
this.removeSubscription(socket, issuer);
|
|
401
448
|
}
|
|
402
449
|
}
|
|
403
450
|
);
|
|
404
451
|
}
|
|
405
452
|
|
|
406
|
-
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>) => {
|
|
407
459
|
socket.on(
|
|
408
460
|
event.eventKey,
|
|
409
461
|
async (content: any) => {
|
|
@@ -442,8 +494,8 @@ export abstract class DyNTS_SocketServerService<
|
|
|
442
494
|
error
|
|
443
495
|
);
|
|
444
496
|
}
|
|
445
|
-
|
|
446
|
-
socket.
|
|
497
|
+
|
|
498
|
+
await this.closeSocket(socket, `${this.params.name} on connection error`, error);
|
|
447
499
|
}
|
|
448
500
|
});
|
|
449
501
|
|
|
@@ -516,8 +568,83 @@ export abstract class DyNTS_SocketServerService<
|
|
|
516
568
|
}
|
|
517
569
|
}
|
|
518
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
|
+
|
|
519
637
|
private async disconnectBaseTask(socket: SocketIO.Socket, issuer: string): Promise<void> {
|
|
520
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
|
+
|
|
521
648
|
await this.removeSubscription(socket, issuer);
|
|
522
649
|
|
|
523
650
|
DyFM_Log.info(`< x > socket(${this.params.name}) disconnected (${issuer})`);
|
|
@@ -547,7 +674,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
547
674
|
new Error(
|
|
548
675
|
`closing socket(${this.params.name}) does not match any in the activePresences`
|
|
549
676
|
),
|
|
550
|
-
issuer
|
|
677
|
+
issuer ?? 'unknown issuer'
|
|
551
678
|
),
|
|
552
679
|
|
|
553
680
|
errorCode: 'NTS-SSS-RS1',
|
|
@@ -556,12 +683,12 @@ export abstract class DyNTS_SocketServerService<
|
|
|
556
683
|
|
|
557
684
|
const activePresence: DyNTS_SocketPresence = this.presences[activePresenceIndex];
|
|
558
685
|
|
|
559
|
-
if (activePresence.issuerLocalId !== issuer) {
|
|
686
|
+
if (issuer && activePresence.issuerLocalId !== issuer) {
|
|
560
687
|
throw new DyFM_Error({
|
|
561
688
|
...this._getDefaultErrorSettings(
|
|
562
689
|
'sendEventForId',
|
|
563
690
|
new Error(
|
|
564
|
-
`socket
|
|
691
|
+
`socket unsubscription for "${issuer}" and ` +
|
|
565
692
|
`"${activePresence.issuerLocalId}" does not match.`
|
|
566
693
|
),
|
|
567
694
|
issuer
|
|
@@ -580,7 +707,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
580
707
|
new Error(
|
|
581
708
|
`closing socket(${this.params.name}) does not match any in the activePresences`
|
|
582
709
|
),
|
|
583
|
-
|
|
710
|
+
activePresence.issuerLocalId
|
|
584
711
|
),
|
|
585
712
|
|
|
586
713
|
errorCode: 'NTS-SSS-RS3',
|
|
@@ -588,20 +715,31 @@ export abstract class DyNTS_SocketServerService<
|
|
|
588
715
|
}
|
|
589
716
|
|
|
590
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
|
+
);
|
|
591
728
|
|
|
592
|
-
if (this.getSubscriptionCloseTasks) {
|
|
729
|
+
/* if (this.getSubscriptionCloseTasks) {
|
|
593
730
|
await DyFM_Array.asyncForEach(
|
|
594
731
|
this.getSubscriptionCloseTasks(),
|
|
595
732
|
async (task: DyFM_SocketEventTask<null>) => {
|
|
596
733
|
await task(null, issuer);
|
|
597
734
|
}
|
|
598
735
|
);
|
|
599
|
-
}
|
|
736
|
+
} */
|
|
600
737
|
|
|
601
738
|
if (activePresence.sockets.length === 0) {
|
|
602
739
|
this.presences.splice(activePresenceIndex);
|
|
603
740
|
}
|
|
604
741
|
|
|
742
|
+
socket.emit(DyFM_SocketEvent_Key.unsubscribeSuccessful, 'unsubscribe was successful');
|
|
605
743
|
socket.disconnect();
|
|
606
744
|
DyFM_Log.info(`<x==> socket(${this.params.name}) unsubscription successful (${issuer})`);
|
|
607
745
|
} catch (error) {
|
|
@@ -609,7 +747,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
609
747
|
...this._getDefaultErrorSettings(
|
|
610
748
|
'sendEventForId',
|
|
611
749
|
error,
|
|
612
|
-
issuer
|
|
750
|
+
issuer ?? 'unknown issuer'
|
|
613
751
|
),
|
|
614
752
|
|
|
615
753
|
errorCode: 'NTS-SSS-RS0',
|
|
@@ -775,8 +913,14 @@ export abstract class DyNTS_SocketServerService<
|
|
|
775
913
|
presence.emitEvent(event, content, issuer);
|
|
776
914
|
});
|
|
777
915
|
} catch (error) {
|
|
778
|
-
|
|
779
|
-
|
|
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
|
+
|
|
780
924
|
throw new DyFM_Error({
|
|
781
925
|
...this._getDefaultErrorSettings('broadcastEvent', error),
|
|
782
926
|
|
|
@@ -813,31 +957,33 @@ export abstract class DyNTS_SocketServerService<
|
|
|
813
957
|
* You must setup events and required services in this function
|
|
814
958
|
*/
|
|
815
959
|
protected abstract getIncomingEvents(): DyFM_SocketEvent<any>[];
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* You can setup tasks for the subscription event in this function
|
|
819
|
-
*/
|
|
820
|
-
protected getSubscriptionTasks?(): DyFM_SocketEventTask<T_SubscriptionContent>[];
|
|
821
960
|
|
|
822
961
|
/**
|
|
823
962
|
* You can setup tasks for the subscription event in this function
|
|
824
963
|
*/
|
|
825
|
-
protected getSubscriptionCloseTasks?(): DyFM_SocketEventTask<null>[];
|
|
964
|
+
/* protected getSubscriptionCloseTasks?(): DyFM_SocketEventTask<null>[]; */
|
|
826
965
|
|
|
827
966
|
/**
|
|
828
967
|
* You can setup preprocesses for the subscription event in this function
|
|
829
968
|
*/
|
|
830
|
-
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>[];
|
|
831
977
|
|
|
832
978
|
/**
|
|
833
979
|
* You can setup tasks for the unsubscribe event in this function
|
|
834
980
|
*/
|
|
835
|
-
protected getUnsubscribeTasks?(): DyFM_SocketEventTask<T_SubscriptionContent>[];
|
|
981
|
+
/* protected getUnsubscribeTasks?(): DyFM_SocketEventTask<T_SubscriptionContent>[]; */
|
|
836
982
|
|
|
837
983
|
/**
|
|
838
984
|
* You can setup preprocesses for the unsubscribe event in this function
|
|
839
985
|
*/
|
|
840
|
-
protected getUnsubscribePreProcesses?(): DyFM_SocketEventPreprocessTask[];
|
|
986
|
+
/* protected getUnsubscribePreProcesses?(): DyFM_SocketEventPreprocessTask[]; */
|
|
841
987
|
|
|
842
988
|
/**
|
|
843
989
|
* You can setup tasks for the error event in this function
|