use socket io rooms instead of allUsers obj
This commit is contained in:
parent
47e7ff18d0
commit
9e97a13425
17
server.js
17
server.js
@ -74,36 +74,23 @@ 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);
|
||||||
sendToAllUsersOfWhiteboard(content["wid"], socket.id, content)
|
socket.broadcast.to(content["wid"]).emit('drawToWhiteboard', content);
|
||||||
s_whiteboard.handleEventsAndData(content); //save whiteboardchanges on the server
|
s_whiteboard.handleEventsAndData(content); //save whiteboardchanges on the server
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('joinWhiteboard', function(wid) {
|
socket.on('joinWhiteboard', function(wid) {
|
||||||
allUsers[socket.id] = {
|
socket.join(wid);
|
||||||
"socket" : socket,
|
|
||||||
"wid" : 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
|
//Prevent cross site scripting
|
||||||
function escapeAllContentStrings(content, cnt) {
|
function escapeAllContentStrings(content, cnt) {
|
||||||
if(!cnt)
|
if(!cnt)
|
||||||
|
Loading…
Reference in New Issue
Block a user