@futdevpro/nts-dynamo 1.6.45 → 1.6.46
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/_constants/mocks/socket-client.mock.js +1 -1
- package/lib/_constants/mocks/socket-client.mock.js.map +1 -1
- package/lib/_enums/http/socket-event-type.enum.d.ts +1 -1
- package/lib/_enums/http/socket-event-type.enum.d.ts.map +1 -1
- package/lib/_enums/http/socket-event-type.enum.js +12 -12
- package/lib/_enums/http/socket-event-type.enum.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.d.ts +6 -5
- package/lib/_models/control-models/socket-event.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js +15 -19
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +10 -2
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_services/socket/socket-client.service.js +6 -6
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +1 -1
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +36 -27
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_constants/mocks/socket-client.mock.ts +2 -2
- package/src/_enums/http/socket-event-type.enum.ts +2 -2
- package/src/_models/control-models/socket-event.control-model.ts +18 -22
- package/src/_models/control-models/socket-presence.control-model.ts +11 -2
- package/src/_services/socket/socket-client.service.ts +7 -7
- package/src/_services/socket/socket-server.service.ts +45 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DynamoNTS_SocketEventKey } from '../../_enums';
|
|
2
2
|
import { DynamoNTS_SocketClientServiceParams, DynamoNTS_SocketEvent } from '../../_models';
|
|
3
3
|
import { DynamoNTS_SocketClientService } from '../../_modules/app-extended.index';
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ export class SocketClient_Mock extends DynamoNTS_SocketClientService {
|
|
|
18
18
|
return [
|
|
19
19
|
new DynamoNTS_SocketEvent({
|
|
20
20
|
name: 'connect',
|
|
21
|
-
|
|
21
|
+
eventKey: DynamoNTS_SocketEventKey.connect,
|
|
22
22
|
tasks: [
|
|
23
23
|
async (content: any, issuer: string) => {
|
|
24
24
|
console.log('SocketClient_Mock: connect event received');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
export enum
|
|
2
|
+
export enum DynamoNTS_SocketEventKey {
|
|
3
3
|
/** incoming connection */
|
|
4
4
|
connection = 'connection',
|
|
5
5
|
/** outgoing connection */
|
|
6
6
|
connect = 'connect',
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
subscribe = 'subscribe',
|
|
9
9
|
subscriptionSuccessful = 'subscriptionSuccessful',
|
|
10
10
|
unsubscribe = 'unsubscribe',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { Dynamo_Array, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
3
3
|
import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
4
|
-
import {
|
|
4
|
+
import { DynamoNTS_SocketEventKey } from '../../_enums/http/socket-event-type.enum';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export type DynamoNTS_SocketEventPreprocessTask<T = any, R = any> = (content?: T, issuer?: string) => Promise<R>;
|
|
@@ -12,7 +12,7 @@ export type DynamoNTS_SocketEventTask<T> = (content?: T, issuer?: string) => Pro
|
|
|
12
12
|
*/
|
|
13
13
|
export class DynamoNTS_SocketEvent<T>{
|
|
14
14
|
socketName?: string;
|
|
15
|
-
|
|
15
|
+
eventKey: DynamoNTS_SocketEventKey | string;
|
|
16
16
|
|
|
17
17
|
preProcessess?: DynamoNTS_SocketEventPreprocessTask<any, any>[];
|
|
18
18
|
tasks?: DynamoNTS_SocketEventTask<T>[];
|
|
@@ -23,14 +23,15 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
23
23
|
constructor(
|
|
24
24
|
set: {
|
|
25
25
|
/**
|
|
26
|
-
* naming the socket will help to follow events on service
|
|
26
|
+
* naming the socket will help to follow events on service,
|
|
27
|
+
* if not set, the eventKey will be used
|
|
27
28
|
*/
|
|
28
|
-
name
|
|
29
|
+
name?: string,
|
|
29
30
|
/**
|
|
30
31
|
* define socket event type such as;
|
|
31
32
|
* connection, connect, disconnect, message, error, or anything else
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
+
eventKey: DynamoNTS_SocketEventKey | string,
|
|
34
35
|
/**
|
|
35
36
|
* preprocesses are the functions the service needs to run before the actual function,
|
|
36
37
|
* these can be used for authentications, or translating data
|
|
@@ -53,36 +54,31 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
53
54
|
}
|
|
54
55
|
) {
|
|
55
56
|
try {
|
|
56
|
-
this.socketName = set.name;
|
|
57
|
-
this.
|
|
57
|
+
this.socketName = set.name ?? set.eventKey;
|
|
58
|
+
this.eventKey = set.eventKey;
|
|
58
59
|
|
|
59
60
|
this.preProcessess = set.preProcessess ?? [];
|
|
60
61
|
this.tasks = set.tasks ?? [];
|
|
61
62
|
|
|
62
63
|
if (set.logEvent !== undefined) {
|
|
63
64
|
this.logEvent = set.logEvent;
|
|
64
|
-
} else if (this.
|
|
65
|
+
} else if (this.eventKey === DynamoNTS_SocketEventKey.subscribe) {
|
|
65
66
|
this.logEvent = false;
|
|
66
67
|
} else if (
|
|
67
68
|
([
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
] as string[]).includes(this.eventType)
|
|
69
|
+
DynamoNTS_SocketEventKey.connection,
|
|
70
|
+
DynamoNTS_SocketEventKey.connect,
|
|
71
|
+
DynamoNTS_SocketEventKey.disconnect,
|
|
72
|
+
] as string[]).includes(this.eventKey)
|
|
73
73
|
) {
|
|
74
74
|
this.logEvent = dynamoNTS_globalSettings.logMainSocketEvents || dynamoNTS_globalSettings.logAllSocketEvent;
|
|
75
75
|
} else {
|
|
76
76
|
this.logEvent = dynamoNTS_globalSettings.logAllSocketEvent;
|
|
77
77
|
}
|
|
78
78
|
this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.logSocketEventContent;
|
|
79
|
-
|
|
80
|
-
/* if (this.logEvent) {
|
|
81
|
-
this.preProcessess.unshift(this.getPreLog());
|
|
82
|
-
} */
|
|
83
79
|
} catch (error) {
|
|
84
80
|
Dynamo_Log.error(
|
|
85
|
-
`\nSocket Event params setup failed (${this.socketName}): ${set.
|
|
81
|
+
`\nSocket Event params setup failed (${this.socketName}): ${set.eventKey}`, error);
|
|
86
82
|
throw error;
|
|
87
83
|
}
|
|
88
84
|
}
|
|
@@ -93,10 +89,10 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
93
89
|
*/
|
|
94
90
|
private async getPreLog(content: T, issuer?: string): Promise<void> {
|
|
95
91
|
try {
|
|
96
|
-
if (this.logEventContent && this.
|
|
97
|
-
Dynamo_Log.log(`---> incoming socket(${this.socketName}) event: ${this.
|
|
92
|
+
if (this.logEventContent && this.eventKey !== DynamoNTS_SocketEventKey.connection) {
|
|
93
|
+
Dynamo_Log.log(`---> incoming socket(${this.socketName}) event: ${this.eventKey};\ncontent:`, content);
|
|
98
94
|
} else {
|
|
99
|
-
Dynamo_Log.log(`---> incoming socket(${this.socketName}) event: ${this.
|
|
95
|
+
Dynamo_Log.log(`---> incoming socket(${this.socketName}) event: ${this.eventKey}...`);
|
|
100
96
|
}
|
|
101
97
|
} catch (error) {
|
|
102
98
|
Dynamo_Log.error(`PreLog failed... (socket: ${this.socketName})`, error);
|
|
@@ -121,7 +117,7 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
121
117
|
await task(content, issuer);
|
|
122
118
|
});
|
|
123
119
|
} catch (error) {
|
|
124
|
-
Dynamo_Log.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.
|
|
120
|
+
Dynamo_Log.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.eventKey})`, error, 'content:', content);
|
|
125
121
|
}
|
|
126
122
|
}
|
|
127
123
|
}
|
|
@@ -47,19 +47,22 @@ export class DynamoNTS_SocketPresence {
|
|
|
47
47
|
emitEvent?(event: string, content: any) {
|
|
48
48
|
let anyFailed: boolean = false;
|
|
49
49
|
const errors = [];
|
|
50
|
+
const inactiveSockets: SocketIO.Socket[] = [];
|
|
50
51
|
|
|
51
52
|
this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
|
|
52
53
|
if (!socket.connected) {
|
|
53
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${index}) failed! socket[${socket}] is not connected!`);
|
|
54
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${index}) failed! socket[${socket.id}] is not connected!`);
|
|
55
|
+
anyFailed = true;
|
|
54
56
|
errors.push(
|
|
55
57
|
new Dynamo_Error({
|
|
56
58
|
status: 500,
|
|
57
59
|
errorCode: 'NTS-SPC-EE1',
|
|
58
60
|
addECToUserMsg: true,
|
|
59
|
-
message: `Emitting event '${event}' on socket(${index}) failed! socket[${socket}] is not connected!`,
|
|
61
|
+
message: `Emitting event '${event}' on socket(${index}) failed! socket[${socket.id}] is not connected!`,
|
|
60
62
|
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
61
63
|
})
|
|
62
64
|
);
|
|
65
|
+
inactiveSockets.push(socket);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
const success: boolean = socket.emit(event, content, error => {
|
|
@@ -74,6 +77,8 @@ export class DynamoNTS_SocketPresence {
|
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
if (anyFailed) {
|
|
80
|
+
/* this.sockets = this.sockets.filter(socket => !inactiveSockets.includes(socket)); */
|
|
81
|
+
|
|
77
82
|
throw new Dynamo_Error({
|
|
78
83
|
status: 500,
|
|
79
84
|
errorCode: 'NTS-SPC-EE2',
|
|
@@ -81,6 +86,10 @@ export class DynamoNTS_SocketPresence {
|
|
|
81
86
|
message: `Emitting event '${event}' on socket(s) failed!`,
|
|
82
87
|
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
83
88
|
/* errors: errors, */
|
|
89
|
+
additionalContent: {
|
|
90
|
+
inactiveSockets: inactiveSockets,
|
|
91
|
+
errors: errors,
|
|
92
|
+
}
|
|
84
93
|
});
|
|
85
94
|
}
|
|
86
95
|
}
|
|
@@ -9,7 +9,7 @@ import { delay, Dynamo_Array } from '@futdevpro/fsm-dynamo/utils';
|
|
|
9
9
|
import { DynamoNTS_SocketClientServiceParams } from '../../_models/control-models/socket-client-service-params.control-model';
|
|
10
10
|
import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
11
11
|
import { DynamoNTS_SocketEvent } from '../../_models/control-models/socket-event.control-model';
|
|
12
|
-
import {
|
|
12
|
+
import { DynamoNTS_SocketEventKey } from '../../_enums/http/socket-event-type.enum';
|
|
13
13
|
|
|
14
14
|
export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonService {
|
|
15
15
|
|
|
@@ -30,7 +30,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
30
30
|
private defaultEvents: DynamoNTS_SocketEvent<any>[] = [
|
|
31
31
|
new DynamoNTS_SocketEvent<any>({
|
|
32
32
|
name: 'connect',
|
|
33
|
-
|
|
33
|
+
eventKey: DynamoNTS_SocketEventKey.connect,
|
|
34
34
|
tasks: [
|
|
35
35
|
async () => {
|
|
36
36
|
this._connected = true;
|
|
@@ -40,7 +40,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
40
40
|
}),
|
|
41
41
|
new DynamoNTS_SocketEvent<any>({
|
|
42
42
|
name: 'disconnect',
|
|
43
|
-
|
|
43
|
+
eventKey: DynamoNTS_SocketEventKey.disconnect,
|
|
44
44
|
tasks: [
|
|
45
45
|
async () => {
|
|
46
46
|
this._connected = false;
|
|
@@ -55,7 +55,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
55
55
|
}),
|
|
56
56
|
new DynamoNTS_SocketEvent<any>({
|
|
57
57
|
name: 'error',
|
|
58
|
-
|
|
58
|
+
eventKey: DynamoNTS_SocketEventKey.error,
|
|
59
59
|
tasks: [
|
|
60
60
|
async (content: any) => {
|
|
61
61
|
Dynamo_Log.error(`Socket Client error: ${this.params.name}`, content);
|
|
@@ -98,7 +98,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
98
98
|
try {
|
|
99
99
|
if (this.logFn) console.log('\nFn:. setupDefaultEvents')
|
|
100
100
|
this.defaultEvents.forEach((defaultEvent: DynamoNTS_SocketEvent<any>) => {
|
|
101
|
-
const eventDeclared = this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.
|
|
101
|
+
const eventDeclared = this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.eventKey === defaultEvent.eventKey);
|
|
102
102
|
if (!eventDeclared) {
|
|
103
103
|
this.incomingEvents.push(defaultEvent);
|
|
104
104
|
} else {
|
|
@@ -119,12 +119,12 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
119
119
|
if (!event.socketName) {
|
|
120
120
|
event.socketName = this.name;
|
|
121
121
|
}
|
|
122
|
-
this.socket.on(event.
|
|
122
|
+
this.socket.on(event.eventKey, async (content: any) => {
|
|
123
123
|
try {
|
|
124
124
|
await event.executeEventTasks(content, this.params.service);
|
|
125
125
|
} catch (error) {
|
|
126
126
|
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
127
|
-
await this.emitEvent(
|
|
127
|
+
await this.emitEvent(DynamoNTS_SocketEventKey.error, error);
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
130
|
});
|
|
@@ -5,7 +5,7 @@ import { Dynamo_Array, Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
|
5
5
|
|
|
6
6
|
import { DynamoNTS_SingletonService } from '../base/singleton.service';
|
|
7
7
|
import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
8
|
-
import {
|
|
8
|
+
import { DynamoNTS_SocketEventKey } from '../../_enums/http/socket-event-type.enum';
|
|
9
9
|
import { DynamoNTS_SocketSecurity } from '../../_enums/socket-security.enum';
|
|
10
10
|
import { DynamoNTS_SocketServerServiceParams } from '../../_models/control-models/socket-server-service-params.control-model';
|
|
11
11
|
import { DynamoNTS_SocketPresence } from '../../_models/control-models/socket-presence.control-model';
|
|
@@ -88,19 +88,18 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
88
88
|
*/
|
|
89
89
|
private async prepareEvents(): Promise<void> {
|
|
90
90
|
try {
|
|
91
|
-
const connectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
91
|
+
const connectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.connection);
|
|
92
92
|
if (0 <= connectEventIndex) {
|
|
93
93
|
this.connectEvent = this.incomingEvents.splice(connectEventIndex)[0];
|
|
94
94
|
} else {
|
|
95
95
|
this.connectEvent = new DynamoNTS_SocketEvent({
|
|
96
|
-
|
|
97
|
-
eventType: DynamoNTS_SocketEventType.connection,
|
|
96
|
+
eventKey: DynamoNTS_SocketEventKey.connection,
|
|
98
97
|
});
|
|
99
98
|
}
|
|
100
99
|
this.connectEvent.socketName = this.params.name;
|
|
101
100
|
|
|
102
101
|
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
103
|
-
const subscriptionEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
102
|
+
const subscriptionEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.subscribe);
|
|
104
103
|
if (0 <= subscriptionEventIndex) {
|
|
105
104
|
this.subscriptionEvent = this.incomingEvents.splice(subscriptionEventIndex)[0];
|
|
106
105
|
Dynamo_Log.error(
|
|
@@ -110,8 +109,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
110
109
|
);
|
|
111
110
|
} else {
|
|
112
111
|
this.subscriptionEvent = new DynamoNTS_SocketEvent<T_SubscriptionContent>({
|
|
113
|
-
|
|
114
|
-
eventType: DynamoNTS_SocketEventType.subscribe
|
|
112
|
+
eventKey: DynamoNTS_SocketEventKey.subscribe
|
|
115
113
|
});
|
|
116
114
|
}
|
|
117
115
|
if (this.getSubscriptionPreProcessess) {
|
|
@@ -121,26 +119,24 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
121
119
|
this.subscriptionEvent.tasks.push(...this.getSubscriptionTasks());
|
|
122
120
|
}
|
|
123
121
|
|
|
124
|
-
const disconnectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
122
|
+
const disconnectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.disconnect);
|
|
125
123
|
if (0 <= disconnectEventIndex) {
|
|
126
|
-
this.incomingEvents[disconnectEventIndex].tasks.push(this.
|
|
124
|
+
this.incomingEvents[disconnectEventIndex].tasks.push(this.removeSubscription);
|
|
127
125
|
} else {
|
|
128
126
|
this.incomingEvents.push(
|
|
129
127
|
new DynamoNTS_SocketEvent({
|
|
130
|
-
|
|
131
|
-
eventType: DynamoNTS_SocketEventType.disconnect,
|
|
128
|
+
eventKey: DynamoNTS_SocketEventKey.disconnect,
|
|
132
129
|
tasks: [
|
|
133
|
-
this.
|
|
130
|
+
this.removeSubscription
|
|
134
131
|
]
|
|
135
132
|
})
|
|
136
133
|
);
|
|
137
134
|
}
|
|
138
135
|
|
|
139
|
-
const errorEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
136
|
+
const errorEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventKey === DynamoNTS_SocketEventKey.error);
|
|
140
137
|
if (errorEventIndex == -1 && this.errorHandling) {
|
|
141
138
|
this.incomingEvents.push(new DynamoNTS_SocketEvent<T_ErrorContent>({
|
|
142
|
-
|
|
143
|
-
eventType: DynamoNTS_SocketEventType.error,
|
|
139
|
+
eventKey: DynamoNTS_SocketEventKey.error,
|
|
144
140
|
tasks: [
|
|
145
141
|
this.errorHandling
|
|
146
142
|
]
|
|
@@ -165,14 +161,14 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
165
161
|
try {
|
|
166
162
|
if (this.logFn) console.log('\nfn:. setupSocketServer');
|
|
167
163
|
|
|
168
|
-
newSocketServer.on(
|
|
164
|
+
newSocketServer.on(DynamoNTS_SocketEventKey.connection, async (socket: SocketIO.Socket) => {
|
|
169
165
|
try {
|
|
170
166
|
let issuer: string;
|
|
171
167
|
|
|
172
168
|
await this.connectEvent.executeEventTasks(socket);
|
|
173
169
|
|
|
174
170
|
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
175
|
-
socket.on(
|
|
171
|
+
socket.on(DynamoNTS_SocketEventKey.subscribe, async (content: any) => {
|
|
176
172
|
try {
|
|
177
173
|
/**
|
|
178
174
|
* usually socket logs are in event.executeEventTasks(),
|
|
@@ -180,9 +176,9 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
180
176
|
* to be able to check content before getPresenceFromSubscrioptionEventContent
|
|
181
177
|
*/
|
|
182
178
|
if (dynamoNTS_globalSettings.logMainSocketEvents || dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
|
|
183
|
-
Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${
|
|
179
|
+
Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe};\ncontent:`, content);
|
|
184
180
|
} else {
|
|
185
|
-
Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${
|
|
181
|
+
Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe}`);
|
|
186
182
|
}
|
|
187
183
|
|
|
188
184
|
const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
@@ -191,26 +187,26 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
191
187
|
this.addSocketToPresence(presence);
|
|
192
188
|
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
193
189
|
|
|
194
|
-
socket.emit(
|
|
190
|
+
socket.emit(DynamoNTS_SocketEventKey.subscriptionSuccessful, 'subscribe was successful', error => {
|
|
195
191
|
Dynamo_Log.error(`Emitting subscriptionSuccessful event failed!\nerror:`, error);
|
|
196
192
|
});
|
|
197
193
|
|
|
198
194
|
Dynamo_Log.success(`<===> socket subscription successfull (${issuer})`);
|
|
199
195
|
} catch (error) {
|
|
200
196
|
Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
201
|
-
socket.emit(
|
|
197
|
+
socket.emit(DynamoNTS_SocketEventKey.error, error);
|
|
202
198
|
socket.disconnect();
|
|
203
199
|
}
|
|
204
200
|
})
|
|
205
201
|
}
|
|
206
202
|
|
|
207
203
|
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
208
|
-
socket.on(event.
|
|
204
|
+
socket.on(event.eventKey, async (content: any) => {
|
|
209
205
|
try {
|
|
210
206
|
await event.executeEventTasks(content, issuer);
|
|
211
207
|
} catch (error) {
|
|
212
208
|
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
213
|
-
socket.emit(
|
|
209
|
+
socket.emit(DynamoNTS_SocketEventKey.error, error);
|
|
214
210
|
}
|
|
215
211
|
});
|
|
216
212
|
});
|
|
@@ -220,7 +216,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
220
216
|
}
|
|
221
217
|
} catch (error) {
|
|
222
218
|
Dynamo_Log.error(`Socket Connection failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
223
|
-
socket.emit(
|
|
219
|
+
socket.emit(DynamoNTS_SocketEventKey.error, error);
|
|
224
220
|
socket.disconnect();
|
|
225
221
|
}
|
|
226
222
|
});
|
|
@@ -262,7 +258,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
262
258
|
}
|
|
263
259
|
}
|
|
264
260
|
|
|
265
|
-
private async
|
|
261
|
+
private async removeSubscription(socket: SocketIO.Socket, issuer?: string): Promise<void> {
|
|
266
262
|
try {
|
|
267
263
|
const activePresenceIndex: number = this.presences.findIndex((pres: DynamoNTS_SocketPresence) => pres.sockets.includes(socket));
|
|
268
264
|
|
|
@@ -314,6 +310,8 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
314
310
|
if (activePresence.sockets.length === 0) {
|
|
315
311
|
this.presences.splice(activePresenceIndex);
|
|
316
312
|
}
|
|
313
|
+
|
|
314
|
+
socket.disconnect();
|
|
317
315
|
} catch (error) {
|
|
318
316
|
throw new Dynamo_Error({
|
|
319
317
|
...this._getDefaultErrorSettings(
|
|
@@ -365,7 +363,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
365
363
|
|
|
366
364
|
emitError(presenceIssuerId: string, error: any): void {
|
|
367
365
|
try {
|
|
368
|
-
this.sendEventForId(presenceIssuerId,
|
|
366
|
+
this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventKey.error, error);
|
|
369
367
|
} catch (error) {
|
|
370
368
|
throw new Dynamo_Error({
|
|
371
369
|
...this._getDefaultErrorSettings(
|
|
@@ -404,10 +402,30 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
404
402
|
});
|
|
405
403
|
}
|
|
406
404
|
} catch (error) {
|
|
405
|
+
|
|
406
|
+
try {
|
|
407
|
+
if (error.flag.includes('DYNAMO') && error?.accitionalInfo?.inactiveSockets) {
|
|
408
|
+
const sockets: SocketIO.Socket[] = error.accitionalInfo.inactiveSockets;
|
|
409
|
+
|
|
410
|
+
await Dynamo_Array.asyncForEach(sockets, async (socket: SocketIO.Socket) => {
|
|
411
|
+
await this.removeSubscription(socket);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
} catch (error) {
|
|
415
|
+
throw new Dynamo_Error({
|
|
416
|
+
...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
|
|
417
|
+
|
|
418
|
+
errorCode: 'NTS-SSS-310',
|
|
419
|
+
message:
|
|
420
|
+
`Error handling of inactive sockets failed!` +
|
|
421
|
+
`\n(Socket Event Emit for id (${id}, ${event}) failed: ${this.params?.name} (${this.params?.port}))`,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
407
425
|
throw new Dynamo_Error({
|
|
408
426
|
...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
|
|
409
427
|
|
|
410
|
-
errorCode: 'NTS-SSS-
|
|
428
|
+
errorCode: 'NTS-SSS-310',
|
|
411
429
|
message: `Socket Event Emit for id (${id}, ${event}) failed: ${this.params?.name} (${this.params?.port})`,
|
|
412
430
|
});
|
|
413
431
|
}
|