@nsshunt/stsappframework 3.1.231 → 3.1.233
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/build.sh +0 -2
- package/dist/commonTypes.js +2 -38
- package/dist/commonTypes.js.map +1 -1
- package/dist/process/processbase.js.map +1 -1
- package/dist/process/serverprocessbase.js +39 -23
- package/dist/process/serverprocessbase.js.map +1 -1
- package/dist/process/singleprocessbase.js.map +1 -1
- package/dist/vitesttesting/appConfig.js +3 -1
- package/dist/vitesttesting/appConfig.js.map +1 -1
- package/dist/vitesttesting/appSingleWSS.js +100 -49
- package/dist/vitesttesting/appSingleWSS.js.map +1 -1
- package/dist/vitesttesting/singleservertest.test.js +155 -63
- package/dist/vitesttesting/singleservertest.test.js.map +1 -1
- package/package.json +4 -2
- package/src/commonTypes.ts +7 -85
- package/src/process/processbase.ts +5 -3
- package/src/process/serverprocessbase.ts +44 -23
- package/src/process/singleprocessbase.ts +1 -2
- package/src/vitesttesting/appConfig.ts +3 -1
- package/src/vitesttesting/appSingleWSS.ts +121 -58
- package/src/vitesttesting/singleservertest.test.ts +187 -70
- package/src/vitesttesting/wsevents.ts +12 -1
- package/types/commonTypes.d.ts +3 -54
- package/types/commonTypes.d.ts.map +1 -1
- package/types/process/processbase.d.ts +4 -2
- package/types/process/processbase.d.ts.map +1 -1
- package/types/process/serverprocessbase.d.ts +1 -1
- package/types/process/serverprocessbase.d.ts.map +1 -1
- package/types/process/singleprocessbase.d.ts.map +1 -1
- package/types/vitesttesting/appConfig.d.ts.map +1 -1
- package/types/vitesttesting/appSingleWSS.d.ts +2 -3
- package/types/vitesttesting/appSingleWSS.d.ts.map +1 -1
- package/types/vitesttesting/wsevents.d.ts +12 -1
- package/types/vitesttesting/wsevents.d.ts.map +1 -1
|
@@ -1,79 +1,142 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
|
|
4
|
-
import { SingleProcessBase,
|
|
5
|
-
import { SocketIoServerHelper } from '@nsshunt/
|
|
4
|
+
import { SingleProcessBase, ProcessOptions } from './../index'
|
|
5
|
+
import { SocketIoServerHelper, STSNamespace, STSRoom, InterServerEvents } from '@nsshunt/stssocketioutils'
|
|
6
6
|
|
|
7
|
-
import { Socket } from "socket.io";
|
|
8
|
-
|
|
9
|
-
import { InterServerEvents } from './../commonTypes'
|
|
7
|
+
import { Namespace, Socket } from "socket.io";
|
|
10
8
|
|
|
11
9
|
import { ClientToServerEvents, ServerToClientEvents } from './wsevents'
|
|
10
|
+
import { JSONObject } from '@nsshunt/stsutils';
|
|
12
11
|
|
|
13
12
|
export class AppSingleWSS extends SingleProcessBase
|
|
14
13
|
{
|
|
15
|
-
constructor(options: ProcessOptions)
|
|
16
|
-
{
|
|
14
|
+
constructor(options: ProcessOptions) {
|
|
17
15
|
super(options);
|
|
18
|
-
this.socketIoServerHelper = new SocketIoServerHelper<ClientToServerEvents, ServerToClientEvents>({
|
|
19
|
-
logger: this.options.logger
|
|
20
|
-
});
|
|
21
16
|
}
|
|
22
17
|
|
|
23
18
|
#LogInfoMessage(message: any) {
|
|
24
19
|
this.options.logger.info(message);
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
socket.
|
|
64
|
-
|
|
22
|
+
#SetupWSSServer = (namespace: STSNamespace) => {
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
this.socketIoServerHelper = new SocketIoServerHelper<ClientToServerEvents, ServerToClientEvents>({
|
|
27
|
+
logger: this.options.logger
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
//this.io?.of('/stsinstrumentmanager/stsmonitor/');
|
|
32
|
+
//return;
|
|
33
|
+
|
|
34
|
+
//this.socketIoServerHelper.SetupNamespaceEx(this.io as any, '/stsinstrumentmanager/stsmonitor/' as any);
|
|
35
|
+
//return;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
this.socketIoServerHelper.SetupNamespace(this.io as any, namespace,
|
|
39
|
+
// Auto joinn room list
|
|
40
|
+
[
|
|
41
|
+
STSRoom.STSInstrumentDataRoom,
|
|
42
|
+
STSRoom.STSRunnerRoom,
|
|
43
|
+
'room3'
|
|
44
|
+
],
|
|
45
|
+
true, // Make any connecting client automatically join the room list above
|
|
46
|
+
|
|
47
|
+
// Connect call back when a client connects
|
|
48
|
+
(socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => {
|
|
49
|
+
this.#LogInfoMessage(chalk.gray(`AppSingleWSS.#SetupWSSServer: Id: [${socket.id}] eventName: [connect]`));
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
// Custom client to server events
|
|
53
|
+
(socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => {
|
|
54
|
+
socket.on('subscribe', (data: any) => {
|
|
55
|
+
socket.emit('subscribeAck', data);
|
|
56
|
+
});
|
|
57
|
+
socket.on('unsubscribe', (data: any) => {
|
|
58
|
+
socket.emit('unsubscribeAck', data);
|
|
59
|
+
});
|
|
60
|
+
socket.on('subscribeKeepAlive', (data: any) => {
|
|
61
|
+
socket.emit('subscribeKeepAliveAck', data);
|
|
62
|
+
});
|
|
63
|
+
socket.on('done', () => {
|
|
64
|
+
socket.emit('doneAck');
|
|
65
|
+
});
|
|
66
|
+
socket.on('compute', (arg: number, cb) => {
|
|
67
|
+
const res = arg * 2;
|
|
68
|
+
cb(res.toString());
|
|
69
|
+
});
|
|
70
|
+
socket.on('compute2', (arg, cb) => {
|
|
71
|
+
cb({data: arg*2});
|
|
72
|
+
});
|
|
73
|
+
socket.on('broadcast', () => {
|
|
74
|
+
|
|
75
|
+
if (this.socketIoServerHelper) {
|
|
76
|
+
const namespaceIo = this.socketIoServerHelper
|
|
77
|
+
.GetSTSSocketIONamespace(namespace).socketionamespace as Namespace<ClientToServerEvents, ServerToClientEvents, InterServerEvents>
|
|
78
|
+
|
|
79
|
+
namespaceIo.to("room3").timeout(5000).emit("compute3", 10, (err: Error, data: JSONObject[]) => {
|
|
80
|
+
if (err) {
|
|
81
|
+
console.log(`room3 broadcast: [${chalk.red(JSON.stringify(err))}]`)
|
|
82
|
+
} else {
|
|
83
|
+
console.log(`room3 broadcast: [${chalk.blue(JSON.stringify(data))}]`)
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
socket.on('__STSsendToRoomWithCB', (rooms: string[], payload: { command: string, payload: JSONObject }): void => {
|
|
90
|
+
rooms.forEach((room) => {
|
|
91
|
+
//this.LogMessage(namespace, `${namespace.socketionamespace.name}:socket.on:sendToRoom: __STSsendToRoom: Sending to room [${room}], ID: [${socket.id}]`);
|
|
92
|
+
|
|
93
|
+
if (this.socketIoServerHelper) {
|
|
94
|
+
const namespaceIo = this.socketIoServerHelper
|
|
95
|
+
.GetSTSSocketIONamespace(namespace).socketionamespace as Namespace<ClientToServerEvents, ServerToClientEvents, InterServerEvents>
|
|
96
|
+
|
|
97
|
+
namespaceIo.to(room).timeout(5000).emit(payload.command as any, payload, (err: Error, data: JSONObject[]) => {
|
|
98
|
+
if (err) {
|
|
99
|
+
console.error(err);
|
|
100
|
+
console.log(`__STSsendToRoomWithCB broadcast: [${chalk.red(JSON.stringify(err))}]`)
|
|
101
|
+
} else {
|
|
102
|
+
console.log(`__STSsendToRoomWithCB broadcast: [${chalk.blue(JSON.stringify(data))}]`)
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
65
106
|
});
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
socket.on('GetThreadDetails', (inputThreaddata: JSONObject, cb: (data: JSONObject) => void) => {
|
|
110
|
+
if (this.socketIoServerHelper) {
|
|
111
|
+
const namespaceIo = this.socketIoServerHelper
|
|
112
|
+
.GetSTSSocketIONamespace(namespace).socketionamespace as Namespace<ClientToServerEvents, ServerToClientEvents, InterServerEvents>
|
|
113
|
+
|
|
114
|
+
namespaceIo.to(inputThreaddata.room).timeout(5000).emit('GetThreadDetailsFromService', { data: inputThreaddata }, (err: Error, data: JSONObject[]) => {
|
|
115
|
+
if (err) {
|
|
116
|
+
console.error(err);
|
|
117
|
+
console.log(`__STSsendToRoomWithCB broadcast: [${chalk.red(JSON.stringify(err))}]`)
|
|
118
|
+
} else {
|
|
119
|
+
console.log(`__STSsendToRoomWithCB broadcast: [${chalk.blue(JSON.stringify(data))}]`)
|
|
120
|
+
cb(data);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
})
|
|
71
126
|
}
|
|
127
|
+
|
|
128
|
+
override ProcessStarted() {
|
|
129
|
+
super.ProcessStarted();
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
const nsp = this.io?.of('/stsinstrumentmanager/stsmonitor');
|
|
133
|
+
nsp?.on("connection", socket => {
|
|
134
|
+
|
|
135
|
+
});
|
|
136
|
+
this.#SetupConnectionMiddleware(nsp);
|
|
137
|
+
*/
|
|
72
138
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return this.socketIoServerHelper.GetSTSSocketIONamespace(STSNamespace.STSMonitor);
|
|
76
|
-
}
|
|
77
|
-
return null;
|
|
139
|
+
this.#SetupWSSServer(STSNamespace.STSMonitor);
|
|
140
|
+
//this.#SetupWSSServer('stsinstrumentmanager/stsmonitor' as any);
|
|
78
141
|
}
|
|
79
142
|
}
|
|
@@ -3,7 +3,7 @@ import chalk from 'chalk';
|
|
|
3
3
|
|
|
4
4
|
import axios, { AxiosError, AxiosResponse } from 'axios';
|
|
5
5
|
|
|
6
|
-
import { Sleep } from '@nsshunt/stsutils'
|
|
6
|
+
import { JSONObject, Sleep } from '@nsshunt/stsutils'
|
|
7
7
|
//import { SingleProcessBase, MasterProcessBase } from './..'
|
|
8
8
|
|
|
9
9
|
import { AppSingleWSS } from './appSingleWSS'
|
|
@@ -14,22 +14,23 @@ import { goptions, $ResetOptions, STSAxiosConfig, AgentManager } from '@nsshunt/
|
|
|
14
14
|
|
|
15
15
|
import { beforeAll, afterAll, test, describe, expect } from 'vitest';
|
|
16
16
|
|
|
17
|
-
import { SocketIoClientHelper, ISocketIoClientHelperOptions } from '@nsshunt/
|
|
17
|
+
import { SocketIoClientHelper, ISocketIoClientHelperOptions } from '@nsshunt/stssocketioutils'
|
|
18
18
|
|
|
19
|
-
import { STSNamespace } from '
|
|
19
|
+
import { STSNamespace } from '@nsshunt/stssocketioutils'
|
|
20
20
|
|
|
21
21
|
import { ServerToClientEvents, ClientToServerEvents } from './wsevents'
|
|
22
22
|
import { Socket } from 'socket.io-client'
|
|
23
23
|
|
|
24
24
|
//import { GenericContainer, Network, Wait } from "testcontainers";
|
|
25
|
-
import { GenericContainer } from "testcontainers";
|
|
25
|
+
import { GenericContainer, Network } from "testcontainers";
|
|
26
26
|
|
|
27
27
|
describe("Single Server Test", () =>
|
|
28
28
|
{
|
|
29
29
|
let app: AppSingleWSS | null = null;
|
|
30
30
|
let ioRedisMessageProcessorUrl = '';
|
|
31
31
|
let ioRedisContainer: any = null;
|
|
32
|
-
|
|
32
|
+
let network: any;
|
|
33
|
+
|
|
33
34
|
const agentManager = new AgentManager({});
|
|
34
35
|
|
|
35
36
|
const endpoint = 'https://localhost'
|
|
@@ -92,14 +93,22 @@ describe("Single Server Test", () =>
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
const StartNetwork = async () => {
|
|
97
|
+
network = await new Network().start();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const StopNetwork = async () => {
|
|
101
|
+
await network.stop();
|
|
102
|
+
}
|
|
103
|
+
|
|
95
104
|
const StartRedis = async () => {
|
|
96
105
|
ioRedisContainer = await new GenericContainer("redis/redis-stack-server")
|
|
97
106
|
.withEnvironment({
|
|
98
107
|
REDIS_ARGS: "--save \"\" --appendonly no",
|
|
99
108
|
})
|
|
100
109
|
.withExposedPorts(6379)
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
.withNetwork(network)
|
|
111
|
+
.withNetworkAliases("redisstackserver")
|
|
103
112
|
//.withWaitStrategy(Wait.forLogMessage(`Ready to accept connections tcp`))
|
|
104
113
|
.start();
|
|
105
114
|
|
|
@@ -109,7 +118,7 @@ describe("Single Server Test", () =>
|
|
|
109
118
|
//expect(goptions.imRedisMessageProcessorUrl).toEqual('redis://localhost:6379');
|
|
110
119
|
// IM_REDIS_MESSAGE_PROCESSOR_URL
|
|
111
120
|
|
|
112
|
-
console.log(chalk.green(`redis/redis-stack-server Started.
|
|
121
|
+
console.log(chalk.green(`redis/redis-stack-server Started. docker [${ioRedisMessageProcessorUrl}]`));
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
const StopRedis = async () => {
|
|
@@ -119,10 +128,12 @@ describe("Single Server Test", () =>
|
|
|
119
128
|
|
|
120
129
|
beforeAll(async () => {
|
|
121
130
|
|
|
131
|
+
await StartNetwork();
|
|
122
132
|
await StartRedis();
|
|
123
133
|
|
|
124
134
|
process.env.IM_REDIS_MESSAGE_PROCESSOR_URL = ioRedisMessageProcessorUrl;
|
|
125
|
-
|
|
135
|
+
process.env.SOCKET_IO_REDIS_ADAPTOR_URL = ioRedisMessageProcessorUrl;
|
|
136
|
+
|
|
126
137
|
$ResetOptions();
|
|
127
138
|
|
|
128
139
|
const appOptions = ServiceConfigOptions(false, true);
|
|
@@ -136,10 +147,15 @@ describe("Single Server Test", () =>
|
|
|
136
147
|
agentManager.Terminate();
|
|
137
148
|
await Sleep(500);
|
|
138
149
|
await app?.TerminateApplication();
|
|
139
|
-
|
|
150
|
+
|
|
151
|
+
await Sleep(2000);
|
|
152
|
+
|
|
140
153
|
app = null;
|
|
141
154
|
|
|
142
155
|
await StopRedis();
|
|
156
|
+
await StopNetwork();
|
|
157
|
+
|
|
158
|
+
await Sleep(2000);
|
|
143
159
|
}, 120000);
|
|
144
160
|
|
|
145
161
|
test('Testing Module', async () => {
|
|
@@ -159,77 +175,178 @@ describe("Single Server Test", () =>
|
|
|
159
175
|
}, 10000);
|
|
160
176
|
|
|
161
177
|
test('client socket testing', async () => {
|
|
162
|
-
expect.assertions(
|
|
163
|
-
|
|
164
|
-
let
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
socket
|
|
178
|
-
LogDebugMessage(chalk.
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
socket.on('unsubscribeAck', (data: any) => {
|
|
182
|
-
LogDebugMessage(chalk.yellow('unsubscribeAck'));
|
|
183
|
-
expect(data.data).toMatch(/(subject02)/i);
|
|
184
|
-
});
|
|
185
|
-
socket.on('subscribeKeepAliveAck', (data: any) => {
|
|
186
|
-
LogDebugMessage(chalk.yellow('subscribeKeepAliveAck'));
|
|
187
|
-
expect(data.data).toMatch(/(ok)/i);
|
|
188
|
-
});
|
|
189
|
-
socket.on('doneAck', async () => {
|
|
190
|
-
LogDebugMessage(chalk.yellow('doneAck'));
|
|
178
|
+
expect.assertions(29);
|
|
179
|
+
|
|
180
|
+
let connectCount = 0;
|
|
181
|
+
let subscribeAckCount = 0;
|
|
182
|
+
let unsubscribeAckCount = 0;
|
|
183
|
+
let subscribeKeepAliveAckCount = 0;
|
|
184
|
+
let doneAckCount = 0;
|
|
185
|
+
|
|
186
|
+
const SetupClient = async (clientName: string, joinRooms: string[]): Promise<Socket<ServerToClientEvents, ClientToServerEvents>> => {
|
|
187
|
+
|
|
188
|
+
const socket = socketUtils.SetupClientSideSocket('STSUITerm',
|
|
189
|
+
// The address defines the namespace to connect to (i.e. io.of('/address'))
|
|
190
|
+
instrumentManagerAddress,
|
|
191
|
+
// Connected call back
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
193
|
+
(socket: Socket<ServerToClientEvents, ClientToServerEvents>) => {
|
|
194
|
+
LogDebugMessage(chalk.green(`${clientName}: connected - 1`));
|
|
195
|
+
connectCount++;
|
|
191
196
|
expect(1).toEqual(1);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
},
|
|
198
|
+
// Custom Events
|
|
199
|
+
(socket: Socket<ServerToClientEvents, ClientToServerEvents>) => {
|
|
200
|
+
socket.on('subscribeAck', (data: any) => {
|
|
201
|
+
LogDebugMessage(chalk.yellow(`${clientName}: subscribeAck`));
|
|
202
|
+
subscribeAckCount++;
|
|
203
|
+
expect(data.data).toMatch(/(subject01|subject02)/i);
|
|
204
|
+
});
|
|
205
|
+
socket.on('unsubscribeAck', (data: any) => {
|
|
206
|
+
unsubscribeAckCount++;
|
|
207
|
+
LogDebugMessage(chalk.yellow(`${clientName}: unsubscribeAck`));
|
|
208
|
+
expect(data.data).toMatch(/(subject02)/i);
|
|
209
|
+
});
|
|
210
|
+
socket.on('subscribeKeepAliveAck', (data: any) => {
|
|
211
|
+
subscribeKeepAliveAckCount++;
|
|
212
|
+
LogDebugMessage(chalk.yellow(`${clientName}: subscribeKeepAliveAck`));
|
|
213
|
+
expect(data.data).toMatch(/(ok)/i);
|
|
214
|
+
});
|
|
215
|
+
socket.on('doneAck', async () => {
|
|
216
|
+
doneAckCount++;
|
|
217
|
+
LogDebugMessage(chalk.yellow(`${clientName}: doneAck`));
|
|
218
|
+
expect(1).toEqual(1);
|
|
219
|
+
});
|
|
220
|
+
socket.on('compute3', async (arg: number, cb) => {
|
|
221
|
+
LogDebugMessage(chalk.yellow(`${clientName}: compute3`));
|
|
222
|
+
cb({arg, clientName});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
socket.on('ServiceCommandGetThreads', async (arg) => {
|
|
226
|
+
LogDebugMessage(chalk.yellow(`${clientName}: ServiceCommandGetThreads: [${JSON.stringify(arg)}]`));
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
socket.on('ServiceCommandGetThreadsEx', async (arg: any, cb) => {
|
|
230
|
+
LogDebugMessage(chalk.green(`${clientName}: ServiceCommandGetThreadsEx: [${JSON.stringify(arg)}]`));
|
|
231
|
+
cb({arg, clientName});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
socket.on('GetThreadDetailsFromService', async (arg: any, cb) => {
|
|
235
|
+
LogDebugMessage(chalk.green(`${clientName}: ServiceCommandGetThreadsEx: [${JSON.stringify(arg)}]`));
|
|
236
|
+
cb({
|
|
237
|
+
threadData: { id: 'someid', extraData: 'someextradata' },
|
|
238
|
+
arg,
|
|
239
|
+
clientName
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
},
|
|
244
|
+
(error: Error) => {
|
|
245
|
+
LogErrorMessage(`${clientName}: SetupClientSideSocket call back: [${error}]`);
|
|
246
|
+
}
|
|
247
|
+
)
|
|
200
248
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
socket.emit('subscribe', { data: 'subject01 '});
|
|
204
|
-
socket.emit('subscribe', { data: 'subject02 '});
|
|
249
|
+
socket.emit('__STSjoinRoom', joinRooms);
|
|
205
250
|
|
|
206
|
-
|
|
251
|
+
socket.emit('__STSjoinRoom', ['room1']).emit('__STSjoinRoom', ['room2']);
|
|
207
252
|
|
|
208
|
-
|
|
253
|
+
socket.emit('subscribe', { data: 'subject01 '});
|
|
254
|
+
socket.emit('subscribe', { data: 'subject02 '});
|
|
209
255
|
|
|
210
|
-
|
|
211
|
-
//socket.emit('done');
|
|
256
|
+
socket.emit('unsubscribe', { data: 'subject02 '});
|
|
212
257
|
|
|
213
|
-
|
|
214
|
-
if (err) {
|
|
215
|
-
LogInfoMessage(err);
|
|
216
|
-
} else {
|
|
217
|
-
expect(arg).toEqual('20');
|
|
218
|
-
}
|
|
219
|
-
});
|
|
258
|
+
socket.emit('subscribeKeepAlive', { data: 'ok'});
|
|
220
259
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
260
|
+
socket.timeout(250).emit('compute', 10, (err, arg) => {
|
|
261
|
+
if (err) {
|
|
262
|
+
LogInfoMessage(err);
|
|
263
|
+
} else {
|
|
264
|
+
console.log(`${clientName}: compute: [${chalk.magenta(JSON.stringify(arg))}]`)
|
|
265
|
+
expect(arg).toEqual('20');
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
socket.timeout(250).emit('compute2', 10, (err, arg) => {
|
|
270
|
+
if (err) {
|
|
271
|
+
LogInfoMessage(err);
|
|
272
|
+
} else {
|
|
273
|
+
console.log(`${clientName}: compute2: [${chalk.magenta(JSON.stringify(arg))}]`)
|
|
274
|
+
expect(arg.data).toEqual(20);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
return socket;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const client1 = await SetupClient('client1', [ 'service' ]);
|
|
282
|
+
const client2 = await SetupClient('client2', [ 'service', 'service_instance1' ]);
|
|
283
|
+
const client3 = await SetupClient('client3', [ 'service', 'service_instance2' ]);
|
|
284
|
+
|
|
285
|
+
await Sleep(1000);
|
|
286
|
+
|
|
287
|
+
//client1.emit('broadcast');
|
|
288
|
+
|
|
289
|
+
//client2.emit('__STSsendToRoom', ['service'], { command: 'ServiceCommandGetThreads', payload: { room: 'service', somedata: 1 }});
|
|
290
|
+
|
|
291
|
+
client2.emit('__STSsendToRoomWithCB',
|
|
292
|
+
['service_instance1'],
|
|
293
|
+
{ command: 'ServiceCommandGetThreadsEx', payload: { room: 'service_instance1', somedata: 1 } }
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
client3.emit('GetThreadDetails', {
|
|
297
|
+
room: 'service_instance1',
|
|
298
|
+
threadInput: 500
|
|
299
|
+
}, (data: JSONObject) => {
|
|
300
|
+
console.log(chalk.magenta(JSON.stringify(data)))
|
|
227
301
|
});
|
|
228
302
|
|
|
229
|
-
|
|
303
|
+
const start = performance.now();
|
|
304
|
+
const promArray: Promise<JSONObject>[] = [ ];
|
|
305
|
+
for (let i=0; i < 20; i++) {
|
|
306
|
+
const prom = new Promise<JSONObject>((res, rej) => {
|
|
307
|
+
try {
|
|
308
|
+
client1.emit('GetThreadDetails', {
|
|
309
|
+
room: 'service',
|
|
310
|
+
threadInput: 500,
|
|
311
|
+
iteration: i
|
|
312
|
+
}, (data: JSONObject) => {
|
|
313
|
+
console.log(chalk.rgb(100, 240, 20)(JSON.stringify(data)))
|
|
314
|
+
res(data);
|
|
315
|
+
});
|
|
316
|
+
} catch (error) {
|
|
317
|
+
rej(error);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
promArray.push(prom);
|
|
321
|
+
}
|
|
322
|
+
await Promise.all(promArray);
|
|
323
|
+
const end = performance.now();
|
|
324
|
+
console.log(chalk.magenta(`Total Time: [${end-start}]`));
|
|
325
|
+
|
|
326
|
+
await Sleep(1000);
|
|
327
|
+
|
|
328
|
+
client1.emit('__STSsendToRoom', ['room3'], { command: 'doneAck', payload: { somedata: 1 }})
|
|
329
|
+
|
|
330
|
+
//while (!complete) {
|
|
331
|
+
while (doneAckCount < 3) {
|
|
230
332
|
await Sleep(100);
|
|
231
333
|
}
|
|
334
|
+
await Sleep(500);
|
|
335
|
+
|
|
336
|
+
console.log(chalk.green(`connectCount: [${connectCount}]`));
|
|
337
|
+
console.log(chalk.green(`subscribeAckCount: [${subscribeAckCount}]`));
|
|
338
|
+
console.log(chalk.green(`unsubscribeAckCount: [${unsubscribeAckCount}]`));
|
|
339
|
+
console.log(chalk.green(`subscribeKeepAliveAckCount: [${subscribeKeepAliveAckCount}]`));
|
|
340
|
+
console.log(chalk.green(`doneAckCount: [${doneAckCount}]`));
|
|
341
|
+
|
|
342
|
+
expect(connectCount).toEqual(3);
|
|
343
|
+
expect(subscribeAckCount).toEqual(6);
|
|
344
|
+
expect(unsubscribeAckCount).toEqual(3);
|
|
345
|
+
expect(subscribeKeepAliveAckCount).toEqual(3);
|
|
346
|
+
expect(doneAckCount).toEqual(3);
|
|
347
|
+
|
|
348
|
+
console.log(chalk.green(`All Done...`));
|
|
232
349
|
|
|
233
|
-
},
|
|
350
|
+
}, 60000);
|
|
234
351
|
});
|
|
235
352
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
-
import { STSDefaultServerToClientEvents, STSDefaultClientToServerEvents } from '@nsshunt/
|
|
2
|
+
import { STSDefaultServerToClientEvents, STSDefaultClientToServerEvents } from '@nsshunt/stssocketioutils'
|
|
3
|
+
import { JSONObject } from '@nsshunt/stsutils';
|
|
3
4
|
|
|
4
5
|
// Syntax sugar from socket.io
|
|
5
6
|
// https://socket.io/docs/v4/typescript/#emitting-with-a-timeout
|
|
@@ -17,6 +18,11 @@ export interface ServerToClientEvents extends STSDefaultServerToClientEvents {
|
|
|
17
18
|
unsubscribeAck: (data: any) => void;
|
|
18
19
|
subscribeKeepAliveAck: (data: any) => void;
|
|
19
20
|
doneAck: () => void;
|
|
21
|
+
compute3: (arg: number, callback: (data: JSONObject) => void) => void;
|
|
22
|
+
ServiceCommandGetThreads: (data: any) => void;
|
|
23
|
+
ServiceCommandGetThreadsEx: (data: any, callback: (data: JSONObject) => void) => void;
|
|
24
|
+
|
|
25
|
+
GetThreadDetailsFromService: (data: any, callback: (data: JSONObject) => void) => void;
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
//export interface ClientToServerEvents<isSender extends boolean = false> extends STSClientToServerEvents {
|
|
@@ -30,4 +36,9 @@ export interface ClientToServerEvents extends STSDefaultClientToServerEvents {
|
|
|
30
36
|
//compute2: (arg: number, callback: (...args: WithTimeoutAck<isSender, [{ data: any}]>) => void) => void;
|
|
31
37
|
compute: (arg: number, callback: (data: string) => void) => void;
|
|
32
38
|
compute2: (arg: number, callback: (data: { data: any}) => void) => void;
|
|
39
|
+
broadcast: () => void;
|
|
40
|
+
|
|
41
|
+
GetThreadDetails: (arg: JSONObject, callback: (data: JSONObject) => void) => void;
|
|
42
|
+
|
|
43
|
+
__STSsendToRoomWithCB: (rooms: string[], payload: { command: string, payload: any }) => void;
|
|
33
44
|
}
|
package/types/commonTypes.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Server, Socket, Namespace } from "socket.io";
|
|
2
1
|
import express from 'express';
|
|
3
2
|
import { JSONObject, ISTSLogger } from "@nsshunt/stsutils";
|
|
4
|
-
import { PublishInstrumentController, InstrumentDefinitions, IContextBase, InstrumentBaseTelemetry, Gauge
|
|
3
|
+
import { PublishInstrumentController, InstrumentDefinitions, IContextBase, InstrumentBaseTelemetry, Gauge } from '@nsshunt/stsobservability';
|
|
4
|
+
import { STSDefaultClientToServerEvents, STSDefaultServerToClientEvents } from '@nsshunt/stssocketioutils';
|
|
5
5
|
import { IDBAccessLayer } from '@nsshunt/stsdatamanagement';
|
|
6
6
|
import { TinyEmitter } from "tiny-emitter";
|
|
7
7
|
import { Worker, Address } from 'node:cluster';
|
|
8
|
+
import { ISocketIoServerHelper } from '@nsshunt/stssocketioutils';
|
|
8
9
|
export interface IServiceProcessContext extends IContextBase {
|
|
9
10
|
serviceId?: string;
|
|
10
11
|
serviceInstanceId?: string;
|
|
@@ -109,58 +110,6 @@ export interface IWorkerProcessBase extends IServerProcessBase {
|
|
|
109
110
|
DeleteWorker: (workerId: string, options: any) => Promise<JSONObject>;
|
|
110
111
|
GetMasterProcessOptions: () => Promise<JSONObject>;
|
|
111
112
|
}
|
|
112
|
-
export type ServerEventCb = (socket: any, data: any) => void;
|
|
113
|
-
export interface ServerSocketEvent {
|
|
114
|
-
serverEventName: string;
|
|
115
|
-
serverEventCb: ServerEventCb;
|
|
116
|
-
}
|
|
117
|
-
export declare enum STSNamespace {
|
|
118
|
-
STSMonitor = "stsinstrumentmanager/stsmonitor",
|
|
119
|
-
STSControl = "stsinstrumentmanager/stscontrol"
|
|
120
|
-
}
|
|
121
|
-
export declare enum STSRoom {
|
|
122
|
-
STSInstrumentDataRoom = "stsinstrumentdataroom",// This room is for all instrument data messages
|
|
123
|
-
STSInstrumentDataSubscriptionRoom = "stsinstrumentdatasubscriptionroom",// This room is only for subscribed instrument data messages
|
|
124
|
-
STSRunnerRoom = "stsrunnerroom",
|
|
125
|
-
STSNodeRunnerRoom = "stsnoderunnerroom"
|
|
126
|
-
}
|
|
127
|
-
export declare enum STSEvent {
|
|
128
|
-
STSInstrumentData = "stsinstrumentdata",
|
|
129
|
-
STSSubInstrumentData = "stssubinstrumentdata",// sub-scribed instrument data. This only outputs the nodes that have been subscribed by the client(s).
|
|
130
|
-
STSResetInstrumentData = "stsresetinstrumentdata",
|
|
131
|
-
STSStartLoggingInstrumentData = "stsStartLoggingInstrumentData",
|
|
132
|
-
STSStopLoggingInstrumentData = "stsStopLoggingInstrumentData",
|
|
133
|
-
STSStart = "stsstart",// Start a test run with options as payload.
|
|
134
|
-
STSStop = "stsstop",// Stop test run(s).
|
|
135
|
-
STSPause = "stspause",// Pause test run(s).
|
|
136
|
-
STSResume = "stsresume",// Resume test run(s).
|
|
137
|
-
STSTerminate = "ststerminate",// Terminate runner instances and exit applications.
|
|
138
|
-
STSUpdateStaticConfig = "stsupdatestaticconfig",// Update base configuration. Options as payload.
|
|
139
|
-
STSUpdateDynamicConfig = "stsupdatedynamicconfig",// Update running configuration. This is used
|
|
140
|
-
STSSendToRoom = "sendToRoom",
|
|
141
|
-
connect = "connect"
|
|
142
|
-
}
|
|
143
|
-
export interface InterServerEvents {
|
|
144
|
-
ping: () => void;
|
|
145
|
-
}
|
|
146
|
-
export interface STSSocketIONamespace {
|
|
147
|
-
namespace: string;
|
|
148
|
-
pid: number;
|
|
149
|
-
socketionamespace: Namespace<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents, InterServerEvents>;
|
|
150
|
-
}
|
|
151
|
-
export type STSSocketIONamespaces = Record<string, STSSocketIONamespace>;
|
|
152
|
-
export type STSServerSocket = Socket<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents, InterServerEvents>;
|
|
153
|
-
export type STSClientSocket = Socket<STSDefaultServerToClientEvents, STSDefaultClientToServerEvents, InterServerEvents>;
|
|
154
|
-
export interface ISocketIoServerHelper<ClientToServerEvents extends STSDefaultClientToServerEvents, ServerToClientEvents extends STSDefaultServerToClientEvents> {
|
|
155
|
-
LogMessage: (namespace: STSSocketIONamespace, message: string) => void;
|
|
156
|
-
LeaveRoom: (namespace: STSSocketIONamespace, socket: STSServerSocket, room: STSRoom) => void;
|
|
157
|
-
JoinRoom: (namespace: STSSocketIONamespace, socket: STSServerSocket, room: STSRoom) => void;
|
|
158
|
-
SetupNamespace: (io: Server, namespace: STSNamespace, rooms: string[], autoJoinRooms: boolean, socketConnectCallBack: ((socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => void) | null, socketEventsCallBack: ((socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => void) | null) => Namespace<ClientToServerEvents, ServerToClientEvents, InterServerEvents>;
|
|
159
|
-
GetSTSSocketIONamespace: (namespace: any) => STSSocketIONamespace;
|
|
160
|
-
GetSTSSocketIONamespaces: () => STSSocketIONamespaces;
|
|
161
|
-
DisconnectSockets: () => void;
|
|
162
|
-
SetupEvent(event: ClientToServerEvents, eventCb: ServerEventCb): ISocketIoServerHelper<ClientToServerEvents, ServerToClientEvents>;
|
|
163
|
-
}
|
|
164
113
|
export declare const iss = "https://stscore.stsmda.org/oauth2/v2.0";
|
|
165
114
|
export interface STSExpressServer {
|
|
166
115
|
get App(): express.Express;
|