@futdevpro/nts-dynamo 1.5.94 → 1.5.96
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/dynamo-nts-socket-client-service-params.model.d.ts +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-client-service-params.model.d.ts.map +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-client-service-params.model.js +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-client-service-params.model.js.map +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-event.model.d.ts +4 -4
- package/lib/_models/control-models/dynamo-nts-socket-event.model.d.ts.map +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-event.model.js +6 -6
- package/lib/_models/control-models/dynamo-nts-socket-event.model.js.map +1 -1
- package/lib/_modules/app-extended.index.d.ts +1 -1
- package/lib/_modules/app-extended.index.d.ts.map +1 -1
- package/lib/_modules/app-extended.index.js +1 -1
- package/lib/_modules/app-extended.index.js.map +1 -1
- package/lib/_modules/app.index.d.ts +1 -1
- package/lib/_modules/app.index.d.ts.map +1 -1
- package/lib/_modules/app.index.js +1 -1
- package/lib/_modules/app.index.js.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.server.d.ts +129 -0
- package/lib/_services/dynamo-nts-app-extended.server.d.ts.map +1 -0
- package/lib/_services/dynamo-nts-app-extended.server.js +213 -0
- package/lib/_services/dynamo-nts-app-extended.server.js.map +1 -0
- package/lib/_services/dynamo-nts-app.server.d.ts +275 -0
- package/lib/_services/dynamo-nts-app.server.d.ts.map +1 -0
- package/lib/_services/dynamo-nts-app.server.js +372 -0
- package/lib/_services/dynamo-nts-app.server.js.map +1 -0
- package/lib/_services/dynamo-nts-app.server.spec.d.ts +1 -0
- package/lib/_services/dynamo-nts-app.server.spec.d.ts.map +1 -0
- package/lib/_services/dynamo-nts-app.server.spec.js +10 -0
- package/lib/_services/dynamo-nts-app.server.spec.js.map +1 -0
- package/lib/_services/dynamo-nts-socket-client.service.d.ts +8 -1
- package/lib/_services/dynamo-nts-socket-client.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket-client.service.js +40 -18
- package/lib/_services/dynamo-nts-socket-client.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket-server.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket-server.service.js +9 -13
- package/lib/_services/dynamo-nts-socket-server.service.js.map +1 -1
- package/lib/_services/index.d.ts +2 -2
- package/lib/_services/index.d.ts.map +1 -1
- package/lib/_services/index.js +2 -2
- package/lib/_services/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_models/control-models/dynamo-nts-socket-client-service-params.model.ts +1 -1
- package/src/_models/control-models/dynamo-nts-socket-event.model.ts +10 -10
- package/src/_modules/app-extended.index.ts +1 -1
- package/src/_modules/app.index.ts +1 -1
- package/src/_services/{dynamo-nts-app-extended.ts → dynamo-nts-app-extended.server.ts} +1 -1
- package/src/_services/dynamo-nts-socket-client.service.ts +40 -15
- package/src/_services/dynamo-nts-socket-server.service.ts +9 -14
- package/src/_services/index.ts +2 -2
- /package/src/_services/{dynamo-nts-app.spec.ts → dynamo-nts-app.server.spec.ts} +0 -0
- /package/src/_services/{dynamo-nts-app.ts → dynamo-nts-app.server.ts} +0 -0
|
@@ -13,18 +13,18 @@ export type DynamoNTS_SocketEventTask = (content?: any, issuer?: string) => Prom
|
|
|
13
13
|
*/
|
|
14
14
|
export class DynamoNTS_SocketEvent<T_EventContent>{
|
|
15
15
|
socketName?: string;
|
|
16
|
-
|
|
16
|
+
eventType: DynamoNTS_SocketEventType | string;
|
|
17
17
|
|
|
18
18
|
preProcessess?: DynamoNTS_SocketEventPreprocessTask<T_EventContent>[];
|
|
19
19
|
tasks: DynamoNTS_SocketEventTask[];
|
|
20
20
|
|
|
21
|
-
logEvent
|
|
22
|
-
logEventContent
|
|
21
|
+
logEvent?: boolean;
|
|
22
|
+
logEventContent?: boolean;
|
|
23
23
|
|
|
24
24
|
constructor(
|
|
25
25
|
set: {
|
|
26
26
|
socketName?: string,
|
|
27
|
-
|
|
27
|
+
eventType: DynamoNTS_SocketEventType | string,
|
|
28
28
|
|
|
29
29
|
preProcessess?: DynamoNTS_SocketEventPreprocessTask<T_EventContent>[],
|
|
30
30
|
tasks?: DynamoNTS_SocketEventTask[],
|
|
@@ -35,14 +35,14 @@ export class DynamoNTS_SocketEvent<T_EventContent>{
|
|
|
35
35
|
) {
|
|
36
36
|
try {
|
|
37
37
|
this.socketName = set.socketName;
|
|
38
|
-
this.
|
|
38
|
+
this.eventType = set.eventType;
|
|
39
39
|
|
|
40
40
|
this.preProcessess = set.preProcessess ?? [];
|
|
41
41
|
this.tasks = set.tasks ?? [];
|
|
42
42
|
|
|
43
43
|
if (set.logEvent !== undefined) {
|
|
44
44
|
this.logEvent = set.logEvent;
|
|
45
|
-
} else if (this.
|
|
45
|
+
} else if (this.eventType === DynamoNTS_SocketEventType.connection || this.eventType === DynamoNTS_SocketEventType.disconnect) {
|
|
46
46
|
this.logEvent = dynamoNTS_GlobalSettings.logMainSocketEvent;
|
|
47
47
|
} else {
|
|
48
48
|
this.logEvent = dynamoNTS_GlobalSettings.logAllSocketEvent;
|
|
@@ -54,7 +54,7 @@ export class DynamoNTS_SocketEvent<T_EventContent>{
|
|
|
54
54
|
}
|
|
55
55
|
} catch (error) {
|
|
56
56
|
Dynamo_Log.error(
|
|
57
|
-
`\nSocket Event params setup failed (${this.socketName}): ${set.
|
|
57
|
+
`\nSocket Event params setup failed (${this.socketName}): ${set.eventType}`, error);
|
|
58
58
|
throw error;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -68,9 +68,9 @@ export class DynamoNTS_SocketEvent<T_EventContent>{
|
|
|
68
68
|
try {
|
|
69
69
|
if (this.logEvent) {
|
|
70
70
|
if (this.logEventContent) {
|
|
71
|
-
console.log(`==> incoming ${this.socketName} socket event: ${this.
|
|
71
|
+
console.log(`==> incoming ${this.socketName} socket event: ${this.eventType} content:`, content);
|
|
72
72
|
} else {
|
|
73
|
-
console.log(`==> incoming ${this.socketName} socket event: ${this.
|
|
73
|
+
console.log(`==> incoming ${this.socketName} socket event: ${this.eventType}...`);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return content;
|
|
@@ -94,7 +94,7 @@ export class DynamoNTS_SocketEvent<T_EventContent>{
|
|
|
94
94
|
await this.tasks[i](content, issuer);
|
|
95
95
|
}
|
|
96
96
|
} catch (error) {
|
|
97
|
-
console.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.
|
|
97
|
+
console.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.eventType})`, error, 'content:', content);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
// SERVICES
|
|
3
|
-
export * from '../_services/dynamo-nts-app-extended';
|
|
3
|
+
export * from '../_services/dynamo-nts-app-extended.server';
|
|
4
4
|
export * from '../_services/dynamo-nts-global.service';
|
|
5
5
|
export * from '../_services/dynamo-nts-routing-module.service';
|
|
6
6
|
export * from '../_services/dynamo-nts-shared.service';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
// SERVICES
|
|
3
|
-
export * from '../_services/dynamo-nts-app';
|
|
3
|
+
export * from '../_services/dynamo-nts-app.server';
|
|
4
4
|
export * from '../_services/dynamo-nts-global.service';
|
|
5
5
|
export * from '../_services/dynamo-nts-routing-module.service';
|
|
6
6
|
export * from '../_services/dynamo-nts-shared.service';
|
|
@@ -4,7 +4,7 @@ import * as Http from 'http';
|
|
|
4
4
|
|
|
5
5
|
import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
6
6
|
|
|
7
|
-
import { DynamoNTS_App } from './dynamo-nts-app';
|
|
7
|
+
import { DynamoNTS_App } from './dynamo-nts-app.server';
|
|
8
8
|
import { DynamoNTS_RouteSecurity } from '../_enums/dynamo-nts-route-security.enum';
|
|
9
9
|
import { DynamoNTS_SocketServerService } from './dynamo-nts-socket-server.service';
|
|
10
10
|
import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.enum';
|
|
@@ -21,38 +21,63 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
21
21
|
protected socket: SocketIO.Socket
|
|
22
22
|
|
|
23
23
|
protected incomingEvents: DynamoNTS_SocketEvent<any>[];
|
|
24
|
+
private defaultEvents: DynamoNTS_SocketEventType[] = [
|
|
25
|
+
DynamoNTS_SocketEventType.disconnect,
|
|
26
|
+
];
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
protected constructor() {
|
|
26
29
|
super();
|
|
27
30
|
|
|
28
31
|
try {
|
|
32
|
+
this._params = this.getParams();
|
|
29
33
|
this.incomingEvents = this.getIncomingEvents() ?? [];
|
|
30
34
|
|
|
35
|
+
this.setupDefaultEvents();
|
|
36
|
+
|
|
31
37
|
this.connectSocket();
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
console.log(`Socket Client Service setup finished: ${this.params?.name}: (${this.params.port})\n`);
|
|
34
40
|
} catch (error) {
|
|
35
|
-
Dynamo_Log.error(`Socket Client setup failed: ${this.params.name} (${this.params.port})`, error);
|
|
41
|
+
Dynamo_Log.error(`Socket Client Service setup failed: ${this.params.name} (${this.params.port})`, error);
|
|
36
42
|
}
|
|
37
43
|
}
|
|
44
|
+
|
|
45
|
+
private setupDefaultEvents(): void {
|
|
46
|
+
this.defaultEvents.forEach((eventType: DynamoNTS_SocketEventType) => {
|
|
47
|
+
if (!this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.eventType === eventType)) {
|
|
48
|
+
this.incomingEvents.push(new DynamoNTS_SocketEvent<any>({
|
|
49
|
+
eventType: eventType,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
38
54
|
|
|
39
55
|
private connectSocket(): void {
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
47
|
-
this.socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
});
|
|
56
|
+
if (this.log) console.log(`Socket Client connecting... ${this.params.name}`);
|
|
57
|
+
this.socket = SocketIO.io(`${this.params.address}:${this.params.port}`);
|
|
58
|
+
|
|
59
|
+
this.socket.on('connect', () => {
|
|
60
|
+
console.log(`Socket Client connected: ${this.params.name} (${this.params.port})`);
|
|
61
|
+
});
|
|
51
62
|
|
|
52
|
-
|
|
63
|
+
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
64
|
+
this.socket.on(event.eventType, async (content: any) => {
|
|
65
|
+
try {
|
|
66
|
+
await event.executeEventTasks(this.params.service, content);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
69
|
+
this.socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
53
72
|
});
|
|
73
|
+
this.socket.connect()
|
|
54
74
|
}
|
|
55
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Emit event to the socket
|
|
78
|
+
* @param event event name
|
|
79
|
+
* @param content event content
|
|
80
|
+
*/
|
|
56
81
|
protected emitEvent(event: string, content: any): void {
|
|
57
82
|
this.socket.emit(event, content);
|
|
58
83
|
}
|
|
@@ -45,7 +45,6 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
45
45
|
this.params = this.getServiceParams();
|
|
46
46
|
this.incomingEvents = this.getIncomingEvents() ?? [];
|
|
47
47
|
|
|
48
|
-
/* this.attachToGlobalCollection(); */
|
|
49
48
|
this.prepareEvents();
|
|
50
49
|
|
|
51
50
|
if (this.log) console.log(`Socket Controller setup done: ${this.params.name} (${this.params.port}) serurity: ${this.params.security}\n`);
|
|
@@ -54,27 +53,23 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
/* private attachToGlobalCollection(): void {
|
|
58
|
-
DynamoNTS_GlobalService.attachNewSocketService(this);
|
|
59
|
-
} */
|
|
60
|
-
|
|
61
56
|
/**
|
|
62
57
|
* You must setup events and required services for this function
|
|
63
58
|
*/
|
|
64
59
|
private prepareEvents(): void {
|
|
65
|
-
const connectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
60
|
+
const connectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventType === DynamoNTS_SocketEventType.connection);
|
|
66
61
|
if (0 <= connectEventIndex) {
|
|
67
62
|
this.connectEvent = this.incomingEvents.splice(connectEventIndex)[0];
|
|
68
63
|
} else {
|
|
69
64
|
this.connectEvent = new DynamoNTS_SocketEvent({
|
|
70
|
-
|
|
65
|
+
eventType: DynamoNTS_SocketEventType.connection,
|
|
71
66
|
tasks: []
|
|
72
67
|
});
|
|
73
68
|
}
|
|
74
69
|
this.connectEvent.socketName = this.params.name;
|
|
75
70
|
|
|
76
71
|
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
77
|
-
const subscriptionEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
72
|
+
const subscriptionEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventType === DynamoNTS_SocketEventType.subscribe);
|
|
78
73
|
if (0 <= subscriptionEventIndex) {
|
|
79
74
|
this.subscriptionEvent = this.incomingEvents.splice(subscriptionEventIndex)[0];
|
|
80
75
|
Dynamo_Log.error(
|
|
@@ -83,7 +78,7 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
83
78
|
);
|
|
84
79
|
} else {
|
|
85
80
|
this.subscriptionEvent = new DynamoNTS_SocketEvent<SocketIO.Socket>({
|
|
86
|
-
|
|
81
|
+
eventType: DynamoNTS_SocketEventType.subscribe
|
|
87
82
|
});
|
|
88
83
|
}
|
|
89
84
|
if (this.getSubscriptionPreProcessess) {
|
|
@@ -93,13 +88,13 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
93
88
|
this.subscriptionEvent.tasks.push(...this.getSubscriptionTasks());
|
|
94
89
|
}
|
|
95
90
|
|
|
96
|
-
const disconnectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
91
|
+
const disconnectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventType === DynamoNTS_SocketEventType.disconnect);
|
|
97
92
|
if (0 <= disconnectEventIndex) {
|
|
98
93
|
this.incomingEvents[disconnectEventIndex].tasks.push(this.removeSubscriptionOnDisconnect);
|
|
99
94
|
} else {
|
|
100
95
|
this.incomingEvents.push(
|
|
101
96
|
new DynamoNTS_SocketEvent<SocketIO.Socket>({
|
|
102
|
-
|
|
97
|
+
eventType: DynamoNTS_SocketEventType.disconnect,
|
|
103
98
|
tasks: [
|
|
104
99
|
this.removeSubscriptionOnDisconnect
|
|
105
100
|
]
|
|
@@ -107,10 +102,10 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
107
102
|
);
|
|
108
103
|
}
|
|
109
104
|
|
|
110
|
-
const errorEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.
|
|
105
|
+
const errorEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventType === DynamoNTS_SocketEventType.error);
|
|
111
106
|
if (errorEventIndex == -1 && this.errorHandling) {
|
|
112
107
|
this.incomingEvents.push(new DynamoNTS_SocketEvent<SocketIO.Socket>({
|
|
113
|
-
|
|
108
|
+
eventType: DynamoNTS_SocketEventType.error,
|
|
114
109
|
tasks: [
|
|
115
110
|
this.errorHandling
|
|
116
111
|
]
|
|
@@ -154,7 +149,7 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
154
149
|
}
|
|
155
150
|
|
|
156
151
|
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
157
|
-
socket.on(event.
|
|
152
|
+
socket.on(event.eventType, async (content: any) => {
|
|
158
153
|
try {
|
|
159
154
|
await event.executeEventTasks(issuer, content);
|
|
160
155
|
} catch (error) {
|
package/src/_services/index.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
// SERVICES
|
|
5
5
|
export * from './dynamo-nts-api.service';
|
|
6
|
-
export * from './dynamo-nts-app';
|
|
7
|
-
export * from './dynamo-nts-app-extended';
|
|
6
|
+
export * from './dynamo-nts-app.server';
|
|
7
|
+
export * from './dynamo-nts-app-extended.server';
|
|
8
8
|
export * from './dynamo-nts-auth.service';
|
|
9
9
|
export * from './dynamo-nts-controller.service';
|
|
10
10
|
export * from './dynamo-nts-data.service';
|
|
File without changes
|
|
File without changes
|