From f5311bcc97ee30358e1809be38ca0b3f1179d2e2 Mon Sep 17 00:00:00 2001 From: rofl256 Date: Fri, 9 Feb 2018 02:04:50 +0100 Subject: [PATCH] fix different whiteboard interference --- public/js/main.js | 2 ++ server.js | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/public/js/main.js b/public/js/main.js index 16711ba..87b89af 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -26,6 +26,8 @@ signaling_socket.on('connect', function () { signaling_socket.on('refreshUserBadges', function () { whiteboard.refreshUserBadges(); }); + + signaling_socket.emit('joinWhiteboard', whiteboardId); }); $(document).ready(function() { diff --git a/server.js b/server.js index 217b791..1256532 100644 --- a/server.js +++ b/server.js @@ -70,18 +70,36 @@ 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); - socket.broadcast.emit('drawToWhiteboard', content); + sendToAllUsersOfWhiteboard(content["wid"], content) s_whiteboard.handleEventsAndData(content); //save whiteboardchanges on the server }); + + socket.on('joinWhiteboard', function(wid) { + allUsers[socket.id] = { + "socket" : socket, + "wid" : wid + }; + }); }); +function sendToAllUsersOfWhiteboard(wid, content) { + for(var i in allUsers) { + if(allUsers[i]["wid"]==wid) { + allUsers[i]["socket"].emit('drawToWhiteboard', content); + } + } +} + //Prevent cross site scripting function escapeAllContentStrings(content, cnt) { if(!cnt)