@nsshunt/stssocketioutils 1.1.30 → 1.1.32
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/dist/stssocketioutils.mjs +211 -233
- package/dist/stssocketioutils.mjs.map +1 -1
- package/dist/stssocketioutils.umd.js +214 -236
- package/dist/stssocketioutils.umd.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __typeError = (msg) => {
|
|
3
|
-
throw TypeError(msg);
|
|
4
|
-
};
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
8
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
12
|
-
var _options, _sockets, _SocketIoClientHelper_instances, LogDebugMessage_fn, LogErrorMessage_fn, EstablishSocketConnect_fn, _socketIoServerHelperOptions, _namespace, _SetupStandardEvents, _SetupConnectionMiddleware, _SetupMessageMiddleware;
|
|
13
1
|
import { io } from "socket.io-client";
|
|
14
2
|
var STSNamespace = /* @__PURE__ */ ((STSNamespace2) => {
|
|
15
3
|
STSNamespace2["STSMonitor"] = "stsinstrumentmanager/stsmonitor";
|
|
@@ -43,14 +31,21 @@ var STSEvent = /* @__PURE__ */ ((STSEvent2) => {
|
|
|
43
31
|
})(STSEvent || {});
|
|
44
32
|
const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
45
33
|
class SocketIoClientHelper {
|
|
34
|
+
#options;
|
|
35
|
+
#sockets = {};
|
|
46
36
|
constructor(options) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
this.#options = options;
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
#LogDebugMessage(message) {
|
|
41
|
+
if (this.#options.logger) this.#options.logger.debug(message);
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
#LogErrorMessage(message) {
|
|
45
|
+
if (this.#options.logger) this.#options.logger.error(message);
|
|
51
46
|
}
|
|
52
47
|
get sockets() {
|
|
53
|
-
return
|
|
48
|
+
return this.#sockets;
|
|
54
49
|
}
|
|
55
50
|
SetupClientSideSocket(name, address, socketIoCustomPath, onConnectCallBack, socketEventsCallBack, errorCallBack) {
|
|
56
51
|
this.sockets[name] = {
|
|
@@ -59,7 +54,7 @@ class SocketIoClientHelper {
|
|
|
59
54
|
socket: null,
|
|
60
55
|
errorCallBack
|
|
61
56
|
};
|
|
62
|
-
|
|
57
|
+
this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack);
|
|
63
58
|
return this.sockets[name].socket;
|
|
64
59
|
}
|
|
65
60
|
GetSocket(name) {
|
|
@@ -68,252 +63,235 @@ class SocketIoClientHelper {
|
|
|
68
63
|
GetSocketDetail(name) {
|
|
69
64
|
return this.sockets[name];
|
|
70
65
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const socketDetail = this.sockets[name];
|
|
85
|
-
if (socketDetail.socket !== null) {
|
|
86
|
-
if (socketDetail.socket.connected === true) {
|
|
87
|
-
socketDetail.socket.disconnect();
|
|
66
|
+
#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack) {
|
|
67
|
+
const socketDetail = this.sockets[name];
|
|
68
|
+
if (socketDetail.socket !== null) {
|
|
69
|
+
if (socketDetail.socket.connected === true) {
|
|
70
|
+
socketDetail.socket.disconnect();
|
|
71
|
+
}
|
|
72
|
+
socketDetail.socket = null;
|
|
73
|
+
if (isNode) {
|
|
74
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
75
|
+
} else {
|
|
76
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
88
79
|
}
|
|
89
|
-
|
|
80
|
+
let socketOptions;
|
|
90
81
|
if (isNode) {
|
|
91
|
-
|
|
82
|
+
socketOptions = {
|
|
83
|
+
transports: ["websocket"]
|
|
84
|
+
};
|
|
85
|
+
if (this.#options.agentManager) {
|
|
86
|
+
socketOptions.agent = this.#options.agentManager.GetAgent(socketDetail.address);
|
|
87
|
+
}
|
|
92
88
|
} else {
|
|
93
|
-
|
|
89
|
+
socketOptions = {
|
|
90
|
+
transports: ["websocket"]
|
|
91
|
+
};
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
let socketOptions;
|
|
98
|
-
if (isNode) {
|
|
99
|
-
socketOptions = {
|
|
100
|
-
transports: ["websocket"]
|
|
101
|
-
};
|
|
102
|
-
if (__privateGet(this, _options).agentManager) {
|
|
103
|
-
socketOptions.agent = __privateGet(this, _options).agentManager.GetAgent(socketDetail.address);
|
|
93
|
+
if (socketIoCustomPath && socketIoCustomPath.localeCompare("") !== 0) {
|
|
94
|
+
socketOptions.path = socketIoCustomPath;
|
|
104
95
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
if (socketEventsCallBack) {
|
|
138
|
-
socketEventsCallBack(socketDetail.socket);
|
|
96
|
+
socketDetail.socket = io(socketDetail.address, socketOptions);
|
|
97
|
+
socketDetail.socket.io.on("error", (err) => {
|
|
98
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('error'): [${err}]`);
|
|
99
|
+
});
|
|
100
|
+
socketDetail.socket.io.on("reconnect_error", (err) => {
|
|
101
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('reconnect_error'): [${err}]`);
|
|
102
|
+
});
|
|
103
|
+
socketDetail.socket.io.on("reconnect", (attempt) => {
|
|
104
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.io.on('reconnect'): Number: [${attempt}]`);
|
|
105
|
+
});
|
|
106
|
+
socketDetail.socket.on("connect_error", (err) => {
|
|
107
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.on('connect_error'): [${err}]`);
|
|
108
|
+
});
|
|
109
|
+
socketDetail.socket.on("connect_timeout", () => {
|
|
110
|
+
this.#LogErrorMessage(`SocketIoClientHelper(): socketDetail.socket.on('connect_timeout')`);
|
|
111
|
+
});
|
|
112
|
+
socketDetail.socket.on("connect", () => {
|
|
113
|
+
if (socketDetail.socket) {
|
|
114
|
+
this.#LogDebugMessage(`SocketIoClientHelper(): Socket: [${socketDetail.socket.id}]: connected`);
|
|
115
|
+
if (onConnectCallBack) {
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
onConnectCallBack(socketDetail.socket);
|
|
118
|
+
}, 0);
|
|
119
|
+
}
|
|
120
|
+
if (socketEventsCallBack) {
|
|
121
|
+
socketEventsCallBack(socketDetail.socket);
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
const errorMessage = "SocketIoClientHelper(): Could not get socket object from socket.io";
|
|
125
|
+
this.#LogErrorMessage(errorMessage);
|
|
126
|
+
socketDetail.errorCallBack(new Error(errorMessage));
|
|
139
127
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (__privateGet(this, _options).agentManager) {
|
|
158
|
-
__privateGet(this, _options).agentManager.ResetAgent();
|
|
128
|
+
});
|
|
129
|
+
socketDetail.socket.on("disconnect", (reason) => {
|
|
130
|
+
this.#LogDebugMessage("SocketIoClientHelper(): socket disconnect: " + reason);
|
|
131
|
+
switch (reason) {
|
|
132
|
+
case "io server disconnect":
|
|
133
|
+
{
|
|
134
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
|
|
135
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The connection will be re-established when the server becomes available.");
|
|
136
|
+
const socketDetail2 = this.sockets[name];
|
|
137
|
+
socketDetail2.socket = null;
|
|
138
|
+
if (isNode) {
|
|
139
|
+
if (this.#options.agentManager) {
|
|
140
|
+
this.#options.agentManager.ResetAgent();
|
|
141
|
+
}
|
|
142
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
143
|
+
} else {
|
|
144
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
159
145
|
}
|
|
160
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
161
|
-
} else {
|
|
162
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
163
146
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
147
|
+
break;
|
|
148
|
+
case "io client disconnect":
|
|
149
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
|
|
150
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The connection will not be re-established automatically.");
|
|
151
|
+
break;
|
|
152
|
+
case "transport close":
|
|
153
|
+
case "ping timeout":
|
|
154
|
+
case "transport error":
|
|
155
|
+
{
|
|
156
|
+
this.#LogDebugMessage(`SocketIoClientHelper(): Server unexpectedly disconnected. Reason: [${reason}]`);
|
|
157
|
+
this.#LogDebugMessage("SocketIoClientHelper(): The connection will be re-established when the server becomes available.");
|
|
158
|
+
const socketDetail2 = this.sockets[name];
|
|
159
|
+
if (socketDetail2.socket) {
|
|
160
|
+
socketDetail2.socket.disconnect();
|
|
161
|
+
}
|
|
162
|
+
socketDetail2.socket = null;
|
|
163
|
+
if (isNode) {
|
|
164
|
+
if (this.#options.agentManager) {
|
|
165
|
+
this.#options.agentManager?.ResetAgent();
|
|
166
|
+
}
|
|
167
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
168
|
+
} else {
|
|
169
|
+
setTimeout(() => this.#EstablishSocketConnect(name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
184
170
|
}
|
|
185
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100).unref();
|
|
186
|
-
} else {
|
|
187
|
-
setTimeout(() => __privateMethod(this, _SocketIoClientHelper_instances, EstablishSocketConnect_fn).call(this, name, socketIoCustomPath, onConnectCallBack, socketEventsCallBack), 100);
|
|
188
171
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
194
177
|
class SocketIoServerHelper {
|
|
178
|
+
#socketIoServerHelperOptions;
|
|
179
|
+
#namespace = {};
|
|
195
180
|
constructor(options) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
181
|
+
this.#socketIoServerHelperOptions = options;
|
|
182
|
+
}
|
|
183
|
+
LogMessage(namespace, message) {
|
|
184
|
+
if (namespace) {
|
|
185
|
+
this.#socketIoServerHelperOptions.logger.debug(`${namespace.namespace}: ${message}`);
|
|
186
|
+
} else {
|
|
187
|
+
this.#socketIoServerHelperOptions.logger.debug(`${message}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
LeaveRoom = (namespace, socket, room) => {
|
|
191
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}: Leaving room [${room}]`);
|
|
192
|
+
socket.leave(room);
|
|
193
|
+
};
|
|
194
|
+
JoinRoom = (namespace, socket, room) => {
|
|
195
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}: Socket joining room [${room}], ID: [${socket.id}]`);
|
|
196
|
+
socket.join(room);
|
|
197
|
+
};
|
|
198
|
+
#SetupStandardEvents = (namespace, socket) => {
|
|
199
|
+
socket.on("disconnect", (reason) => {
|
|
200
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket disconnect, ID: [${socket.id}] [${reason}]`);
|
|
201
201
|
});
|
|
202
|
-
|
|
203
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}:
|
|
204
|
-
socket.join(room);
|
|
202
|
+
socket.on("disconnecting", (reason) => {
|
|
203
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket disconnecting, ID: [${socket.id}] [${reason}]`);
|
|
205
204
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket disconnect, ID: [${socket.id}] [${reason}]`);
|
|
209
|
-
});
|
|
210
|
-
socket.on("disconnecting", (reason) => {
|
|
211
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket disconnecting, ID: [${socket.id}] [${reason}]`);
|
|
212
|
-
});
|
|
213
|
-
socket.on("error", (error) => {
|
|
214
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket error, ID: [${socket.id}] [${error}]`);
|
|
215
|
-
});
|
|
216
|
-
socket.on("__STSdisconnect", (reason) => {
|
|
217
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: __STSdisconnect: socket disconnect, ID: [${socket.id}] [${reason}]`);
|
|
218
|
-
});
|
|
219
|
-
socket.on("__STSdisconnecting", (reason, callBackResult) => {
|
|
220
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: __STSdisconnecting: socket disconnecting, ID: [${socket.id}] [${reason}]`);
|
|
221
|
-
callBackResult("__STSdisconnecting accepted by server.");
|
|
222
|
-
});
|
|
223
|
-
socket.on("__STSjoinRoom", (rooms) => {
|
|
224
|
-
rooms.forEach((room) => {
|
|
225
|
-
this.JoinRoom(namespace, socket, room);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
socket.on("__STSleaveRoom", (rooms) => {
|
|
229
|
-
rooms.forEach((room) => {
|
|
230
|
-
this.LeaveRoom(namespace, socket, room);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
socket.on("__STSsendToRoom", (rooms, payload) => {
|
|
234
|
-
rooms.forEach((room) => {
|
|
235
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}:socket.on:sendToRoom: __STSsendToRoom: Sending to room [${room}], ID: [${socket.id}]`);
|
|
236
|
-
namespace.socketionamespace.to(room).emit(payload.command, payload);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
205
|
+
socket.on("error", (error) => {
|
|
206
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket error, ID: [${socket.id}] [${error}]`);
|
|
239
207
|
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
208
|
+
socket.on("__STSdisconnect", (reason) => {
|
|
209
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}: __STSdisconnect: socket disconnect, ID: [${socket.id}] [${reason}]`);
|
|
210
|
+
});
|
|
211
|
+
socket.on("__STSdisconnecting", (reason, callBackResult) => {
|
|
212
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}: __STSdisconnecting: socket disconnecting, ID: [${socket.id}] [${reason}]`);
|
|
213
|
+
callBackResult("__STSdisconnecting accepted by server.");
|
|
214
|
+
});
|
|
215
|
+
socket.on("__STSjoinRoom", (rooms) => {
|
|
216
|
+
rooms.forEach((room) => {
|
|
217
|
+
this.JoinRoom(namespace, socket, room);
|
|
246
218
|
});
|
|
247
219
|
});
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
next();
|
|
220
|
+
socket.on("__STSleaveRoom", (rooms) => {
|
|
221
|
+
rooms.forEach((room) => {
|
|
222
|
+
this.LeaveRoom(namespace, socket, room);
|
|
252
223
|
});
|
|
253
224
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
namespace,
|
|
257
|
-
|
|
258
|
-
socketionamespace: io2.of(`/${namespace}/`)
|
|
259
|
-
};
|
|
260
|
-
__privateGet(this, _SetupConnectionMiddleware).call(this, __privateGet(this, _namespace)[namespace]);
|
|
261
|
-
__privateGet(this, _namespace)[namespace].socketionamespace.on("connection", (socket) => {
|
|
262
|
-
this.LogMessage(__privateGet(this, _namespace)[namespace], `${namespace}: Socket connected, ID: [${socket.id}]`);
|
|
263
|
-
this.LogMessage(__privateGet(this, _namespace)[namespace], `${namespace}: Authentication Handshake: [${JSON.stringify(socket.handshake.auth)}]`);
|
|
264
|
-
__privateGet(this, _SetupMessageMiddleware).call(this, socket);
|
|
265
|
-
if (autoJoinRooms) {
|
|
266
|
-
rooms.map((room) => {
|
|
267
|
-
this.JoinRoom(__privateGet(this, _namespace)[namespace], socket, room);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
__privateGet(this, _SetupStandardEvents).call(this, __privateGet(this, _namespace)[namespace], socket);
|
|
271
|
-
if (socketConnectCallBack) {
|
|
272
|
-
setTimeout(() => {
|
|
273
|
-
socketConnectCallBack(socket);
|
|
274
|
-
}, 0);
|
|
275
|
-
}
|
|
276
|
-
if (socketEventsCallBack) {
|
|
277
|
-
socketEventsCallBack(socket);
|
|
278
|
-
}
|
|
225
|
+
socket.on("__STSsendToRoom", (rooms, payload) => {
|
|
226
|
+
rooms.forEach((room) => {
|
|
227
|
+
this.LogMessage(namespace, `${namespace.socketionamespace.name}:socket.on:sendToRoom: __STSsendToRoom: Sending to room [${room}], ID: [${socket.id}]`);
|
|
228
|
+
namespace.socketionamespace.to(room).emit(payload.command, payload);
|
|
279
229
|
});
|
|
280
|
-
return __privateGet(this, _namespace)[namespace].socketionamespace;
|
|
281
230
|
});
|
|
282
|
-
|
|
283
|
-
|
|
231
|
+
};
|
|
232
|
+
// Use this middleward to check every incomming connection
|
|
233
|
+
#SetupConnectionMiddleware = (nameSpace) => {
|
|
234
|
+
nameSpace.socketionamespace.use((socket, next) => {
|
|
235
|
+
{
|
|
236
|
+
next();
|
|
237
|
+
}
|
|
284
238
|
});
|
|
285
|
-
|
|
286
|
-
|
|
239
|
+
};
|
|
240
|
+
// Use this middleware to check very packet being received
|
|
241
|
+
#SetupMessageMiddleware = (socket) => {
|
|
242
|
+
socket.use(([event, ...args], next) => {
|
|
243
|
+
next();
|
|
287
244
|
});
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
245
|
+
};
|
|
246
|
+
SetupNamespace = (io2, namespace, rooms, autoJoinRooms, socketConnectCallBack, socketEventsCallBack) => {
|
|
247
|
+
this.#namespace[namespace] = {
|
|
248
|
+
namespace,
|
|
249
|
+
pid: process.pid,
|
|
250
|
+
socketionamespace: io2.of(`/${namespace}/`)
|
|
251
|
+
};
|
|
252
|
+
this.#SetupConnectionMiddleware(this.#namespace[namespace]);
|
|
253
|
+
this.#namespace[namespace].socketionamespace.on("connection", (socket) => {
|
|
254
|
+
this.LogMessage(this.#namespace[namespace], `${namespace}: Socket connected, ID: [${socket.id}]`);
|
|
255
|
+
this.LogMessage(this.#namespace[namespace], `${namespace}: Authentication Handshake: [${JSON.stringify(socket.handshake.auth)}]`);
|
|
256
|
+
this.#SetupMessageMiddleware(socket);
|
|
257
|
+
if (autoJoinRooms) {
|
|
258
|
+
rooms.map((room) => {
|
|
259
|
+
this.JoinRoom(this.#namespace[namespace], socket, room);
|
|
260
|
+
});
|
|
291
261
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
262
|
+
this.#SetupStandardEvents(this.#namespace[namespace], socket);
|
|
263
|
+
if (socketConnectCallBack) {
|
|
264
|
+
setTimeout(() => {
|
|
265
|
+
socketConnectCallBack(socket);
|
|
266
|
+
}, 0);
|
|
267
|
+
}
|
|
268
|
+
if (socketEventsCallBack) {
|
|
269
|
+
socketEventsCallBack(socket);
|
|
296
270
|
}
|
|
297
|
-
__privateSet(this, _namespace, {});
|
|
298
271
|
});
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
272
|
+
return this.#namespace[namespace].socketionamespace;
|
|
273
|
+
};
|
|
274
|
+
GetSTSSocketIONamespace = (namespace) => {
|
|
275
|
+
return this.#namespace[namespace];
|
|
276
|
+
};
|
|
277
|
+
GetSTSSocketIONamespaces = () => {
|
|
278
|
+
return this.#namespace;
|
|
279
|
+
};
|
|
280
|
+
CloseAdaptors = async () => {
|
|
281
|
+
for (const [, namespace] of Object.entries(this.#namespace)) {
|
|
282
|
+
await namespace.socketionamespace.adapter.close();
|
|
306
283
|
}
|
|
307
|
-
}
|
|
284
|
+
};
|
|
285
|
+
DisconnectSockets = () => {
|
|
286
|
+
for (const [, namespace] of Object.entries(this.#namespace)) {
|
|
287
|
+
namespace.socketionamespace.disconnectSockets();
|
|
288
|
+
}
|
|
289
|
+
this.#namespace = {};
|
|
290
|
+
};
|
|
308
291
|
SetupEvent(event, eventCb) {
|
|
309
292
|
return this;
|
|
310
293
|
}
|
|
311
294
|
}
|
|
312
|
-
_socketIoServerHelperOptions = new WeakMap();
|
|
313
|
-
_namespace = new WeakMap();
|
|
314
|
-
_SetupStandardEvents = new WeakMap();
|
|
315
|
-
_SetupConnectionMiddleware = new WeakMap();
|
|
316
|
-
_SetupMessageMiddleware = new WeakMap();
|
|
317
295
|
export {
|
|
318
296
|
STSEvent,
|
|
319
297
|
STSNamespace,
|