From ba8bca95a8b8d8cf6c23c6c82a2cdcad7ff35958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Sat, 25 Mar 2023 14:47:54 +0100 Subject: [PATCH] Minor fixes regarding websockets --- .gitignore | 1 + main.js | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index a08e52b..413c0ae 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules package-lock.json sessions.json +client_sessions.json diff --git a/main.js b/main.js index 5406d81..15d5a83 100644 --- a/main.js +++ b/main.js @@ -516,10 +516,10 @@ class CenterSession { } this.logger.log1(`Sending notify message from ${source} to ${destination} with message ${message}`); this.getNextSession().submit_sm({ - source_addr: source, - destination_addr: destination, - short_message: message - }, pdu => { + source_addr: source, + destination_addr: destination, + short_message: message + }, pdu => { resolve(pdu); }); }); @@ -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) { - 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(`Session with ID ${sessionId} fired PDU`); + let payload = { + type: 'pdu', + sessionId: sessionId, + value: pdu + } this.logger.log2(`Broadcasting session with ID ${sessionId} to ${clients.length} clients`); clients.forEach(client => { client.send(JSON.stringify(payload));