Minor fixes regarding websockets
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
node_modules
|
||||
package-lock.json
|
||||
sessions.json
|
||||
client_sessions.json
|
||||
|
7
main.js
7
main.js
@@ -1024,6 +1024,9 @@ class WSServer {
|
||||
delete this.clients[sessionId][index];
|
||||
}
|
||||
this.clients[sessionId] = this.clients[sessionId].filter(Boolean);
|
||||
if (this.clients[sessionId].length === 0) {
|
||||
delete this.clients[sessionId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1044,14 +1047,14 @@ class WSServer {
|
||||
}
|
||||
|
||||
pduEvent(sessionId, pdu) {
|
||||
let clients = this.clients[sessionId];
|
||||
if (!!clients) {
|
||||
this.logger.log2(`Session with ID ${sessionId} fired PDU`);
|
||||
let payload = {
|
||||
type: 'pdu',
|
||||
sessionId: sessionId,
|
||||
value: pdu
|
||||
}
|
||||
let clients = this.clients[sessionId];
|
||||
if (!!clients) {
|
||||
this.logger.log2(`Broadcasting session with ID ${sessionId} to ${clients.length} clients`);
|
||||
clients.forEach(client => {
|
||||
client.send(JSON.stringify(payload));
|
||||
|
Reference in New Issue
Block a user