fix messages not being broadcasted

This commit is contained in:
hippoz 2020-11-20 20:15:20 +02:00
parent de6a66a877
commit 35d37ea782
2 changed files with 6 additions and 6 deletions

View file

@ -101,9 +101,8 @@ GatewayServer.prototype.eventSetup = function() {
content: content, content: content,
_id: uuid.v4() _id: uuid.v4()
}; };
socket.broadcast.to(category._id).emit('message', messageObject); this._gateway.in(category._id).emit('message', messageObject);
socket.emit('message', messageObject);
}); });
socket.on('subscribe', async (categories) => { socket.on('subscribe', async (categories) => {
@ -114,9 +113,9 @@ GatewayServer.prototype.eventSetup = function() {
const category = await Category.findById(v); const category = await Category.findById(v);
if (category && category.title && category._id) { if (category && category.title && category._id) {
if (!socket.joinedCategories) socket.joinedCategories = {}; if (!socket.joinedCategories) socket.joinedCategories = {};
if (socket.joinedCategories[category._id]) continue; if (socket.joinedCategories[v]) continue;
socket.joinedCategories[category._id] = category.title; socket.joinedCategories[v] = category.title;
socket.join(category._id); await socket.join(v);
} }
} }
}); });

View file

@ -222,6 +222,7 @@ const app = new Vue({
}; };
this.gateway.connect(this.loggedInUser.token); this.gateway.connect(this.loggedInUser.token);
this.gateway.socket.on('message', (e) => { this.gateway.socket.on('message', (e) => {
console.log(e);
this.processMessage(e); this.processMessage(e);
}); });
}, },