Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# WBO
# WBO

WBO is an online collaborative whiteboard that allows many users to draw simultaneously on a large virtual board.
The board is updated in real time for all connected users, and its state is always persisted. It can be used for many different purposes, including art, entertainment, design, teaching.
Expand Down Expand Up @@ -92,6 +92,7 @@ You can see a list of these variables in [`configuration.js`](./server/configura
Some important environment variables are :
- `WBO_HISTORY_DIR` : configures the directory where the boards are saved. Defaults to `./server-data/`.
- `WBO_MAX_EMIT_COUNT` : the maximum number of messages that a client can send per unit of time. Increase this value if you want smoother drawings, at the expense of being susceptible to denial of service attacks if your server does not have enough processing power. By default, the units of this quantity are messages per 4 seconds, and the default value is `192`.
- `DELETE_ON_LEAVE` : (default: `false` / `true`) whether the board gets deleted if the last user leaves or not
- `AUTH_SECRET_KEY` : If you would like to authenticate your boards using jwt, this declares the secret key.

## Troubleshooting
Expand Down
36 changes: 36 additions & 0 deletions client-data/js/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ Tools.drawingEvent = true;
Tools.showMarker = true;
Tools.showOtherCursors = true;
Tools.showMyCursor = true;
Tools.metadata = {users: 1};

Tools.isIE = /MSIE|Trident/.test(window.navigator.userAgent);
Tools.isInIFrame = function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}()

Tools.socket = null;
Tools.connect = function () {
Expand Down Expand Up @@ -85,6 +93,15 @@ Tools.connect = function () {
});
});

//Receive metadata about the board from server
this.socket.on("metadata", function (msg) {
if (!msg.users) {
Tools.metadata.users = 1;
console.error("Received a badly formatted message (no users). ", msg);
}
Tools.metadata.users = msg.users;
});

this.socket.on("reconnect", function onReconnection() {
Tools.socket.emit('joinboard', Tools.boardName);
});
Expand Down Expand Up @@ -342,6 +359,10 @@ Tools.send = function (data, toolName) {
"board": Tools.boardName,
"data": d
};
if(d.tool !== "Cursor"){
// Reset the downloaded property as the Whiteboard was updated
Tools.metadata.downloaded = false;
}
Tools.socket.emit('broadcast', message);
};

Expand Down Expand Up @@ -469,6 +490,10 @@ function resizeCanvas(m) {
}

function updateUnreadCount(m) {
if(m.tool !== "Cursor"){
// Reset the downloaded property as the Whiteboard was updated
Tools.metadata.downloaded = false;
}
if (document.hidden && ["child", "update"].indexOf(m.type) === -1) {
Tools.newUnreadMessage();
}
Expand Down Expand Up @@ -711,4 +736,15 @@ Tools.svg.height.baseVal.value = document.body.clientHeight;
document.removeEventListener("mouseup", menu_mouseup);
}
menu.addEventListener("mousedown", menu_mousedown);
// Ask to save before leave
if(Tools.server_config.DELETE_ON_LEAVE && !Tools.isInIFrame){
window.addEventListener('beforeunload', function (e) {
if (Tools.metadata.users === 1 && Tools.metadata.downloaded === false ) {
e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown
e.returnValue = 'The board will be deleted after you leave, make sure you saved the content!';
} else {
delete e['returnValue'];
}
});
}
})()
4 changes: 3 additions & 1 deletion client-data/tools/download/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
downloadContent(blob, Tools.boardName + ".svg");
}

function downloadContent(blob, filename) {
function downloadContent(blob, filename){
Tools.metadata.downloaded = true;
if (window.navigator.msSaveBlob) { // Internet Explorer
window.navigator.msSaveBlob(blob, filename);
} else {
Expand All @@ -67,6 +68,7 @@
document.body.removeChild(element);
window.URL.revokeObjectURL(url);
}
Tools.metadata.downloaded = true;
}

Tools.add({ //The new tool
Expand Down
Loading