@futdevpro/nts-dynamo 1.6.59 → 1.6.71
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/app-extended-server.mock.js +8 -13
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js +4 -9
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/auth-service.mock.js +3 -10
- package/lib/_constants/mocks/auth-service.mock.js.map +1 -1
- package/lib/_constants/mocks/data-model.mock.js +17 -0
- package/lib/_constants/mocks/data-model.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.js +1 -4
- package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.js +12 -13
- package/lib/_constants/mocks/endpoint.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-client.mock.js +2 -3
- package/lib/_constants/mocks/socket-client.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js +2 -5
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.js +32 -0
- package/lib/_models/control-models/api-call-params.control-model.js.map +1 -1
- package/lib/_models/control-models/app-params.control-model.js +31 -4
- package/lib/_models/control-models/app-params.control-model.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.js +3 -5
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.js +4 -6
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +91 -88
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-client-service-params.control-model.js +8 -5
- package/lib/_models/control-models/socket-client-service-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js +35 -34
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +10 -9
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-server-service-params.control-model.js +3 -0
- package/lib/_models/control-models/socket-server-service-params.control-model.js.map +1 -1
- package/lib/_models/control-models/system-control.control-model.js +3 -5
- package/lib/_models/control-models/system-control.control-model.js.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.js +6 -7
- package/lib/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/lib/_modules/test/test.controller.js +12 -13
- package/lib/_modules/test/test.controller.js.map +1 -1
- package/lib/_modules/usage/usage.controller.js +15 -14
- package/lib/_modules/usage/usage.controller.js.map +1 -1
- package/lib/_modules/usage/usage.data-service.js +88 -96
- package/lib/_modules/usage/usage.data-service.js.map +1 -1
- package/lib/_services/base/data.service.js +370 -295
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.js +315 -246
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/base/singleton.service.js +2 -0
- package/lib/_services/base/singleton.service.js.map +1 -1
- package/lib/_services/core/api.service.js +185 -188
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/core/auth.service.js +3 -3
- package/lib/_services/core/auth.service.js.map +1 -1
- package/lib/_services/core/email.service.js +103 -88
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/_services/core/global.service.js +38 -40
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/route/controller.service.js +28 -0
- package/lib/_services/route/controller.service.js.map +1 -1
- package/lib/_services/route/routing-module.service.js +11 -8
- package/lib/_services/route/routing-module.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.js +241 -247
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.js +18 -19
- package/lib/_services/server/app-extended.server.spec.js.map +1 -1
- package/lib/_services/server/app.server.js +404 -412
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +12 -13
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.static-service.js +15 -17
- package/lib/_services/shared.static-service.js.map +1 -1
- package/lib/_services/socket/socket-client.service.js +134 -145
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.js +294 -263
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -21
- package/tsconfig.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DynamoNTS_SocketServerService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
6
5
|
const singleton_service_1 = require("../base/singleton.service");
|
|
7
6
|
const global_settings_const_1 = require("../../_constants/global-settings.const");
|
|
@@ -22,262 +21,268 @@ const socket_event_control_model_1 = require("../../_models/control-models/socke
|
|
|
22
21
|
* ```
|
|
23
22
|
*/
|
|
24
23
|
class DynamoNTS_SocketServerService extends singleton_service_1.DynamoNTS_SingletonService {
|
|
24
|
+
params;
|
|
25
25
|
get name() { return this.params.name; }
|
|
26
26
|
get port() { return this.params.port; }
|
|
27
27
|
get security() { return this.params.security; }
|
|
28
|
+
openSocketServer;
|
|
29
|
+
secureSocketServer;
|
|
30
|
+
connectEvent;
|
|
31
|
+
incomingEvents;
|
|
32
|
+
subscriptionEvent;
|
|
33
|
+
presences = [];
|
|
34
|
+
logSetup;
|
|
35
|
+
logFn;
|
|
36
|
+
defaultErrorUserMsg = `We encountered an unhandled Socket Server Error, ` +
|
|
37
|
+
`\nplease contact the responsible development team.`;
|
|
28
38
|
constructor() {
|
|
29
39
|
super();
|
|
30
|
-
this.presences = [];
|
|
31
|
-
this.defaultErrorUserMsg = `We encountered an unhandled Socket Server Error, ` +
|
|
32
|
-
`\nplease contact the responsible development team.`;
|
|
33
40
|
this.asyncConstructor().catch((error) => {
|
|
34
|
-
|
|
35
|
-
fsm_dynamo_1.Dynamo_Log.error(`Socket Server Service setup failed: ${(_a = this.params) === null || _a === void 0 ? void 0 : _a.name} (${(_b = this.params) === null || _b === void 0 ? void 0 : _b.port})`, error);
|
|
41
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Server Service setup failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
36
42
|
});
|
|
37
43
|
}
|
|
38
|
-
asyncConstructor() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
});
|
|
44
|
+
async asyncConstructor() {
|
|
45
|
+
try {
|
|
46
|
+
this.logSetup = global_settings_const_1.dynamoNTS_globalSettings.logSetup;
|
|
47
|
+
this.params = this.getServiceParams();
|
|
48
|
+
this.incomingEvents = this.getIncomingEvents() ?? [];
|
|
49
|
+
await this.prepareEvents();
|
|
50
|
+
if (this.logSetup)
|
|
51
|
+
console.log(`Socket Server Service setup done: ${this.params.name} (${this.params.port}) serurity: ${this.params.security}\n`);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Server Service setup failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
55
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
56
|
+
errorCode: 'NTS-SSS-001',
|
|
57
|
+
error: error,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* You must setup events and required services for this function
|
|
60
63
|
*/
|
|
61
|
-
prepareEvents() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
async prepareEvents() {
|
|
65
|
+
try {
|
|
66
|
+
/** Setup connect event */
|
|
67
|
+
const connectEventIndex = this.incomingEvents.findIndex((event) => event.eventKey === socket_event_type_enum_1.DynamoNTS_SocketEventKey.connection);
|
|
68
|
+
if (0 <= connectEventIndex) {
|
|
69
|
+
this.connectEvent = this.incomingEvents.splice(connectEventIndex)[0];
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.connectEvent = new socket_event_control_model_1.DynamoNTS_SocketEvent({
|
|
73
|
+
eventKey: socket_event_type_enum_1.DynamoNTS_SocketEventKey.connection,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
this.connectEvent.serviceName = this.params.name;
|
|
77
|
+
/** Setup subscription event */
|
|
78
|
+
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
79
|
+
const subscriptionEventIndex = this.incomingEvents.findIndex((event) => event.eventKey === socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscribe);
|
|
80
|
+
if (0 <= subscriptionEventIndex) {
|
|
81
|
+
this.subscriptionEvent = this.incomingEvents.splice(subscriptionEventIndex)[0];
|
|
82
|
+
fsm_dynamo_1.Dynamo_Log.error(`You should not set the subscription event, but the subscriptions tasks, ` +
|
|
83
|
+
`in case you need additional steps for your subscriptions.`, `${this.params.name} (${this.params.port})`);
|
|
69
84
|
}
|
|
70
85
|
else {
|
|
71
|
-
this.
|
|
72
|
-
eventKey: socket_event_type_enum_1.DynamoNTS_SocketEventKey.
|
|
86
|
+
this.subscriptionEvent = new socket_event_control_model_1.DynamoNTS_SocketEvent({
|
|
87
|
+
eventKey: socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscribe
|
|
73
88
|
});
|
|
74
89
|
}
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
if (this.getSubscriptionPreProcessess) {
|
|
90
|
-
this.subscriptionEvent.preProcessess.push(...this.getSubscriptionPreProcessess());
|
|
91
|
-
}
|
|
92
|
-
if (this.getSubscriptionTasks) {
|
|
93
|
-
this.subscriptionEvent.tasks.push(...this.getSubscriptionTasks());
|
|
94
|
-
}
|
|
95
|
-
this.subscriptionEvent.serviceName = this.params.name;
|
|
96
|
-
/** Setup disconnect event */
|
|
97
|
-
const disconnectEventIndex = this.incomingEvents.findIndex((event) => event.eventKey === socket_event_type_enum_1.DynamoNTS_SocketEventKey.disconnect);
|
|
98
|
-
if (0 <= disconnectEventIndex) {
|
|
99
|
-
this.incomingEvents[disconnectEventIndex].serviceName = this.params.name;
|
|
100
|
-
this.incomingEvents[disconnectEventIndex].tasks.push(this.disconnectBaseTask);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
this.incomingEvents.push(new socket_event_control_model_1.DynamoNTS_SocketEvent({
|
|
104
|
-
serviceName: this.params.name,
|
|
105
|
-
eventKey: socket_event_type_enum_1.DynamoNTS_SocketEventKey.disconnect,
|
|
106
|
-
tasks: [
|
|
107
|
-
this.disconnectBaseTask
|
|
108
|
-
]
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
/** Setup error event */
|
|
112
|
-
const errorEventIndex = this.incomingEvents.findIndex((event) => event.eventKey === socket_event_type_enum_1.DynamoNTS_SocketEventKey.error);
|
|
113
|
-
if (errorEventIndex == -1 && this.errorHandling) {
|
|
114
|
-
this.incomingEvents.push(new socket_event_control_model_1.DynamoNTS_SocketEvent({
|
|
115
|
-
serviceName: this.params.name,
|
|
116
|
-
eventKey: socket_event_type_enum_1.DynamoNTS_SocketEventKey.error,
|
|
117
|
-
tasks: [
|
|
118
|
-
this.errorHandling
|
|
119
|
-
]
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
this.subscriptionEvent.socketName = this.params.name;
|
|
90
|
+
if (this.getSubscriptionPreProcessess) {
|
|
91
|
+
this.subscriptionEvent.preProcessess.push(...this.getSubscriptionPreProcessess());
|
|
92
|
+
}
|
|
93
|
+
if (this.getSubscriptionTasks) {
|
|
94
|
+
this.subscriptionEvent.tasks.push(...this.getSubscriptionTasks());
|
|
95
|
+
}
|
|
96
|
+
this.subscriptionEvent.serviceName = this.params.name;
|
|
97
|
+
/** Setup disconnect event */
|
|
98
|
+
const disconnectEventIndex = this.incomingEvents.findIndex((event) => event.eventKey === socket_event_type_enum_1.DynamoNTS_SocketEventKey.disconnect);
|
|
99
|
+
if (0 <= disconnectEventIndex) {
|
|
100
|
+
this.incomingEvents[disconnectEventIndex].serviceName = this.params.name;
|
|
101
|
+
this.incomingEvents[disconnectEventIndex].tasks.push(this.disconnectBaseTask);
|
|
123
102
|
}
|
|
124
103
|
else {
|
|
125
|
-
|
|
104
|
+
this.incomingEvents.push(new socket_event_control_model_1.DynamoNTS_SocketEvent({
|
|
105
|
+
serviceName: this.params.name,
|
|
106
|
+
eventKey: socket_event_type_enum_1.DynamoNTS_SocketEventKey.disconnect,
|
|
107
|
+
tasks: [
|
|
108
|
+
this.disconnectBaseTask
|
|
109
|
+
]
|
|
110
|
+
}));
|
|
126
111
|
}
|
|
127
|
-
/**
|
|
128
|
-
this.incomingEvents.
|
|
129
|
-
|
|
130
|
-
|
|
112
|
+
/** Setup error event */
|
|
113
|
+
const errorEventIndex = this.incomingEvents.findIndex((event) => event.eventKey === socket_event_type_enum_1.DynamoNTS_SocketEventKey.error);
|
|
114
|
+
if (errorEventIndex == -1 && this.errorHandling) {
|
|
115
|
+
this.incomingEvents.push(new socket_event_control_model_1.DynamoNTS_SocketEvent({
|
|
116
|
+
serviceName: this.params.name,
|
|
117
|
+
eventKey: socket_event_type_enum_1.DynamoNTS_SocketEventKey.error,
|
|
118
|
+
tasks: [
|
|
119
|
+
this.errorHandling
|
|
120
|
+
]
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
this.subscriptionEvent.socketName = this.params.name;
|
|
131
124
|
}
|
|
132
|
-
|
|
133
|
-
fsm_dynamo_1.Dynamo_Log.error(
|
|
134
|
-
throw error;
|
|
125
|
+
else {
|
|
126
|
+
fsm_dynamo_1.Dynamo_Log.error('getPresenceFromSubscrioptionEventContent is not set', `${this.params.name} (${this.params.port})`);
|
|
135
127
|
}
|
|
136
|
-
|
|
128
|
+
/** Set incoming events serviceName */
|
|
129
|
+
this.incomingEvents.forEach((event) => {
|
|
130
|
+
event.serviceName = this.params.name;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Server Service - Event Preparation setup failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
137
|
}
|
|
138
|
-
setupSocketServer(newSocketServer, security, successCallback) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
fsm_dynamo_1.Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscribe};` +
|
|
158
|
-
`\ncontent:`, content);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
fsm_dynamo_1.Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscribe}`);
|
|
162
|
-
}
|
|
163
|
-
const presence = yield this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
164
|
-
presence.serviceName = this.params.name;
|
|
165
|
-
issuer = presence.issuerId;
|
|
166
|
-
this.addSocketToPresence(presence);
|
|
167
|
-
yield this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
168
|
-
socket.emit(socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscriptionSuccessful, 'subscribe was successful', error => {
|
|
169
|
-
fsm_dynamo_1.Dynamo_Log.error(`Emitting subscriptionSuccessful event failed!\nerror:`, error);
|
|
170
|
-
});
|
|
171
|
-
fsm_dynamo_1.Dynamo_Log.success(`<===> socket(${this.params.name}) subscription successfull (${issuer})`);
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
fsm_dynamo_1.Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
175
|
-
socket.emit(socket_event_type_enum_1.DynamoNTS_SocketEventKey.error, error);
|
|
176
|
-
socket.disconnect();
|
|
177
|
-
}
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
this.incomingEvents.forEach((event) => {
|
|
181
|
-
socket.on(event.eventKey, (content) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
try {
|
|
183
|
-
yield event.executeEventTasks(content, issuer);
|
|
138
|
+
async setupSocketServer(newSocketServer, security, successCallback) {
|
|
139
|
+
try {
|
|
140
|
+
if (this.logFn)
|
|
141
|
+
console.log('\nfn:. setupSocketServer');
|
|
142
|
+
newSocketServer.on(socket_event_type_enum_1.DynamoNTS_SocketEventKey.connection, async (socket) => {
|
|
143
|
+
try {
|
|
144
|
+
let issuer;
|
|
145
|
+
await this.connectEvent.executeEventTasks(socket);
|
|
146
|
+
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
147
|
+
socket.on(socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscribe, async (content) => {
|
|
148
|
+
try {
|
|
149
|
+
/**
|
|
150
|
+
* usually socket logs are in event.executeEventTasks(),
|
|
151
|
+
* but subscribe event is an exception from this,
|
|
152
|
+
* to be able to check content before getPresenceFromSubscrioptionEventContent
|
|
153
|
+
*/
|
|
154
|
+
if (global_settings_const_1.dynamoNTS_globalSettings.logSocketEventContent) {
|
|
155
|
+
fsm_dynamo_1.Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscribe};` +
|
|
156
|
+
`\ncontent:`, content);
|
|
184
157
|
}
|
|
185
|
-
|
|
186
|
-
fsm_dynamo_1.Dynamo_Log.
|
|
187
|
-
socket.emit(socket_event_type_enum_1.DynamoNTS_SocketEventKey.error, error);
|
|
158
|
+
else {
|
|
159
|
+
fsm_dynamo_1.Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscribe}`);
|
|
188
160
|
}
|
|
189
|
-
|
|
161
|
+
const presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
162
|
+
presence.serviceName = this.params.name;
|
|
163
|
+
issuer = presence.issuerId;
|
|
164
|
+
this.addSocketToPresence(presence);
|
|
165
|
+
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
166
|
+
socket.emit(socket_event_type_enum_1.DynamoNTS_SocketEventKey.subscriptionSuccessful, 'subscribe was successful', error => {
|
|
167
|
+
fsm_dynamo_1.Dynamo_Log.error(`Emitting subscriptionSuccessful event failed!\nerror:`, error);
|
|
168
|
+
});
|
|
169
|
+
fsm_dynamo_1.Dynamo_Log.success(`<===> socket(${this.params.name}) subscription successfull (${issuer})`);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
173
|
+
socket.emit(socket_event_type_enum_1.DynamoNTS_SocketEventKey.error, error);
|
|
174
|
+
socket.disconnect();
|
|
175
|
+
}
|
|
190
176
|
});
|
|
191
|
-
if (global_settings_const_1.dynamoNTS_globalSettings.logMainSocketEvents) {
|
|
192
|
-
fsm_dynamo_1.Dynamo_Log.success(`< > socket(${this.params.name}): new CONNECTION established`);
|
|
193
|
-
}
|
|
194
177
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
178
|
+
this.incomingEvents.forEach((event) => {
|
|
179
|
+
socket.on(event.eventKey, async (content) => {
|
|
180
|
+
try {
|
|
181
|
+
await event.executeEventTasks(content, issuer);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
185
|
+
socket.emit(socket_event_type_enum_1.DynamoNTS_SocketEventKey.error, error);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
if (global_settings_const_1.dynamoNTS_globalSettings.logMainSocketEvents) {
|
|
190
|
+
fsm_dynamo_1.Dynamo_Log.success(`< > socket(${this.params.name}): new CONNECTION established`);
|
|
199
191
|
}
|
|
200
|
-
}));
|
|
201
|
-
newSocketServer.listen(this.params.port);
|
|
202
|
-
fsm_dynamo_1.Dynamo_Log.success(`\nsocket server setup finished: ${this.params.name}` +
|
|
203
|
-
`\nsocket server listening on port: ${this.params.port}`);
|
|
204
|
-
successCallback();
|
|
205
|
-
if (security === socket_security_enum_1.DynamoNTS_SocketSecurity.open) {
|
|
206
|
-
this.openSocketServer = newSocketServer;
|
|
207
|
-
return this.openSocketServer;
|
|
208
192
|
}
|
|
209
|
-
|
|
210
|
-
this.
|
|
211
|
-
|
|
193
|
+
catch (error) {
|
|
194
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Connection failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
|
|
195
|
+
socket.emit(socket_event_type_enum_1.DynamoNTS_SocketEventKey.error, error);
|
|
196
|
+
socket.disconnect();
|
|
212
197
|
}
|
|
198
|
+
});
|
|
199
|
+
newSocketServer.listen(this.params.port);
|
|
200
|
+
fsm_dynamo_1.Dynamo_Log.success(`\nsocket server setup finished: ${this.params.name}` +
|
|
201
|
+
`\nsocket server listening on port: ${this.params.port}`);
|
|
202
|
+
successCallback();
|
|
203
|
+
if (security === socket_security_enum_1.DynamoNTS_SocketSecurity.open) {
|
|
204
|
+
this.openSocketServer = newSocketServer;
|
|
205
|
+
return this.openSocketServer;
|
|
213
206
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
else {
|
|
208
|
+
this.secureSocketServer = newSocketServer;
|
|
209
|
+
return this.secureSocketServer;
|
|
217
210
|
}
|
|
218
|
-
}
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Server Service - Deep Setup failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
219
216
|
}
|
|
220
|
-
addSocketToPresence(newPresence) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (activePresence) {
|
|
226
|
-
activePresence.sockets.push(...newPresence.sockets);
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
this.presences.push(newPresence);
|
|
230
|
-
}
|
|
217
|
+
async addSocketToPresence(newPresence) {
|
|
218
|
+
try {
|
|
219
|
+
const activePresence = this.presences.find((pres) => pres.issuerId === newPresence.issuerId);
|
|
220
|
+
if (activePresence) {
|
|
221
|
+
activePresence.sockets.push(...newPresence.sockets);
|
|
231
222
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
throw error;
|
|
223
|
+
else {
|
|
224
|
+
this.presences.push(newPresence);
|
|
235
225
|
}
|
|
236
|
-
}
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
fsm_dynamo_1.Dynamo_Log.error(`Socket Subscription failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
237
231
|
}
|
|
238
|
-
disconnectBaseTask(socket, issuer) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
232
|
+
async disconnectBaseTask(socket, issuer) {
|
|
233
|
+
try {
|
|
234
|
+
await this.removeSubscription(socket, issuer);
|
|
235
|
+
fsm_dynamo_1.Dynamo_Log.info(`< x > socket(${this.params.name}) disconnected (${issuer})`);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
239
|
+
...this._getDefaultErrorSettings('disconnectBaseTask', error, issuer),
|
|
240
|
+
errorCode: 'NTS-SSS-109'
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async removeSubscription(socket, issuer) {
|
|
245
|
+
try {
|
|
246
|
+
const activePresenceIndex = this.presences.findIndex((pres) => pres.sockets.includes(socket));
|
|
247
|
+
if (activePresenceIndex === -1) {
|
|
248
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
249
|
+
...this._getDefaultErrorSettings('sendEventForId', new Error(`closing socket(${this.params.name}) does not match any in the activePresences`), issuer),
|
|
250
|
+
errorCode: 'NTS-SSS-203',
|
|
251
|
+
});
|
|
243
252
|
}
|
|
244
|
-
|
|
245
|
-
|
|
253
|
+
const activePresence = this.presences[activePresenceIndex];
|
|
254
|
+
if (activePresence.issuerId !== issuer) {
|
|
255
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
256
|
+
...this._getDefaultErrorSettings('sendEventForId', new Error(`socket subscription for ${issuer} and ${activePresence.issuerId} does not match.`), issuer),
|
|
257
|
+
errorCode: 'NTS-SSS-201',
|
|
258
|
+
});
|
|
246
259
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const activePresenceIndex = this.presences.findIndex((pres) => pres.sockets.includes(socket));
|
|
254
|
-
if (activePresenceIndex === -1) {
|
|
255
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('sendEventForId', new Error(`closing socket(${this.params.name}) does not match any in the activePresences`), issuer)), { errorCode: 'NTS-SSS-203' }));
|
|
256
|
-
}
|
|
257
|
-
const activePresence = this.presences[activePresenceIndex];
|
|
258
|
-
if (activePresence.issuerId !== issuer) {
|
|
259
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('sendEventForId', new Error(`socket subscription for ${issuer} and ${activePresence.issuerId} does not match.`), issuer)), { errorCode: 'NTS-SSS-201' }));
|
|
260
|
-
}
|
|
261
|
-
const socketIndex = activePresence.sockets.findIndex((s) => s === socket);
|
|
262
|
-
if (socketIndex === -1) {
|
|
263
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('sendEventForId', new Error(`closing socket(${this.params.name}) does not match any in the activePresences`), issuer)), { errorCode: 'NTS-SSS-202' }));
|
|
264
|
-
}
|
|
265
|
-
activePresence.sockets.splice(socketIndex);
|
|
266
|
-
if (this.getSubscriptionCloseTasks) {
|
|
267
|
-
yield fsm_dynamo_1.Dynamo_Array.asyncForEach(this.getSubscriptionCloseTasks(), (task) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
yield task(null, issuer);
|
|
269
|
-
}));
|
|
270
|
-
}
|
|
271
|
-
if (activePresence.sockets.length === 0) {
|
|
272
|
-
this.presences.splice(activePresenceIndex);
|
|
273
|
-
}
|
|
274
|
-
socket.disconnect();
|
|
275
|
-
fsm_dynamo_1.Dynamo_Log.info(`<=x=> socket(${this.params.name}) unsubscription successfull (${issuer})`);
|
|
260
|
+
const socketIndex = activePresence.sockets.findIndex((s) => s === socket);
|
|
261
|
+
if (socketIndex === -1) {
|
|
262
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
263
|
+
...this._getDefaultErrorSettings('sendEventForId', new Error(`closing socket(${this.params.name}) does not match any in the activePresences`), issuer),
|
|
264
|
+
errorCode: 'NTS-SSS-202',
|
|
265
|
+
});
|
|
276
266
|
}
|
|
277
|
-
|
|
278
|
-
|
|
267
|
+
activePresence.sockets.splice(socketIndex);
|
|
268
|
+
if (this.getSubscriptionCloseTasks) {
|
|
269
|
+
await fsm_dynamo_1.Dynamo_Array.asyncForEach(this.getSubscriptionCloseTasks(), async (task) => {
|
|
270
|
+
await task(null, issuer);
|
|
271
|
+
});
|
|
279
272
|
}
|
|
280
|
-
|
|
273
|
+
if (activePresence.sockets.length === 0) {
|
|
274
|
+
this.presences.splice(activePresenceIndex);
|
|
275
|
+
}
|
|
276
|
+
socket.disconnect();
|
|
277
|
+
fsm_dynamo_1.Dynamo_Log.info(`<=x=> socket(${this.params.name}) unsubscription successfull (${issuer})`);
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
281
|
+
...this._getDefaultErrorSettings('sendEventForId', error, issuer),
|
|
282
|
+
errorCode: 'NTS-SSS-200',
|
|
283
|
+
message: `socket(${this.params.name}) Subscription Removal failed: ${this.params?.name}`,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
281
286
|
}
|
|
282
287
|
/* emitServerEvent(event: string, content: any): void {
|
|
283
288
|
try {
|
|
@@ -303,55 +308,74 @@ class DynamoNTS_SocketServerService extends singleton_service_1.DynamoNTS_Single
|
|
|
303
308
|
return !!this.presences.find((presence) => presence.issuerId === id);
|
|
304
309
|
}
|
|
305
310
|
catch (error) {
|
|
306
|
-
throw new fsm_dynamo_1.Dynamo_Error(
|
|
311
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
312
|
+
...this._getDefaultErrorSettings('idIsSubscribed', error),
|
|
313
|
+
errorCode: 'NTS-SSS-600',
|
|
314
|
+
message: `socket(${this.params.name}) ID Subscription Check (${id}) failed`,
|
|
315
|
+
});
|
|
307
316
|
}
|
|
308
317
|
}
|
|
309
|
-
emitError(presenceIssuerId, error) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
318
|
+
async emitError(presenceIssuerId, error) {
|
|
319
|
+
try {
|
|
320
|
+
await this.sendEventForId(presenceIssuerId, socket_event_type_enum_1.DynamoNTS_SocketEventKey.error, error);
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
324
|
+
...this._getDefaultErrorSettings('emitError', error, presenceIssuerId),
|
|
325
|
+
errorCode: 'NTS-SSS-700',
|
|
326
|
+
message: `socket(${this.params.name}) Error Emit (id: ${presenceIssuerId}) failed`,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async sendEventForId(id, event, content /* , error?: (err: any) => void */) {
|
|
331
|
+
try {
|
|
332
|
+
const presence = this.presences.find((pres) => pres.issuerId === id);
|
|
333
|
+
if (!presence) {
|
|
334
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
335
|
+
...this._getDefaultErrorSettings('sendEventForId', new Error(`No active socket with this specific ID: ${id}`), content?.source),
|
|
336
|
+
status: 404,
|
|
337
|
+
errorCode: 'NTS-SSS-301',
|
|
338
|
+
});
|
|
313
339
|
}
|
|
314
|
-
|
|
315
|
-
|
|
340
|
+
presence.emitEvent(event, content);
|
|
341
|
+
if (global_settings_const_1.dynamoNTS_globalSettings.logSocketEventContent) {
|
|
342
|
+
fsm_dynamo_1.Dynamo_Log.success(` <--- emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id}) \ncontent:`, content);
|
|
316
343
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
344
|
+
else {
|
|
345
|
+
fsm_dynamo_1.Dynamo_Log.success(` <--- emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id})`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
322
349
|
try {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
350
|
+
if (error.flag.includes('DYNAMO') && error?.accitionalInfo?.inactiveSockets) {
|
|
351
|
+
const sockets = error.accitionalInfo.inactiveSockets;
|
|
352
|
+
await fsm_dynamo_1.Dynamo_Array.asyncForEach(sockets, async (socket) => {
|
|
353
|
+
await this.removeSubscription(socket);
|
|
354
|
+
});
|
|
355
|
+
const presence = this.presences.find((pres) => pres.issuerId === id);
|
|
356
|
+
if (!presence) {
|
|
357
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
358
|
+
...this._getDefaultErrorSettings('sendEventForId', new Error(`No active socket(${this.params.name}) with this specific ID: ${id}`), content?.source),
|
|
359
|
+
status: 404,
|
|
360
|
+
errorCode: 'NTS-SSS-302',
|
|
361
|
+
});
|
|
362
|
+
}
|
|
333
363
|
}
|
|
334
364
|
}
|
|
335
365
|
catch (error) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const presence = this.presences.find((pres) => pres.issuerId === id);
|
|
343
|
-
if (!presence) {
|
|
344
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('sendEventForId', new Error(`No active socket(${this.params.name}) with this specific ID: ${id}`), content === null || content === void 0 ? void 0 : content.source)), { status: 404, errorCode: 'NTS-SSS-302' }));
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
catch (error) {
|
|
349
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('sendEventForId', error, content === null || content === void 0 ? void 0 : content.source)), { errorCode: 'NTS-SSS-310', message: `Error handling of inactive sockets(${this.params.name}) failed!` +
|
|
350
|
-
`\n(Socket Event Emit for id (${id}, ${event}) failed)` }));
|
|
351
|
-
}
|
|
352
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('sendEventForId', error, content === null || content === void 0 ? void 0 : content.source)), { errorCode: 'NTS-SSS-310', message: `socket(${this.params.name}) Event Emit for id (${id}, ${event}) failed` }));
|
|
366
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
367
|
+
...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
|
|
368
|
+
errorCode: 'NTS-SSS-310',
|
|
369
|
+
message: `Error handling of inactive sockets(${this.params.name}) failed!` +
|
|
370
|
+
`\n(Socket Event Emit for id (${id}, ${event}) failed)`,
|
|
371
|
+
});
|
|
353
372
|
}
|
|
354
|
-
|
|
373
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
374
|
+
...this._getDefaultErrorSettings('sendEventForId', error, content?.source),
|
|
375
|
+
errorCode: 'NTS-SSS-310',
|
|
376
|
+
message: `socket(${this.params.name}) Event Emit for id (${id}, ${event}) failed`,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
355
379
|
}
|
|
356
380
|
broadcastEvent(event, content) {
|
|
357
381
|
try {
|
|
@@ -362,21 +386,28 @@ class DynamoNTS_SocketServerService extends singleton_service_1.DynamoNTS_Single
|
|
|
362
386
|
}
|
|
363
387
|
catch (error) {
|
|
364
388
|
fsm_dynamo_1.Dynamo_Log.error(`socket(${this.params.name}) Event Broadcast (${event}) failed`, error);
|
|
365
|
-
throw new fsm_dynamo_1.Dynamo_Error(
|
|
389
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
390
|
+
...this._getDefaultErrorSettings('broadcastEvent', error),
|
|
391
|
+
errorCode: 'NTS-SSS-400',
|
|
392
|
+
message: `socket(${this.params.name}) Event Broadcast (${event}) failed`,
|
|
393
|
+
});
|
|
366
394
|
}
|
|
367
395
|
}
|
|
368
396
|
_getDefaultErrorSettings(fnName, error, issuer) {
|
|
369
|
-
var _a, _b, _c;
|
|
370
397
|
return {
|
|
371
|
-
status:
|
|
372
|
-
message:
|
|
398
|
+
status: error?.___status ?? 500,
|
|
399
|
+
message: error?.message ?? `${fnName} was UNSUCCESFUL (NTS)`,
|
|
373
400
|
addECToUserMsg: true,
|
|
374
401
|
userMessage: this.defaultErrorUserMsg,
|
|
375
402
|
issuer: issuer,
|
|
376
|
-
issuerService:
|
|
403
|
+
issuerService: this.constructor?.name,
|
|
377
404
|
error: error,
|
|
378
405
|
};
|
|
379
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* You can setup tasks for the error event in this function
|
|
409
|
+
*/
|
|
410
|
+
errorHandling;
|
|
380
411
|
}
|
|
381
412
|
exports.DynamoNTS_SocketServerService = DynamoNTS_SocketServerService;
|
|
382
413
|
//# sourceMappingURL=socket-server.service.js.map
|