From 9e97a134256f1d4f51868c7c8df6f0d488d34677 Mon Sep 17 00:00:00 2001 From: raphael Date: Fri, 11 Jan 2019 10:49:18 +0100 Subject: [PATCH] use socket io rooms instead of allUsers obj --- server.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/server.js b/server.js index 6948873..dff09d1 100644 --- a/server.js +++ b/server.js @@ -74,36 +74,23 @@ function progressUploadFormData(formData) { }); } -var allUsers = {}; io.on('connection', function(socket){ socket.on('disconnect', function () { - delete allUsers[socket.id]; socket.broadcast.emit('refreshUserBadges', null); }); socket.on('drawToWhiteboard', function(content) { content = escapeAllContentStrings(content); - sendToAllUsersOfWhiteboard(content["wid"], socket.id, content) + socket.broadcast.to(content["wid"]).emit('drawToWhiteboard', content); s_whiteboard.handleEventsAndData(content); //save whiteboardchanges on the server }); socket.on('joinWhiteboard', function(wid) { - allUsers[socket.id] = { - "socket" : socket, - "wid" : wid - }; + socket.join(wid); }); }); -function sendToAllUsersOfWhiteboard(wid, ownSocketId, content) { - for(var i in allUsers) { - if(allUsers[i]["wid"]===wid && allUsers[i]["socket"].id !== ownSocketId) { - allUsers[i]["socket"].emit('drawToWhiteboard', content); - } - } -} - //Prevent cross site scripting function escapeAllContentStrings(content, cnt) { if(!cnt)