From 6c5470e6b14d655a5038ec2b3b56a7332dbeaefe Mon Sep 17 00:00:00 2001 From: hippoz Date: Sun, 3 Jan 2021 17:04:23 +0200 Subject: [PATCH] fix #10 --- api/v1/gateway/index.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index 77eba9f..b5f75dc 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -226,22 +226,26 @@ GatewayServer.prototype.eventSetup = function() { socket.on('subscribe', async (categories) => { if ( !socket.isConnected || !socket.user || !categories || !Array.isArray(categories) || categories === []) return; - for (const v of categories) { - if (!v && !(typeof v === 'string')) continue; - // TODO: When/if category permissions are added, check if the user has permissions for that category - const category = await Category.findById(v); - if (category && category.title && category._id) { - if (!socket.joinedCategories) socket.joinedCategories = {}; - if (socket.joinedCategories[v]) continue; - socket.joinedCategories[v] = category.title; - await socket.join(v); - - console.log(`[*] [gateway] User ${socket.user.username} subscribed to room ${v} (${category.title}), sending updated user list to all members of that room...`); - - const upd = await this._generateClientListUpdateObject(v, category.title); - this._gateway.in(v).emit('clientListUpdate', upd); + try { + for (const v of categories) { + if (!v && !(typeof v === 'string')) continue; + // TODO: When/if category permissions are added, check if the user has permissions for that category + const category = await Category.findById(v); + if (category && category.title && category._id) { + if (!socket.joinedCategories) socket.joinedCategories = {}; + if (socket.joinedCategories[v]) continue; + socket.joinedCategories[v] = category.title; + await socket.join(v); + + console.log(`[*] [gateway] User ${socket.user.username} subscribed to room ${v} (${category.title}), sending updated user list to all members of that room...`); + + const upd = await this._generateClientListUpdateObject(v, category.title); + this._gateway.in(v).emit('clientListUpdate', upd); + } } - } + } catch (e) { + return; + } }); socket.on('disconnecting', async () => {