fix different whiteboard interference

This commit is contained in:
rofl256 2018-02-09 02:04:50 +01:00
parent 88a2fe0dda
commit f5311bcc97
2 changed files with 21 additions and 1 deletions

View File

@ -26,6 +26,8 @@ signaling_socket.on('connect', function () {
signaling_socket.on('refreshUserBadges', function () { signaling_socket.on('refreshUserBadges', function () {
whiteboard.refreshUserBadges(); whiteboard.refreshUserBadges();
}); });
signaling_socket.emit('joinWhiteboard', whiteboardId);
}); });
$(document).ready(function() { $(document).ready(function() {

View File

@ -70,17 +70,35 @@ function progressUploadFormData(formData) {
}); });
} }
var allUsers = {};
io.on('connection', function(socket){ io.on('connection', function(socket){
socket.on('disconnect', function () { socket.on('disconnect', function () {
delete allUsers[socket.id];
socket.broadcast.emit('refreshUserBadges', null); socket.broadcast.emit('refreshUserBadges', null);
}); });
socket.on('drawToWhiteboard', function(content) { socket.on('drawToWhiteboard', function(content) {
content = escapeAllContentStrings(content); content = escapeAllContentStrings(content);
socket.broadcast.emit('drawToWhiteboard', content); sendToAllUsersOfWhiteboard(content["wid"], content)
s_whiteboard.handleEventsAndData(content); //save whiteboardchanges on the server 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 //Prevent cross site scripting
function escapeAllContentStrings(content, cnt) { function escapeAllContentStrings(content, cnt) {