From 7bebf6d4713cb494a83c7110b936f0684b0819fa Mon Sep 17 00:00:00 2001 From: hippoz Date: Sat, 21 Nov 2020 17:40:35 +0200 Subject: [PATCH] hopefully fix user list --- api/v1/gateway/index.js | 15 ++++++++++----- app/resources/js/app.js | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index e16dd54..4c8cf9b 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -129,7 +129,8 @@ GatewayServer.prototype.eventSetup = function() { console.log(`[*] [gateway] User ${socket.user.username} subscribed to room ${v} (${category.title}), sending updated user list to all members of that room...`); - this._gateway.in(v).emit('clientListUpdate', await this._generateClientListUpdateObject(v, category.title)); + const upd = await this._generateClientListUpdateObject(v, category.title); + this._gateway.in(v).emit('clientListUpdate', upd); } } }); @@ -144,7 +145,8 @@ GatewayServer.prototype.eventSetup = function() { const categoryTitle = socket.joinedCategories[room] || 'UNKNOWN'; await socket.leave(room); - socket.in(room).emit('clientListUpdate', await this._generateClientListUpdateObject(room, categoryTitle)); + const upd = await this._generateClientListUpdateObject(room, categoryTitle); + socket.in(room).emit('clientListUpdate', upd); }); }); }); @@ -152,11 +154,14 @@ GatewayServer.prototype.eventSetup = function() { }; GatewayServer.prototype._getSocketsInRoom = async function(room) { - const clients = this._gateway.in(room).sockets; + // NOTE: I have no idea why i have to do this dumb thing, why can't socket io just let you simply get the sockets from a room? idk + // There kinda was a way in the previous version, but they want to change the api for the worse each version, i'm guessing + const clients = await this._gateway.in(room).allSockets(); const updatedClientList = []; - clients.forEach((client) => { - if (!client.isConnected || !client.user) return; + clients.forEach((sid) => { + const client = this._gateway.sockets.get(sid); // lol they also used dumb ass maps for the socket list, can you fucking not? + if (!client || !client.isConnected || !client.user) return; updatedClientList.push({ user: { username: client.user.username, diff --git a/app/resources/js/app.js b/app/resources/js/app.js index f855624..659443f 100755 --- a/app/resources/js/app.js +++ b/app/resources/js/app.js @@ -231,6 +231,7 @@ const app = new Vue({ }; this.gateway.connect(this.loggedInUser.token); this.gateway.socket.on('message', (e) => { + //console.log('[*] [gateway] Message received', e); this.processMessage(e); }); this.gateway.socket.on('clientListUpdate', (e) => {