aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sockets.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-04-16 18:14:36 +0000
committerAdam Soltys <[email protected]>2023-04-16 18:16:59 +0000
commite1beafc2c1add04495fe31475aa344c5219e525c (patch)
treee76df5d71c5fa16d3a17a40ec384ed0f275159ea /lib/sockets.js
parentd404f11e5df3c982ed91e4cddd2fbc9de6870262 (diff)
downloadcoinos-server-e1beafc2c1add04495fe31475aa344c5219e525c.tar.gz
coinos-server-e1beafc2c1add04495fe31475aa344c5219e525c.zip
ip and lnurl fixes
Diffstat (limited to 'lib/sockets.js')
-rw-r--r--lib/sockets.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/sockets.js b/lib/sockets.js
index e5f2638b..c42c9c7a 100644
--- a/lib/sockets.js
+++ b/lib/sockets.js
@@ -49,17 +49,19 @@ export const broadcast = (type, data) => {
let track = async (ws, token) => {
let { id } = ws;
let { id: uid } = jwt.decode(token);
+
if (!uid) throw new Error("Invalid JWT token");
let user = await g(`user:${uid}`);
if (!user) throw new Error("User not found");
if (!store.sockets[uid]) store.sockets[uid] = {};
- if (store.sockets[uid][id]) return;
+
const existing = Object.keys(store.sockets[uid]);
if (existing.length > 4) {
const p = existing.find(sid => sid !== uid);
store.sockets[uid][p].close(code, "too many sockets");
}
+
store.sockets[uid][id] = ws;
users[id] = uid;
ws.user = user;