@futdevpro/nts-dynamo 1.6.52 → 1.6.54
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/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +39 -45
- package/lib/_models/control-models/endpoint-params.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 +20 -13
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +2 -9
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts +4 -0
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +4 -0
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +5 -0
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +3 -2
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/socket/socket-client.service.d.ts +1 -1
- package/lib/_services/socket/socket-client.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-client.service.js +20 -25
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +0 -1
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +19 -12
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +18 -25
- package/src/_models/control-models/socket-presence.control-model.ts +17 -13
- package/src/_services/base/db.service.ts +2 -9
- package/src/_services/core/global.service.ts +9 -0
- package/src/_services/server/app.server.ts +9 -0
- package/src/_services/socket/socket-client.service.ts +19 -20
- package/src/_services/socket/socket-server.service.ts +3 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
4
|
|
|
5
5
|
import { Dynamo_Array, Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
6
6
|
import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
@@ -117,23 +117,16 @@ export class DynamoNTS_EndpointParams{
|
|
|
117
117
|
*
|
|
118
118
|
* @returns
|
|
119
119
|
*/
|
|
120
|
-
private async preLog(req: Request, res: Response): Promise<void> {
|
|
120
|
+
private async preLog(req: Request, res: Response, issuer: string): Promise<void> {
|
|
121
121
|
try {
|
|
122
122
|
if (this.logRequest) {
|
|
123
123
|
if (this.logRequestsContent) {
|
|
124
124
|
const params = this.getPathParamsLogContent(req);
|
|
125
|
-
/* let params = '';
|
|
126
|
-
for(let i = 0; i < this.pathParams.length; i++) {
|
|
127
|
-
params += `\n ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
|
|
128
|
-
if (i + 1 < this.pathParams.length) {
|
|
129
|
-
params += ',';
|
|
130
|
-
}
|
|
131
|
-
} */
|
|
132
125
|
|
|
133
126
|
if (req.body && 0 < Object.keys(req.body).length) {
|
|
134
|
-
console.log(`===> incoming ${this.name} request
|
|
127
|
+
console.log(`===> incoming ${this.name} request... (issuer: ${issuer})\npathParams:${params}\nbody:`, req.body);
|
|
135
128
|
} else {
|
|
136
|
-
console.log(`===> incoming ${this.name} request
|
|
129
|
+
console.log(`===> incoming ${this.name} request... (issuer: ${issuer})\npathParams:${params}`);
|
|
137
130
|
}
|
|
138
131
|
} else {
|
|
139
132
|
console.log(`===> incoming ${this.name} request...`);
|
|
@@ -141,7 +134,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
141
134
|
}
|
|
142
135
|
|
|
143
136
|
} catch (error) {
|
|
144
|
-
this.error(req, res, error);
|
|
137
|
+
this.error(req, res, error, issuer);
|
|
145
138
|
}
|
|
146
139
|
}
|
|
147
140
|
|
|
@@ -150,10 +143,14 @@ export class DynamoNTS_EndpointParams{
|
|
|
150
143
|
* @returns
|
|
151
144
|
*/
|
|
152
145
|
getFullExecution(): (req: Request, res: Response) => Promise<void> {
|
|
146
|
+
let issuer: string;
|
|
147
|
+
|
|
153
148
|
return async (req: Request, res: Response) => {
|
|
154
149
|
try {
|
|
150
|
+
issuer = DynamoNTS_GlobalService?.getAuthService()?.getIssuerFromRequest(req);
|
|
151
|
+
|
|
155
152
|
if (this.logRequest) {
|
|
156
|
-
await this.preLog(req, res);
|
|
153
|
+
await this.preLog(req, res, issuer);
|
|
157
154
|
}
|
|
158
155
|
|
|
159
156
|
await Dynamo_Array.asyncForEach(this.preProcessess,
|
|
@@ -161,8 +158,6 @@ export class DynamoNTS_EndpointParams{
|
|
|
161
158
|
await preProcess(req, res);
|
|
162
159
|
}
|
|
163
160
|
);
|
|
164
|
-
|
|
165
|
-
const issuer: string = DynamoNTS_GlobalService?.getAuthService()?.getIssuerFromRequest(req);
|
|
166
161
|
|
|
167
162
|
await Dynamo_Array.asyncForEach(this.tasks,
|
|
168
163
|
async (task: (req: Request, res: Response, issuer?: string) => Promise<void>) => {
|
|
@@ -179,7 +174,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
179
174
|
}
|
|
180
175
|
}
|
|
181
176
|
} catch (error) {
|
|
182
|
-
this.error(req, res, error);
|
|
177
|
+
this.error(req, res, error, issuer);
|
|
183
178
|
}
|
|
184
179
|
};
|
|
185
180
|
}
|
|
@@ -189,12 +184,9 @@ export class DynamoNTS_EndpointParams{
|
|
|
189
184
|
* @param res
|
|
190
185
|
* @param error
|
|
191
186
|
*/
|
|
192
|
-
private error(req: Request, res: Response, error: Error | Dynamo_Error): void {
|
|
187
|
+
private async error(req: Request, res: Response, error: Error | Dynamo_Error, issuer: string): Promise<void> {
|
|
193
188
|
try {
|
|
194
189
|
let msg: string = `Endpoint catched an error. ${this.name} (${this.endpoint})`;
|
|
195
|
-
/* this.pathParams.forEach((param: string) => {
|
|
196
|
-
msg += `\n${param}: ${req.params[param]}`;
|
|
197
|
-
}); */
|
|
198
190
|
msg += this.getPathParamsLogContent(req);
|
|
199
191
|
msg += `\nERROR:`;
|
|
200
192
|
|
|
@@ -206,10 +198,10 @@ export class DynamoNTS_EndpointParams{
|
|
|
206
198
|
'\n'
|
|
207
199
|
);
|
|
208
200
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
201
|
+
await DynamoNTS_GlobalService.globalErrorHandler?.(error, req, res, issuer).catch(err => {
|
|
202
|
+
Dynamo_Log.warn('DynamoNTS_GlobalService.globalErrorHandler failed to handle error: ', err);
|
|
203
|
+
Dynamo_Log.warn('It will proceed as normal.');
|
|
204
|
+
});
|
|
213
205
|
|
|
214
206
|
res.status((error as Dynamo_Error)?.___status ?? 501);
|
|
215
207
|
res.send(error);
|
|
@@ -230,7 +222,8 @@ export class DynamoNTS_EndpointParams{
|
|
|
230
222
|
}
|
|
231
223
|
} catch (error) {
|
|
232
224
|
console.error(
|
|
233
|
-
|
|
225
|
+
`\n\nDYNAMO MULTILEVEL ERROR:DynamoNTS_EndpointParams:error: (${this.name}, ${this.endpoint})` +
|
|
226
|
+
`\n(DYNAMO MULTILEVEL ERROR means, that the ERRORHANDLING is ALSO FAILED, and the error message was not sent.)` +
|
|
234
227
|
`\nERROR:`, error, '\n'
|
|
235
228
|
);
|
|
236
229
|
}
|
|
@@ -47,27 +47,26 @@ export class DynamoNTS_SocketPresence {
|
|
|
47
47
|
* @param content
|
|
48
48
|
*/
|
|
49
49
|
emitEvent?(event: string, content: any) {
|
|
50
|
-
let anyFailed: boolean = false;
|
|
50
|
+
/* let anyFailed: boolean = false; */
|
|
51
51
|
const errors = [];
|
|
52
52
|
const inactiveSockets: SocketIO.Socket[] = [];
|
|
53
53
|
|
|
54
54
|
this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
|
|
55
55
|
if (!socket.connected) {
|
|
56
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed
|
|
57
|
-
anyFailed = true;
|
|
56
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!\nERROR: socket[${socket.id}] is not connected! (it will be removed...)`);
|
|
58
57
|
|
|
59
|
-
errors.push(
|
|
58
|
+
/* errors.push(
|
|
60
59
|
new Dynamo_Error({
|
|
61
60
|
status: 500,
|
|
62
61
|
errorCode: 'NTS-SPC-EE1',
|
|
63
62
|
addECToUserMsg: true,
|
|
64
|
-
message: `Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed
|
|
63
|
+
message: `Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!\nERROR: socket[${socket.id}] is not connected!`,
|
|
65
64
|
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
66
65
|
})
|
|
67
|
-
);
|
|
66
|
+
); */
|
|
68
67
|
|
|
69
68
|
inactiveSockets.push(socket);
|
|
70
|
-
socket
|
|
69
|
+
socket?.disconnect(true);
|
|
71
70
|
}
|
|
72
71
|
});
|
|
73
72
|
|
|
@@ -75,30 +74,35 @@ export class DynamoNTS_SocketPresence {
|
|
|
75
74
|
|
|
76
75
|
this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
|
|
77
76
|
const success: boolean = socket.emit(event, content, error => {
|
|
78
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!
|
|
77
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!(0)\nerror:`, error);
|
|
79
78
|
errors.push(error);
|
|
80
|
-
anyFailed = true;
|
|
81
79
|
});
|
|
82
80
|
|
|
83
81
|
if (!success) {
|
|
84
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!
|
|
85
|
-
anyFailed = true;
|
|
82
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!(1)`);
|
|
86
83
|
}
|
|
87
84
|
});
|
|
88
85
|
|
|
89
|
-
if (
|
|
86
|
+
if (0 < errors.length) {
|
|
90
87
|
throw new Dynamo_Error({
|
|
91
88
|
status: 500,
|
|
92
89
|
errorCode: 'NTS-SPC-EE2',
|
|
93
90
|
addECToUserMsg: true,
|
|
94
91
|
message: `Emitting event '${event}' on socket(s)(${this.serviceName}) failed!`,
|
|
95
92
|
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
96
|
-
/* errors: errors, */
|
|
97
93
|
additionalContent: {
|
|
98
94
|
inactiveSockets: inactiveSockets,
|
|
99
95
|
errors: errors,
|
|
100
96
|
}
|
|
101
97
|
});
|
|
98
|
+
} else if (this.sockets.length === 0) {
|
|
99
|
+
throw new Dynamo_Error({
|
|
100
|
+
status: 404,
|
|
101
|
+
errorCode: 'NTS-SPC-EE3',
|
|
102
|
+
addECToUserMsg: true,
|
|
103
|
+
message: `Emitting event '${event}' on socket(s)(${this.serviceName}) failed! No more sockets left connected!`,
|
|
104
|
+
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
105
|
+
});
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
|
|
@@ -100,14 +100,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
newData._id = `${newData._id}`;
|
|
105
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
106
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.createData)')
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
data._id = newData._id;
|
|
110
|
-
data.__v = newData.__v;
|
|
103
|
+
data = this.stringifyDataId(data, 'createData');
|
|
111
104
|
|
|
112
105
|
return data;
|
|
113
106
|
}
|
|
@@ -830,7 +823,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
830
823
|
data = JSON.parse(JSON.stringify(data));
|
|
831
824
|
|
|
832
825
|
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
833
|
-
Dynamo_Log.error(`data._id stringifying failed! Please notfiy the developers! (${fnName})`, new Error());
|
|
826
|
+
Dynamo_Log.error(`data._id stringifying failed! Please notfiy the DynamoNTS developers! (${fnName})`, new Error());
|
|
834
827
|
}
|
|
835
828
|
}
|
|
836
829
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
|
+
|
|
3
5
|
import { Dynamo_Metadata, Dynamo_DataParams, Dynamo_Log, Dynamo_Error } from '@futdevpro/fsm-dynamo';
|
|
4
6
|
import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
|
|
5
7
|
|
|
@@ -34,6 +36,9 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
34
36
|
authService: DynamoNTS_AuthService;
|
|
35
37
|
dbServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_DBService<any>>; // DynamoNTS_DBServiceCollection;
|
|
36
38
|
emailServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_EmailService>; // DynamoNTS_EmailServiceCollection;
|
|
39
|
+
|
|
40
|
+
private static _globalErrorHandler?: (err: any, req: Request, res: Response, issuer: string) => Promise<void>;
|
|
41
|
+
static get globalErrorHandler(): (err: any, req: Request, res: Response, issuer: string) => Promise<void> { return this._globalErrorHandler; }
|
|
37
42
|
|
|
38
43
|
/**
|
|
39
44
|
* You need to setup global Services through this function
|
|
@@ -73,6 +78,10 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
73
78
|
this._params = params;
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
static setGlobalErrorHandler(handler?: (err: any, req: Request, res: Response, issuer: string) => Promise<void>): void {
|
|
82
|
+
this.instance.globalErrorHandler = handler;
|
|
83
|
+
}
|
|
84
|
+
|
|
76
85
|
/**
|
|
77
86
|
*
|
|
78
87
|
* @returns
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
import Mongoose = require("mongoose");
|
|
3
3
|
import Express = require("express");
|
|
4
|
+
|
|
4
5
|
import * as Http from 'http';
|
|
5
6
|
import * as Https from 'https';
|
|
6
7
|
import * as FileSystem from 'fs';
|
|
7
8
|
import * as BodyParser from 'body-parser';
|
|
8
9
|
|
|
10
|
+
import { Request, Response } from 'express';
|
|
11
|
+
|
|
9
12
|
import { Dynamo_Array, Dynamo_Error, dynamo_error_default, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
|
|
10
13
|
|
|
11
14
|
import { DynamoNTS_SingletonService } from '../base/singleton.service';
|
|
@@ -241,6 +244,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
241
244
|
this.globalService = DynamoNTS_GlobalService.getInstance();
|
|
242
245
|
DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
|
|
243
246
|
DynamoNTS_GlobalService.setParams(this.params);
|
|
247
|
+
DynamoNTS_GlobalService.setGlobalErrorHandler(this.getGlobalErrorHandler?.());
|
|
244
248
|
|
|
245
249
|
if (this.getPortSettings) {
|
|
246
250
|
this._ports = this.getPortSettings();
|
|
@@ -878,4 +882,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
878
882
|
* MISSING Description (TODO)
|
|
879
883
|
*/
|
|
880
884
|
postProcess?(): Promise<void>;
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* MISSING Description (TODO)
|
|
888
|
+
*/
|
|
889
|
+
getGlobalErrorHandler?(): (err: any, req: Request, res: Response, issuer: string) => Promise<void>;
|
|
881
890
|
}
|
|
@@ -24,7 +24,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
24
24
|
protected _connected: boolean = false;
|
|
25
25
|
get connected(): boolean { return this._connected; }
|
|
26
26
|
|
|
27
|
-
protected
|
|
27
|
+
protected debugLog: boolean = dynamoNTS_globalSettings.logSetup;
|
|
28
28
|
protected logFn: boolean;
|
|
29
29
|
|
|
30
30
|
private defaultEvents: DynamoNTS_SocketEvent<any>[] = [
|
|
@@ -33,7 +33,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
33
33
|
tasks: [
|
|
34
34
|
async () => {
|
|
35
35
|
this._connected = true;
|
|
36
|
-
Dynamo_Log.success(
|
|
36
|
+
Dynamo_Log.success(`< > socket-client(${this.params.name}) connected!`);
|
|
37
37
|
}
|
|
38
38
|
]
|
|
39
39
|
}),
|
|
@@ -43,7 +43,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
43
43
|
tasks: [
|
|
44
44
|
async () => {
|
|
45
45
|
this._connected = false;
|
|
46
|
-
Dynamo_Log.warn(
|
|
46
|
+
Dynamo_Log.warn(`< x > socket-client(${this.params.name}) disconnected!`);
|
|
47
47
|
|
|
48
48
|
if (this._params.reconnect) {
|
|
49
49
|
await delay(this._params.reconnectDelay);
|
|
@@ -57,7 +57,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
57
57
|
eventKey: DynamoNTS_SocketEventKey.subscriptionSuccessful,
|
|
58
58
|
tasks: [
|
|
59
59
|
async () => {
|
|
60
|
-
Dynamo_Log.success(
|
|
60
|
+
Dynamo_Log.success(`<-=-> socket-client(${this.params.name}) subscription successful!`);
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
}),
|
|
@@ -66,7 +66,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
66
66
|
eventKey: DynamoNTS_SocketEventKey.error,
|
|
67
67
|
tasks: [
|
|
68
68
|
async (content: any) => {
|
|
69
|
-
Dynamo_Log.error(
|
|
69
|
+
Dynamo_Log.error(`---> socket-client(${this.params.name}) ERROR!:`, content);
|
|
70
70
|
}
|
|
71
71
|
]
|
|
72
72
|
}),
|
|
@@ -76,7 +76,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
76
76
|
super();
|
|
77
77
|
|
|
78
78
|
this.asyncConstructor().catch((error: any) => {
|
|
79
|
-
Dynamo_Log.error(
|
|
79
|
+
Dynamo_Log.error(`socket-client(${this.params?.name}) Service setup failed! ERROR:`, error);
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -90,11 +90,11 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
90
90
|
|
|
91
91
|
await this.setupSocketEvents();
|
|
92
92
|
|
|
93
|
-
Dynamo_Log.
|
|
93
|
+
Dynamo_Log.success(`\nsocket-client(${this.params?.name}) Service setup finished`);
|
|
94
94
|
|
|
95
95
|
await this.connectSocket();
|
|
96
96
|
} catch (error) {
|
|
97
|
-
Dynamo_Log.error(
|
|
97
|
+
Dynamo_Log.error(`socket-client(${this.params?.name}) Service setup failed!`, error);
|
|
98
98
|
throw new Dynamo_Error({
|
|
99
99
|
errorCode: 'NTS-SCS-001',
|
|
100
100
|
error: error,
|
|
@@ -107,6 +107,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
107
107
|
if (this.logFn) console.log('\nFn:. setupDefaultEvents');
|
|
108
108
|
|
|
109
109
|
this.defaultEvents.forEach((defaultEvent: DynamoNTS_SocketEvent<any>) => {
|
|
110
|
+
defaultEvent.serviceName = this.params.name;
|
|
110
111
|
const eventDeclared = this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.eventKey === defaultEvent.eventKey);
|
|
111
112
|
if (!eventDeclared) {
|
|
112
113
|
this.incomingEvents.push(defaultEvent);
|
|
@@ -115,37 +116,35 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
115
116
|
}
|
|
116
117
|
});
|
|
117
118
|
} catch (error) {
|
|
118
|
-
Dynamo_Log.error(`
|
|
119
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Setup Default Events failed, ERROR:`, error);
|
|
119
120
|
throw error;
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
private async setupSocketEvents(): Promise<void> {
|
|
124
125
|
try {
|
|
125
|
-
if (this.
|
|
126
|
+
if (this.debugLog) console.log(`Setup socket-client(${this.params.name}) Events...`);
|
|
126
127
|
|
|
127
128
|
await Dynamo_Array.asyncForEach(this.incomingEvents, async (event: DynamoNTS_SocketEvent<any>) => {
|
|
128
|
-
|
|
129
|
-
event.socketName = this.name;
|
|
130
|
-
}
|
|
129
|
+
event.serviceName = this.params.name;
|
|
131
130
|
this.socket.on(event.eventKey, async (content: any) => {
|
|
132
131
|
try {
|
|
133
132
|
await event.executeEventTasks(content, this.params.service);
|
|
134
133
|
} catch (error) {
|
|
135
|
-
Dynamo_Log.error(`
|
|
134
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Event failed, ERROR:`, error);
|
|
136
135
|
await this.emitEvent(DynamoNTS_SocketEventKey.error, error);
|
|
137
136
|
}
|
|
138
137
|
});
|
|
139
138
|
});
|
|
140
139
|
} catch (error) {
|
|
141
|
-
Dynamo_Log.error(`
|
|
140
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Setup Socket Events failed, ERROR:`, error);
|
|
142
141
|
throw error;
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
private async connectSocket(): Promise<void> {
|
|
147
146
|
try {
|
|
148
|
-
Dynamo_Log.
|
|
147
|
+
Dynamo_Log.info(`< .. > socket-client(${this.params.name}) connecting to ${this.params.address}:${this.params.port} ...`);
|
|
149
148
|
|
|
150
149
|
this.socket.connect();
|
|
151
150
|
|
|
@@ -153,7 +152,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
153
152
|
await this.tryReconnectIfNeeded();
|
|
154
153
|
}
|
|
155
154
|
} catch (error) {
|
|
156
|
-
Dynamo_Log.error(`
|
|
155
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Connect Socket failed, ERROR:`, error);
|
|
157
156
|
throw error;
|
|
158
157
|
}
|
|
159
158
|
}
|
|
@@ -167,7 +166,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
167
166
|
await this.connectSocket();
|
|
168
167
|
}
|
|
169
168
|
} catch (error) {
|
|
170
|
-
Dynamo_Log.error(`
|
|
169
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Try Reconnect failed, ERROR:`, error);
|
|
171
170
|
throw error;
|
|
172
171
|
}
|
|
173
172
|
}
|
|
@@ -179,10 +178,10 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
179
178
|
*/
|
|
180
179
|
protected async emitEvent(eventType: string, content: any): Promise<void> {
|
|
181
180
|
try {
|
|
182
|
-
Dynamo_Log.log(`<-=- outgoing ${this.name}
|
|
181
|
+
Dynamo_Log.log(`<-=- outgoing socket-client(${this.params.name}) event: ${eventType}`);
|
|
183
182
|
this.socket.emit(eventType, content);
|
|
184
183
|
} catch (error) {
|
|
185
|
-
Dynamo_Log.error(`
|
|
184
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Emit Event failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
186
185
|
throw error;
|
|
187
186
|
}
|
|
188
187
|
}
|
|
@@ -355,9 +355,10 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
emitServerEvent(event: string, content: any): void {
|
|
358
|
+
/* emitServerEvent(event: string, content: any): void {
|
|
359
359
|
try {
|
|
360
360
|
Dynamo_Log.log(` <=-- emitting server socket(${this.params.name}) event: ${event}`);
|
|
361
|
+
|
|
361
362
|
this.openSocketServer.emit(event, content, error => {
|
|
362
363
|
Dynamo_Log.error(`Emitting server event '${event}' failed!\nerror:`, error);
|
|
363
364
|
});
|
|
@@ -372,7 +373,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
372
373
|
message: `socket(${this.params.name}) Event Emit (${event}) failed: ${this.params?.name}`,
|
|
373
374
|
});
|
|
374
375
|
}
|
|
375
|
-
}
|
|
376
|
+
} */
|
|
376
377
|
|
|
377
378
|
idIsSubscribed(id: string): boolean {
|
|
378
379
|
try {
|