@futdevpro/nts-dynamo 1.6.3 → 1.6.5
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-event.model.d.ts +8 -15
- 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 +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-event.model.js.map +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-presence.model.d.ts +4 -8
- package/lib/_models/control-models/dynamo-nts-socket-presence.model.d.ts.map +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-presence.model.js +2 -0
- package/lib/_models/control-models/dynamo-nts-socket-presence.model.js.map +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-server-service-params.model.d.ts +2 -10
- package/lib/_models/control-models/dynamo-nts-socket-server-service-params.model.d.ts.map +1 -1
- package/lib/_models/control-models/dynamo-nts-socket-server-service-params.model.js +13 -11
- package/lib/_models/control-models/dynamo-nts-socket-server-service-params.model.js.map +1 -1
- package/lib/_services/dynamo-nts-socket-client.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket-client.service.js +5 -2
- package/lib/_services/dynamo-nts-socket-client.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket-server.service.d.ts +5 -5
- package/lib/_services/dynamo-nts-socket-server.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket-server.service.js +3 -3
- package/lib/_services/dynamo-nts-socket-server.service.js.map +1 -1
- package/lib/_services/index.d.ts +0 -1
- package/lib/_services/index.d.ts.map +1 -1
- package/lib/_services/index.js +0 -1
- 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-event.model.ts +9 -18
- package/src/_models/control-models/dynamo-nts-socket-presence.model.ts +4 -8
- package/src/_models/control-models/dynamo-nts-socket-server-service-params.model.ts +6 -13
- package/src/_services/dynamo-nts-socket-client.service.ts +5 -2
- package/src/_services/dynamo-nts-socket-server.service.ts +11 -11
- package/src/_services/index.ts +0 -1
- package/src/_services/dynamo-nts-socket-server-service-collection.service.ts +0 -16
|
@@ -7,15 +7,11 @@ import * as SocketIO from 'socket.io';
|
|
|
7
7
|
*/
|
|
8
8
|
export class DynamoNTS_SocketPresence {
|
|
9
9
|
issuerId: string;
|
|
10
|
-
sockets
|
|
11
|
-
onDestroy
|
|
10
|
+
sockets?: SocketIO.Socket[] = [];
|
|
11
|
+
onDestroy?: (issuerId: string) => void = id => {};
|
|
12
12
|
|
|
13
13
|
constructor(
|
|
14
|
-
set:
|
|
15
|
-
issuerId: string,
|
|
16
|
-
sockets: SocketIO.Socket[],
|
|
17
|
-
onDestroy?: (issuerId: string) => void,
|
|
18
|
-
}
|
|
14
|
+
set: DynamoNTS_SocketPresence
|
|
19
15
|
) {
|
|
20
16
|
if (!set?.issuerId) {
|
|
21
17
|
throw new Dynamo_Error({
|
|
@@ -48,7 +44,7 @@ export class DynamoNTS_SocketPresence {
|
|
|
48
44
|
* @param event
|
|
49
45
|
* @param content
|
|
50
46
|
*/
|
|
51
|
-
emitEvent(event: string, content: any) {
|
|
47
|
+
emitEvent?(event: string, content: any) {
|
|
52
48
|
this.sockets.forEach((socket: SocketIO.Socket) => {
|
|
53
49
|
socket.emit(event, content);
|
|
54
50
|
});
|
|
@@ -6,29 +6,22 @@ import { DynamoNTS_SocketSecurity } from '../../_enums/dynamo-nts-socket-securit
|
|
|
6
6
|
/**
|
|
7
7
|
* socket handling and clarification is under development
|
|
8
8
|
*/
|
|
9
|
-
export class DynamoNTS_SocketServerServiceParams {
|
|
9
|
+
export class DynamoNTS_SocketServerServiceParams<T = any> {
|
|
10
10
|
name: string;
|
|
11
11
|
port: number;
|
|
12
12
|
security?: DynamoNTS_SocketSecurity;
|
|
13
|
-
groupActiveSocketsBy?: string;
|
|
13
|
+
/* groupActiveSocketsBy?: string; */
|
|
14
14
|
|
|
15
|
-
getIdFromSubscrioption?: (content:
|
|
15
|
+
/* getIdFromSubscrioption?: (content: T) => Promise<string>; */
|
|
16
16
|
|
|
17
17
|
constructor(
|
|
18
|
-
set:
|
|
19
|
-
name: string,
|
|
20
|
-
port: number,
|
|
21
|
-
security?: DynamoNTS_SocketSecurity,
|
|
22
|
-
groupActiveSocketsBy?: string,
|
|
23
|
-
|
|
24
|
-
getIdFromSubscrioption?: (content: any) => string,
|
|
25
|
-
}
|
|
18
|
+
set: DynamoNTS_SocketServerServiceParams<T>
|
|
26
19
|
) {
|
|
27
20
|
this.name = set.name;
|
|
28
21
|
this.port = set.port;
|
|
29
22
|
this.security = set.security ? set.security : dynamoNTS_GlobalSettings.defaultSocketSecurity;
|
|
30
23
|
|
|
31
|
-
if (set.getIdFromSubscrioption) {
|
|
24
|
+
/* if (set.getIdFromSubscrioption) {
|
|
32
25
|
this.getIdFromSubscrioption = set.getIdFromSubscrioption;
|
|
33
26
|
|
|
34
27
|
if (set.groupActiveSocketsBy) {
|
|
@@ -38,6 +31,6 @@ export class DynamoNTS_SocketServerServiceParams {
|
|
|
38
31
|
}
|
|
39
32
|
} else if (set.groupActiveSocketsBy) {
|
|
40
33
|
this.getIdFromSubscrioption = content => content[set.groupActiveSocketsBy];
|
|
41
|
-
}
|
|
34
|
+
} */
|
|
42
35
|
}
|
|
43
36
|
}
|
|
@@ -96,9 +96,12 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
96
96
|
if (this.log) console.log(`Setup Socket Events... (${this.params.name})`);
|
|
97
97
|
|
|
98
98
|
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
99
|
+
if (!event.socketName) {
|
|
100
|
+
event.socketName = this.name;
|
|
101
|
+
}
|
|
99
102
|
this.socket.on(event.eventType, async (content: any) => {
|
|
100
103
|
try {
|
|
101
|
-
await event.executeEventTasks(this.params.service
|
|
104
|
+
await event.executeEventTasks(content, this.params.service);
|
|
102
105
|
} catch (error) {
|
|
103
106
|
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
104
107
|
this.emitEvent(DynamoNTS_SocketEventType.error, error);
|
|
@@ -108,7 +111,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
private connectSocket(): void {
|
|
111
|
-
console.log(`${this.params.name} Socket Client connecting to ${this.params.address}:${this.params.port}
|
|
114
|
+
console.log(`${this.params.name} Socket Client connecting to ${this.params.address}:${this.params.port} ...`);
|
|
112
115
|
|
|
113
116
|
this.socket.connect();
|
|
114
117
|
|
|
@@ -14,7 +14,7 @@ import { DynamoNTS_SocketEvent, DynamoNTS_SocketEventPreprocessTask, DynamoNTS_S
|
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
-
export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS_SocketPresence,
|
|
17
|
+
export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS_SocketPresence, T_SubscriptionContent = any, T_ErrorContent = any> extends DynamoNTS_SingletonService {
|
|
18
18
|
protected params: DynamoNTS_SocketServerServiceParams;
|
|
19
19
|
get name(): string { return this.params.name; }
|
|
20
20
|
get port(): number { return this.params.port; }
|
|
@@ -29,7 +29,7 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
29
29
|
/**
|
|
30
30
|
* You need to setup a function that converts subscription event content to presence
|
|
31
31
|
*/
|
|
32
|
-
protected getPresenceFromSubscrioptionEventContent?: (socketSubscription:
|
|
32
|
+
protected abstract getPresenceFromSubscrioptionEventContent?: (socketSubscription: T_SubscriptionContent, socket: SocketIO.Socket) => Promise<T_Presence>;
|
|
33
33
|
protected presences: T_Presence[] = [];
|
|
34
34
|
|
|
35
35
|
protected log: boolean = dynamoNTS_GlobalSettings.logSetup;
|
|
@@ -77,7 +77,7 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
77
77
|
`in case you need additional steps for your subscripotions.`
|
|
78
78
|
);
|
|
79
79
|
} else {
|
|
80
|
-
this.subscriptionEvent = new DynamoNTS_SocketEvent<
|
|
80
|
+
this.subscriptionEvent = new DynamoNTS_SocketEvent<T_SubscriptionContent>({
|
|
81
81
|
eventType: DynamoNTS_SocketEventType.subscribe
|
|
82
82
|
});
|
|
83
83
|
}
|
|
@@ -93,7 +93,7 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
93
93
|
this.incomingEvents[disconnectEventIndex].tasks.push(this.removeSubscriptionOnDisconnect);
|
|
94
94
|
} else {
|
|
95
95
|
this.incomingEvents.push(
|
|
96
|
-
new DynamoNTS_SocketEvent
|
|
96
|
+
new DynamoNTS_SocketEvent({
|
|
97
97
|
eventType: DynamoNTS_SocketEventType.disconnect,
|
|
98
98
|
tasks: [
|
|
99
99
|
this.removeSubscriptionOnDisconnect
|
|
@@ -104,7 +104,7 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
104
104
|
|
|
105
105
|
const errorEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventType === DynamoNTS_SocketEventType.error);
|
|
106
106
|
if (errorEventIndex == -1 && this.errorHandling) {
|
|
107
|
-
this.incomingEvents.push(new DynamoNTS_SocketEvent<
|
|
107
|
+
this.incomingEvents.push(new DynamoNTS_SocketEvent<T_ErrorContent>({
|
|
108
108
|
eventType: DynamoNTS_SocketEventType.error,
|
|
109
109
|
tasks: [
|
|
110
110
|
this.errorHandling
|
|
@@ -136,11 +136,11 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
136
136
|
if (this.getPresenceFromSubscrioptionEventContent) {
|
|
137
137
|
socket.on(DynamoNTS_SocketEventType.subscribe, async (content: any) => {
|
|
138
138
|
try {
|
|
139
|
-
const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content);
|
|
139
|
+
const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
|
|
140
140
|
issuer = presence.issuerId;
|
|
141
141
|
|
|
142
142
|
this.socketSubscription(presence);
|
|
143
|
-
await this.subscriptionEvent.executeEventTasks(
|
|
143
|
+
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
144
144
|
} catch (error) {
|
|
145
145
|
Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port})`, error);
|
|
146
146
|
socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
@@ -151,7 +151,7 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
151
151
|
this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
|
|
152
152
|
socket.on(event.eventType, async (content: any) => {
|
|
153
153
|
try {
|
|
154
|
-
await event.executeEventTasks(
|
|
154
|
+
await event.executeEventTasks(content, issuer);
|
|
155
155
|
} catch (error) {
|
|
156
156
|
Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
|
|
157
157
|
socket.emit(DynamoNTS_SocketEventType.error, error);
|
|
@@ -248,15 +248,15 @@ export abstract class DynamoNTS_SocketServerService<T_Presence extends DynamoNTS
|
|
|
248
248
|
/**
|
|
249
249
|
* You can setup tasks for the subscription event in this function
|
|
250
250
|
*/
|
|
251
|
-
protected getSubscriptionTasks?(): DynamoNTS_SocketEventTask[];
|
|
251
|
+
protected getSubscriptionTasks?(): DynamoNTS_SocketEventTask<T_SubscriptionContent>[];
|
|
252
252
|
|
|
253
253
|
/**
|
|
254
254
|
* You can setup preprocessess for the subscription event in this function
|
|
255
255
|
*/
|
|
256
|
-
protected getSubscriptionPreProcessess?(): DynamoNTS_SocketEventPreprocessTask
|
|
256
|
+
protected getSubscriptionPreProcessess?(): DynamoNTS_SocketEventPreprocessTask[];
|
|
257
257
|
|
|
258
258
|
/**
|
|
259
259
|
* You can setup tasks for the error event in this function
|
|
260
260
|
*/
|
|
261
|
-
protected errorHandling?: DynamoNTS_SocketEventTask
|
|
261
|
+
protected errorHandling?: DynamoNTS_SocketEventTask<T_ErrorContent>;
|
|
262
262
|
}
|
package/src/_services/index.ts
CHANGED
|
@@ -17,6 +17,5 @@ export * from './dynamo-nts-routing-module.service';
|
|
|
17
17
|
export * from './dynamo-nts-shared.service';
|
|
18
18
|
export * from './dynamo-nts-singleton.service';
|
|
19
19
|
export * from './dynamo-nts-socket-client.service';
|
|
20
|
-
export * from './dynamo-nts-socket-server-service-collection.service';
|
|
21
20
|
export * from './dynamo-nts-socket-server.service';
|
|
22
21
|
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { DynamoNTS_SingletonService } from './dynamo-nts-singleton.service';
|
|
3
|
-
import { DynamoNTS_SocketServerService } from './dynamo-nts-socket-server.service';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
/* export class DynamoNTS_SocketServiceCollection extends DynamoNTS_SingletonService {
|
|
9
|
-
|
|
10
|
-
static getInstance(): DynamoNTS_SocketServiceCollection {
|
|
11
|
-
return DynamoNTS_SocketServiceCollection.getSingletonInstance();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
[service: string]: DynamoNTS_SocketService<any>;
|
|
15
|
-
|
|
16
|
-
} */
|