-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_whiteboard.js
39 lines (38 loc) · 1.34 KB
/
s_whiteboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//This file is only for saving the whiteboard. (Not to a file, only to RAM atm. Whiteboard is gone after server restart)
var savedBoards = {};
module.exports = {
handleEventsAndData : function(content) {
var tool = content["t"]; //Tool witch is used
var wid = content["wid"]; //whiteboard ID
var username = content["username"];
if(tool==="clear") { //Clear the whiteboard
delete savedBoards[wid];
} else if(tool==="undo") { //Undo an action
if(savedBoards[wid]) {
for(var i=savedBoards[wid].length-1;i>=0;i--){
if(savedBoards[wid][i]["username"]==username) {
var drawId = savedBoards[wid][i]["drawId"];
for(var i=savedBoards[wid].length-1;i>=0;i--){
if(savedBoards[wid][i]["drawId"]==drawId && savedBoards[wid][i]["username"]==username) {
savedBoards[wid].splice(i, 1);
}
}
break;
}
}
}
} else if(tool==="line" || tool==="pen" || tool==="rect" || tool==="circle" || tool==="eraser" || tool==="addImgBG" || tool==="recSelect" || tool==="eraseRec") { //Save all this actions
if(!savedBoards[wid]) {
savedBoards[wid] = [];
}
delete content["wid"]; //Delete id from content so we don't store it twice
savedBoards[wid].push(content);
}
},
loadStoredData : function(wid) { //Load saved whiteboard
if(!savedBoards[wid]) {
return [];
}
return savedBoards[wid];
}
}