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