@futdevpro/nts-dynamo 1.6.35 → 1.6.37
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.d.ts.map +1 -1
- package/lib/_constants/global-settings.const.js +3 -2
- package/lib/_constants/global-settings.const.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js +13 -7
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/interfaces/global-settings.interface.d.ts +5 -1
- package/lib/_models/interfaces/global-settings.interface.d.ts.map +1 -1
- package/lib/_services/core/api.service.d.ts.map +1 -1
- package/lib/_services/core/api.service.js +19 -3
- package/lib/_services/core/api.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 +68 -32
- 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 +4 -2
- package/src/_models/control-models/socket-event.control-model.ts +14 -7
- package/src/_models/interfaces/global-settings.interface.ts +6 -1
- package/src/_services/core/api.service.ts +19 -3
- package/src/_services/socket/socket-server.service.ts +73 -34
|
@@ -15,6 +15,8 @@ export const dynamoNTS_globalSettings: DynamoNTS_GlobalSettings = {
|
|
|
15
15
|
logResponseContent: false,
|
|
16
16
|
|
|
17
17
|
logMainSocketEvent: true,
|
|
18
|
-
logAllSocketEvent:
|
|
19
|
-
|
|
18
|
+
logAllSocketEvent: true,
|
|
19
|
+
logSocketEventContent: true,
|
|
20
|
+
|
|
21
|
+
logDetailedApiEvents: true,
|
|
20
22
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
2
|
+
import { Dynamo_Array, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
3
3
|
import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
4
4
|
import { DynamoNTS_SocketEventType } from '../../_enums/http/socket-event-type.enum';
|
|
5
5
|
|
|
@@ -37,7 +37,7 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
37
37
|
} else {
|
|
38
38
|
this.logEvent = dynamoNTS_globalSettings.logAllSocketEvent;
|
|
39
39
|
}
|
|
40
|
-
this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.
|
|
40
|
+
this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.logSocketEventContent;
|
|
41
41
|
|
|
42
42
|
if (this.logEvent) {
|
|
43
43
|
this.preProcessess.unshift(this.getPreLog());
|
|
@@ -63,6 +63,7 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
63
63
|
console.log(`\n==> incoming ${this.socketName} socket event: ${this.eventType}...`);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
|
|
66
67
|
return content;
|
|
67
68
|
} catch (error) {
|
|
68
69
|
console.error(`PreLog failed... (socket: ${this.socketName})`, error);
|
|
@@ -75,14 +76,20 @@ export class DynamoNTS_SocketEvent<T>{
|
|
|
75
76
|
* @returns
|
|
76
77
|
*/
|
|
77
78
|
async executeEventTasks?(content?: T, issuer?: string): Promise<void> {
|
|
78
|
-
try {
|
|
79
|
-
|
|
79
|
+
try {
|
|
80
|
+
await Dynamo_Array.asyncForEach(this.preProcessess, async (preProcess: DynamoNTS_SocketEventPreprocessTask<any, any>) => {
|
|
81
|
+
content = await preProcess(content);
|
|
82
|
+
});
|
|
83
|
+
/* for (let i = 0; i < this.preProcessess.length; i++) {
|
|
80
84
|
content = await this.preProcessess[i](content);
|
|
81
|
-
}
|
|
85
|
+
} */
|
|
82
86
|
|
|
83
|
-
|
|
87
|
+
await Dynamo_Array.asyncForEach(this.tasks, async (task: DynamoNTS_SocketEventTask<T>) => {
|
|
88
|
+
await task(content, issuer);
|
|
89
|
+
});
|
|
90
|
+
/* for (let i = 0; i < this.tasks.length; i++) {
|
|
84
91
|
await this.tasks[i](content, issuer);
|
|
85
|
-
}
|
|
92
|
+
} */
|
|
86
93
|
} catch (error) {
|
|
87
94
|
console.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.eventType})`, error, 'content:', content);
|
|
88
95
|
}
|
|
@@ -53,5 +53,10 @@ export interface DynamoNTS_GlobalSettings {
|
|
|
53
53
|
/**
|
|
54
54
|
* this is an application wide default setting for socket debug logs
|
|
55
55
|
*/
|
|
56
|
-
|
|
56
|
+
logSocketEventContent?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* this is an application wide default setting for api debug logs
|
|
60
|
+
*/
|
|
61
|
+
logDetailedApiEvents?: boolean;
|
|
57
62
|
}
|
|
@@ -5,6 +5,7 @@ import { Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
|
5
5
|
import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
|
|
6
6
|
import { DynamoNTS_HttpResponseType } from '../../_enums/http/http-response-type.enum';
|
|
7
7
|
import { DynamoNTS_ApiCallParams } from '../../_models/control-models/api-call-params.control-model';
|
|
8
|
+
import { dynamoNTS_globalSettings } from '../../_constants';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* This predefined Api service contains the basic API call function which can be used in various ways
|
|
@@ -111,7 +112,12 @@ export class DynamoNTS_ApiService {
|
|
|
111
112
|
} else {
|
|
112
113
|
a = res.data;
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
+
|
|
116
|
+
if (dynamoNTS_globalSettings.logDetailedApiEvents) {
|
|
117
|
+
Dynamo_Log.success(`${callParams.name} was successful`, res.data);
|
|
118
|
+
} else {
|
|
119
|
+
Dynamo_Log.success(`${callParams.name} was successful`);
|
|
120
|
+
}
|
|
115
121
|
});
|
|
116
122
|
break;
|
|
117
123
|
case DynamoNTS_HttpCallType.delete:
|
|
@@ -122,7 +128,12 @@ export class DynamoNTS_ApiService {
|
|
|
122
128
|
if (callParams.getFullResponse) {
|
|
123
129
|
a = res;
|
|
124
130
|
}
|
|
125
|
-
|
|
131
|
+
|
|
132
|
+
if (dynamoNTS_globalSettings.logDetailedApiEvents) {
|
|
133
|
+
Dynamo_Log.success(`${callParams.name} was successful`, res.data);
|
|
134
|
+
} else {
|
|
135
|
+
Dynamo_Log.success(`${callParams.name} was successful`);
|
|
136
|
+
}
|
|
126
137
|
});
|
|
127
138
|
break;
|
|
128
139
|
case DynamoNTS_HttpCallType.post:
|
|
@@ -140,7 +151,12 @@ export class DynamoNTS_ApiService {
|
|
|
140
151
|
} else {
|
|
141
152
|
a = res.data;
|
|
142
153
|
}
|
|
143
|
-
|
|
154
|
+
|
|
155
|
+
if (dynamoNTS_globalSettings.logDetailedApiEvents) {
|
|
156
|
+
Dynamo_Log.success(`${callParams.name} api call was successful`, res.data);
|
|
157
|
+
} else {
|
|
158
|
+
Dynamo_Log.success(`${callParams.name} api call was successful`);
|
|
159
|
+
}
|
|
144
160
|
});
|
|
145
161
|
break;
|
|
146
162
|
default:
|
|
@@ -145,6 +145,8 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
this.subscriptionEvent.socketName = this.params.name;
|
|
148
|
+
} else {
|
|
149
|
+
Dynamo_Log.error('getPresenceFromSubscrioptionEventContent is not set', `${this.params.name} (${this.params.port})`);
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
@@ -166,44 +168,79 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
166
168
|
} */
|
|
167
169
|
/* (security === DynamoNTS_SocketSecurity.open ? this.openSocketServer : this.secureSocketServer) */
|
|
168
170
|
newSocketServer.on(DynamoNTS_SocketEventType.connection, async (socket: SocketIO.Socket) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
try {
|
|
172
|
+
let issuer: string;
|
|
173
|
+
if (dynamoNTS_globalSettings.logMainSocketEvent) {
|
|
174
|
+
console.log(`Socket (${this.params.name}): new incoming CONNECTION...`);
|
|
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
|
+
} */
|
|
178
185
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
183
|
-
issuer = presence.issuerId;
|
|
184
|
-
|
|
185
|
-
this.socketSubscription(presence);
|
|
186
|
-
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
187
|
-
|
|
188
|
-
console.log(`socket subscription successfull (${issuer})`);
|
|
189
|
-
} catch (error) {
|
|
190
|
-
Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
191
|
-
socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
192
|
-
socket.disconnect();
|
|
186
|
+
await Dynamo_Array.asyncForEach(this.connectEvent.tasks,
|
|
187
|
+
async (task: (content: SocketIO.Socket) => Promise<void>) => {
|
|
188
|
+
await task(socket);
|
|
193
189
|
}
|
|
194
|
-
|
|
195
|
-
|
|
190
|
+
);
|
|
191
|
+
/* for (let i = 0; i < this.connectEvent.tasks.length; i++) {
|
|
192
|
+
await this.connectEvent.tasks[i](socket);
|
|
193
|
+
} */
|
|
194
|
+
|
|
195
|
+
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
196
|
+
socket.on(DynamoNTS_SocketEventType.subscribe, async (content: any) => {
|
|
197
|
+
try {
|
|
198
|
+
if (dynamoNTS_globalSettings.logMainSocketEvent || dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
|
|
199
|
+
console.log(`---> incoming socket event: ${DynamoNTS_SocketEventType.subscribe} (${this.params.name}, presenceId: ${issuer})`, content);
|
|
200
|
+
} else {
|
|
201
|
+
console.log(`---> incoming socket event: ${DynamoNTS_SocketEventType.subscribe} (${this.params.name}, presenceId: ${issuer})`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
205
|
+
issuer = presence.issuerId;
|
|
206
|
+
|
|
207
|
+
this.socketSubscription(presence);
|
|
208
|
+
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
209
|
+
|
|
210
|
+
Dynamo_Log.success(` <=> socket subscription successfull (${issuer})`);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
213
|
+
socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
214
|
+
socket.disconnect();
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
}
|
|
196
218
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
219
|
+
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
220
|
+
socket.on(event.eventType, async (content: any) => {
|
|
221
|
+
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
|
+
await event.executeEventTasks(content, issuer);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
231
|
+
socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
205
234
|
});
|
|
206
|
-
|
|
235
|
+
|
|
236
|
+
if (dynamoNTS_globalSettings.logMainSocketEvent) {
|
|
237
|
+
console.log(`Socket (${this.params.name}): new CONNECTION established`);
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
Dynamo_Log.error(`Socket Connection failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
241
|
+
socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
242
|
+
socket.disconnect();
|
|
243
|
+
}
|
|
207
244
|
});
|
|
208
245
|
|
|
209
246
|
newSocketServer.listen(this.params.port);
|
|
@@ -283,6 +320,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
283
320
|
|
|
284
321
|
emitEvent(event: string, content: any): void {
|
|
285
322
|
try {
|
|
323
|
+
console.log(` <--- emitting socket event: ${event} (${this.params.name})`);
|
|
286
324
|
this.openSocketServer.emit(event, content);
|
|
287
325
|
} catch (error) {
|
|
288
326
|
Dynamo_Log.error(`Socket Event Emit (${event}) failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
@@ -312,6 +350,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
312
350
|
try {
|
|
313
351
|
const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
|
|
314
352
|
if (presence) {
|
|
353
|
+
console.log(` <--- emitting socket event for presence: ${event} (${this.params.name}, presenceId: ${id})`);
|
|
315
354
|
presence.emitEvent(event, content);
|
|
316
355
|
} else {
|
|
317
356
|
if (error) {
|