@futdevpro/nts-dynamo 1.6.36 → 1.6.38
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/global-settings.const.js +1 -1
- package/lib/_constants/global-settings.const.js.map +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-client.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-client.mock.js +1 -0
- package/lib/_constants/mocks/socket-client.mock.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.d.ts +32 -3
- package/lib/_models/control-models/socket-event.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js +26 -24
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/interfaces/global-settings.interface.d.ts +1 -1
- package/lib/_models/interfaces/global-settings.interface.d.ts.map +1 -1
- package/lib/_services/socket/socket-client.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-client.service.js +6 -3
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +16 -41
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/_constants/global-settings.const.ts +1 -1
- package/src/_constants/mocks/app-server.mock.ts +0 -1
- package/src/_constants/mocks/socket-client.mock.ts +1 -0
- package/src/_models/control-models/socket-event.control-model.ts +59 -29
- package/src/_models/interfaces/global-settings.interface.ts +1 -1
- package/src/_services/socket/socket-client.service.ts +6 -3
- package/src/_services/socket/socket-server.service.ts +18 -47
|
@@ -13,7 +13,6 @@ import { DynamoNTS_RoutingModule } from '../../_services/route/routing-module.se
|
|
|
13
13
|
import { DynamoNTS_App } from '../../_services/server/app.server';
|
|
14
14
|
import { DynamoNTS_Controller_Mock } from './controller.mock';
|
|
15
15
|
import { AuthService_Mock } from './auth-service.mock';
|
|
16
|
-
import { dynamoNTS_globalSettings } from '../global-settings.const';
|
|
17
16
|
import { dependency_mock_DataParams, dependent_mock_DataParams } from './data-model.mock';
|
|
18
17
|
import { getCustomDataRoutingModule } from '../../_modules/custom-data';
|
|
19
18
|
|
|
@@ -17,6 +17,7 @@ export class SocketClient_Mock extends DynamoNTS_SocketClientService {
|
|
|
17
17
|
getIncomingEvents(): DynamoNTS_SocketEvent<any>[] {
|
|
18
18
|
return [
|
|
19
19
|
new DynamoNTS_SocketEvent({
|
|
20
|
+
name: 'connect',
|
|
20
21
|
eventType: DynamoNTS_SocketEventType.connect,
|
|
21
22
|
tasks: [
|
|
22
23
|
async (content: any, issuer: string) => {
|
|
@@ -21,10 +21,39 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
21
21
|
logEventContent?: boolean;
|
|
22
22
|
|
|
23
23
|
constructor(
|
|
24
|
-
set:
|
|
24
|
+
set: {
|
|
25
|
+
/**
|
|
26
|
+
* naming the socket will help to follow events on service
|
|
27
|
+
*/
|
|
28
|
+
name: string,
|
|
29
|
+
/**
|
|
30
|
+
* define socket event type such as;
|
|
31
|
+
* connection, connect, disconnect, message, error, or anything else
|
|
32
|
+
*/
|
|
33
|
+
eventType: DynamoNTS_SocketEventType | string,
|
|
34
|
+
/**
|
|
35
|
+
* preprocesses are the functions the service needs to run before the actual function,
|
|
36
|
+
* these can be used for authentications, or translating data
|
|
37
|
+
*
|
|
38
|
+
* the last function in the array should return the content in the type(T) of the socket<T>
|
|
39
|
+
*/
|
|
40
|
+
preProcessess?: DynamoNTS_SocketEventPreprocessTask<any, any>[],
|
|
41
|
+
/**
|
|
42
|
+
* tasks are the functions the service needs to run
|
|
43
|
+
*/
|
|
44
|
+
tasks?: DynamoNTS_SocketEventTask<T>[],
|
|
45
|
+
/**
|
|
46
|
+
* logEvent will create a log for the event triggered
|
|
47
|
+
*/
|
|
48
|
+
logEvent?: boolean,
|
|
49
|
+
/**
|
|
50
|
+
* logEventContent will create a log for the event triggered with the content
|
|
51
|
+
*/
|
|
52
|
+
logEventContent?: boolean,
|
|
53
|
+
}
|
|
25
54
|
) {
|
|
26
55
|
try {
|
|
27
|
-
this.socketName = set.
|
|
56
|
+
this.socketName = set.name;
|
|
28
57
|
this.eventType = set.eventType;
|
|
29
58
|
|
|
30
59
|
this.preProcessess = set.preProcessess ?? [];
|
|
@@ -32,16 +61,25 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
32
61
|
|
|
33
62
|
if (set.logEvent !== undefined) {
|
|
34
63
|
this.logEvent = set.logEvent;
|
|
35
|
-
} else if (
|
|
36
|
-
this.logEvent =
|
|
64
|
+
} else if (this.eventType === DynamoNTS_SocketEventType.subscribe) {
|
|
65
|
+
this.logEvent = false;
|
|
66
|
+
} else if (
|
|
67
|
+
([
|
|
68
|
+
DynamoNTS_SocketEventType.connection,
|
|
69
|
+
DynamoNTS_SocketEventType.connect,
|
|
70
|
+
/* DynamoNTS_SocketEventType.subscribe, */
|
|
71
|
+
DynamoNTS_SocketEventType.disconnect,
|
|
72
|
+
] as string[]).includes(this.eventType)
|
|
73
|
+
) {
|
|
74
|
+
this.logEvent = dynamoNTS_globalSettings.logMainSocketEvents || dynamoNTS_globalSettings.logAllSocketEvent;
|
|
37
75
|
} else {
|
|
38
76
|
this.logEvent = dynamoNTS_globalSettings.logAllSocketEvent;
|
|
39
77
|
}
|
|
40
78
|
this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.logSocketEventContent;
|
|
41
79
|
|
|
42
|
-
if (this.logEvent) {
|
|
80
|
+
/* if (this.logEvent) {
|
|
43
81
|
this.preProcessess.unshift(this.getPreLog());
|
|
44
|
-
}
|
|
82
|
+
} */
|
|
45
83
|
} catch (error) {
|
|
46
84
|
Dynamo_Log.error(
|
|
47
85
|
`\nSocket Event params setup failed (${this.socketName}): ${set.eventType}`, error);
|
|
@@ -53,45 +91,37 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
53
91
|
*
|
|
54
92
|
* @returns
|
|
55
93
|
*/
|
|
56
|
-
getPreLog
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} else {
|
|
63
|
-
console.log(`\n==> incoming ${this.socketName} socket event: ${this.eventType}...`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return content;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error(`PreLog failed... (socket: ${this.socketName})`, error);
|
|
94
|
+
private async getPreLog(content: T, issuer?: string): Promise<void> {
|
|
95
|
+
try {
|
|
96
|
+
if (this.logEventContent && this.eventType !== DynamoNTS_SocketEventType.connection) {
|
|
97
|
+
Dynamo_Log.log(`--> incoming socket(${this.socketName}) event: ${this.eventType}; content:`, content);
|
|
98
|
+
} else {
|
|
99
|
+
Dynamo_Log.log(`--> incoming socket(${this.socketName}) event: ${this.eventType}...`);
|
|
70
100
|
}
|
|
71
|
-
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
Dynamo_Log.error(`PreLog failed... (socket: ${this.socketName})`, error);
|
|
103
|
+
}
|
|
72
104
|
}
|
|
73
105
|
|
|
74
106
|
/**
|
|
75
107
|
*
|
|
76
108
|
* @returns
|
|
77
109
|
*/
|
|
78
|
-
async executeEventTasks
|
|
110
|
+
async executeEventTasks(content?: T, issuer?: string): Promise<void> {
|
|
79
111
|
try {
|
|
112
|
+
if (this.logEvent || this.logEventContent) {
|
|
113
|
+
await this.getPreLog(content, issuer);
|
|
114
|
+
}
|
|
115
|
+
|
|
80
116
|
await Dynamo_Array.asyncForEach(this.preProcessess, async (preProcess: DynamoNTS_SocketEventPreprocessTask<any, any>) => {
|
|
81
117
|
content = await preProcess(content);
|
|
82
118
|
});
|
|
83
|
-
/* for (let i = 0; i < this.preProcessess.length; i++) {
|
|
84
|
-
content = await this.preProcessess[i](content);
|
|
85
|
-
} */
|
|
86
119
|
|
|
87
120
|
await Dynamo_Array.asyncForEach(this.tasks, async (task: DynamoNTS_SocketEventTask<T>) => {
|
|
88
121
|
await task(content, issuer);
|
|
89
122
|
});
|
|
90
|
-
/* for (let i = 0; i < this.tasks.length; i++) {
|
|
91
|
-
await this.tasks[i](content, issuer);
|
|
92
|
-
} */
|
|
93
123
|
} catch (error) {
|
|
94
|
-
|
|
124
|
+
Dynamo_Log.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.eventType})`, error, 'content:', content);
|
|
95
125
|
}
|
|
96
126
|
}
|
|
97
127
|
}
|
|
@@ -45,7 +45,7 @@ export interface DynamoNTS_GlobalSettings {
|
|
|
45
45
|
/**
|
|
46
46
|
* this is an application wide default setting for socket debug logs
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
logMainSocketEvents?: boolean;
|
|
49
49
|
/**
|
|
50
50
|
* this is an application wide default setting for socket debug logs
|
|
51
51
|
*/
|
|
@@ -29,6 +29,7 @@ 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',
|
|
32
33
|
eventType: DynamoNTS_SocketEventType.connect,
|
|
33
34
|
tasks: [
|
|
34
35
|
async () => {
|
|
@@ -38,6 +39,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
38
39
|
]
|
|
39
40
|
}),
|
|
40
41
|
new DynamoNTS_SocketEvent<any>({
|
|
42
|
+
name: 'disconnect',
|
|
41
43
|
eventType: DynamoNTS_SocketEventType.disconnect,
|
|
42
44
|
tasks: [
|
|
43
45
|
async () => {
|
|
@@ -52,6 +54,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
52
54
|
]
|
|
53
55
|
}),
|
|
54
56
|
new DynamoNTS_SocketEvent<any>({
|
|
57
|
+
name: 'error',
|
|
55
58
|
eventType: DynamoNTS_SocketEventType.error,
|
|
56
59
|
tasks: [
|
|
57
60
|
async (content: any) => {
|
|
@@ -79,7 +82,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
79
82
|
|
|
80
83
|
await this.setupSocketEvents();
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
Dynamo_Log.log(`\n${this.params?.name} Socket Client Service setup finished`);
|
|
83
86
|
|
|
84
87
|
await this.connectSocket();
|
|
85
88
|
} catch (error) {
|
|
@@ -133,7 +136,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
133
136
|
|
|
134
137
|
private async connectSocket(): Promise<void> {
|
|
135
138
|
try {
|
|
136
|
-
|
|
139
|
+
Dynamo_Log.log(`${this.params.name} Socket Client connecting to ${this.params.address}:${this.params.port} ...`);
|
|
137
140
|
|
|
138
141
|
this.socket.connect();
|
|
139
142
|
|
|
@@ -167,7 +170,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
167
170
|
*/
|
|
168
171
|
protected async emitEvent(eventType: string, content: any): Promise<void> {
|
|
169
172
|
try {
|
|
170
|
-
|
|
173
|
+
Dynamo_Log.log(`\n<-- outgoing ${this.name} socket event: ${eventType}`);
|
|
171
174
|
this.socket.emit(eventType, content);
|
|
172
175
|
} catch (error) {
|
|
173
176
|
Dynamo_Log.error(`Socket Client Service Emit Event failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
@@ -93,8 +93,8 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
93
93
|
this.connectEvent = this.incomingEvents.splice(connectEventIndex)[0];
|
|
94
94
|
} else {
|
|
95
95
|
this.connectEvent = new DynamoNTS_SocketEvent({
|
|
96
|
+
name: 'connect',
|
|
96
97
|
eventType: DynamoNTS_SocketEventType.connection,
|
|
97
|
-
tasks: []
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
100
|
this.connectEvent.socketName = this.params.name;
|
|
@@ -110,6 +110,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
110
110
|
);
|
|
111
111
|
} else {
|
|
112
112
|
this.subscriptionEvent = new DynamoNTS_SocketEvent<T_SubscriptionContent>({
|
|
113
|
+
name: 'subscribe',
|
|
113
114
|
eventType: DynamoNTS_SocketEventType.subscribe
|
|
114
115
|
});
|
|
115
116
|
}
|
|
@@ -126,6 +127,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
126
127
|
} else {
|
|
127
128
|
this.incomingEvents.push(
|
|
128
129
|
new DynamoNTS_SocketEvent({
|
|
130
|
+
name: 'disconnect',
|
|
129
131
|
eventType: DynamoNTS_SocketEventType.disconnect,
|
|
130
132
|
tasks: [
|
|
131
133
|
this.removeSubscriptionOnDisconnect
|
|
@@ -137,6 +139,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
137
139
|
const errorEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventType === DynamoNTS_SocketEventType.error);
|
|
138
140
|
if (errorEventIndex == -1 && this.errorHandling) {
|
|
139
141
|
this.incomingEvents.push(new DynamoNTS_SocketEvent<T_ErrorContent>({
|
|
142
|
+
name: 'error',
|
|
140
143
|
eventType: DynamoNTS_SocketEventType.error,
|
|
141
144
|
tasks: [
|
|
142
145
|
this.errorHandling
|
|
@@ -161,44 +164,25 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
161
164
|
async setupSocketServer(newSocketServer: SocketIO.Server, security: DynamoNTS_SocketSecurity.open | DynamoNTS_SocketSecurity.secure, successCallback: () => void): Promise<SocketIO.Server> {
|
|
162
165
|
try {
|
|
163
166
|
if (this.logFn) console.log('\nfn:. setupSocketServer');
|
|
164
|
-
|
|
165
|
-
this.openSocketServer = newSocketServer;
|
|
166
|
-
} else {
|
|
167
|
-
this.secureSocketServer = newSocketServer;
|
|
168
|
-
} */
|
|
169
|
-
/* (security === DynamoNTS_SocketSecurity.open ? this.openSocketServer : this.secureSocketServer) */
|
|
167
|
+
|
|
170
168
|
newSocketServer.on(DynamoNTS_SocketEventType.connection, async (socket: SocketIO.Socket) => {
|
|
171
169
|
try {
|
|
172
170
|
let issuer: string;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
await Dynamo_Array.asyncForEach(this.connectEvent.preProcessess,
|
|
178
|
-
async (preProcess: (content: SocketIO.Socket) => Promise<void>) => {
|
|
179
|
-
await preProcess(socket);
|
|
180
|
-
}
|
|
181
|
-
);
|
|
182
|
-
/* for (let i = 0; i < this.connectEvent.preProcessess.length; i++) {
|
|
183
|
-
await this.connectEvent.preProcessess[i](socket);
|
|
184
|
-
} */
|
|
185
|
-
|
|
186
|
-
await Dynamo_Array.asyncForEach(this.connectEvent.tasks,
|
|
187
|
-
async (task: (content: SocketIO.Socket) => Promise<void>) => {
|
|
188
|
-
await task(socket);
|
|
189
|
-
}
|
|
190
|
-
);
|
|
191
|
-
/* for (let i = 0; i < this.connectEvent.tasks.length; i++) {
|
|
192
|
-
await this.connectEvent.tasks[i](socket);
|
|
193
|
-
} */
|
|
171
|
+
|
|
172
|
+
await this.connectEvent.executeEventTasks(socket);
|
|
194
173
|
|
|
195
174
|
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
196
175
|
socket.on(DynamoNTS_SocketEventType.subscribe, async (content: any) => {
|
|
197
176
|
try {
|
|
198
|
-
|
|
199
|
-
|
|
177
|
+
/**
|
|
178
|
+
* usually socket logs are in event.executeEventTasks(),
|
|
179
|
+
* but subscribe event is an exception from this,
|
|
180
|
+
* to be able to check content before getPresenceFromSubscrioptionEventContent
|
|
181
|
+
*/
|
|
182
|
+
if (dynamoNTS_globalSettings.logMainSocketEvents || dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
|
|
183
|
+
Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventType.subscribe}; content:`, content);
|
|
200
184
|
} else {
|
|
201
|
-
|
|
185
|
+
Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventType.subscribe}`);
|
|
202
186
|
}
|
|
203
187
|
|
|
204
188
|
const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
@@ -219,12 +203,6 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
219
203
|
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
220
204
|
socket.on(event.eventType, async (content: any) => {
|
|
221
205
|
try {
|
|
222
|
-
if (dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
|
|
223
|
-
console.log(`---> incoming socket event: ${event.eventType} (${this.params.name}, presenceId: ${issuer})`, content);
|
|
224
|
-
} else {
|
|
225
|
-
console.log(`---> incoming socket event: ${event.eventType} (${this.params.name}, presenceId: ${issuer})`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
206
|
await event.executeEventTasks(content, issuer);
|
|
229
207
|
} catch (error) {
|
|
230
208
|
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
@@ -233,7 +211,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
233
211
|
});
|
|
234
212
|
});
|
|
235
213
|
|
|
236
|
-
if (dynamoNTS_globalSettings.
|
|
214
|
+
if (dynamoNTS_globalSettings.logMainSocketEvents) {
|
|
237
215
|
console.log(`Socket (${this.params.name}): new CONNECTION established`);
|
|
238
216
|
}
|
|
239
217
|
} catch (error) {
|
|
@@ -244,13 +222,6 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
244
222
|
});
|
|
245
223
|
|
|
246
224
|
newSocketServer.listen(this.params.port);
|
|
247
|
-
/* if (security === DynamoNTS_SocketSecurity.open) {
|
|
248
|
-
this.openSocketServer = newSocketServer;
|
|
249
|
-
this.openSocketServer.listen(this.params.port);
|
|
250
|
-
} else {
|
|
251
|
-
this.secureSocketServer = newSocketServer;
|
|
252
|
-
this.secureSocketServer.listen(this.params.port);
|
|
253
|
-
} */
|
|
254
225
|
|
|
255
226
|
Dynamo_Log.success(
|
|
256
227
|
`\nsocket server setup finished: ${this.params.name}` +
|
|
@@ -320,7 +291,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
320
291
|
|
|
321
292
|
emitEvent(event: string, content: any): void {
|
|
322
293
|
try {
|
|
323
|
-
|
|
294
|
+
Dynamo_Log.log(` <--- emitting socket event: ${event} (${this.params.name})`);
|
|
324
295
|
this.openSocketServer.emit(event, content);
|
|
325
296
|
} catch (error) {
|
|
326
297
|
Dynamo_Log.error(`Socket Event Emit (${event}) failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
@@ -350,7 +321,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
350
321
|
try {
|
|
351
322
|
const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
|
|
352
323
|
if (presence) {
|
|
353
|
-
|
|
324
|
+
Dynamo_Log.log(` <--- emitting socket event for presence: ${event} (${this.params.name}, presenceId: ${id})`);
|
|
354
325
|
presence.emitEvent(event, content);
|
|
355
326
|
} else {
|
|
356
327
|
if (error) {
|