use socket io rooms instead of allUsers obj

This commit is contained in:
raphael 2019-01-11 10:49:18 +01:00
parent 47e7ff18d0
commit 9e97a13425
1 changed files with 2 additions and 15 deletions

View File

@ -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)