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)