aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sockets.js
diff options
context:
space:
mode:
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;