From 35d37ea7826c2fda5827390631999684fc8f0b72 Mon Sep 17 00:00:00 2001 From: hippoz Date: Fri, 20 Nov 2020 20:15:20 +0200 Subject: [PATCH] fix messages not being broadcasted --- api/v1/gateway/index.js | 11 +++++------ app/resources/js/app.js | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index b068c2f..d5968a5 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -101,9 +101,8 @@ GatewayServer.prototype.eventSetup = function() { content: content, _id: uuid.v4() }; - - socket.broadcast.to(category._id).emit('message', messageObject); - socket.emit('message', messageObject); + + this._gateway.in(category._id).emit('message', messageObject); }); socket.on('subscribe', async (categories) => { @@ -114,9 +113,9 @@ GatewayServer.prototype.eventSetup = function() { const category = await Category.findById(v); if (category && category.title && category._id) { if (!socket.joinedCategories) socket.joinedCategories = {}; - if (socket.joinedCategories[category._id]) continue; - socket.joinedCategories[category._id] = category.title; - socket.join(category._id); + if (socket.joinedCategories[v]) continue; + socket.joinedCategories[v] = category.title; + await socket.join(v); } } }); diff --git a/app/resources/js/app.js b/app/resources/js/app.js index d654d8f..78aed49 100755 --- a/app/resources/js/app.js +++ b/app/resources/js/app.js @@ -222,6 +222,7 @@ const app = new Vue({ }; this.gateway.connect(this.loggedInUser.token); this.gateway.socket.on('message', (e) => { + console.log(e); this.processMessage(e); }); },