Created
February 19, 2015 17:41
-
-
Save francescogior/425776cdfedec3fc0789 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Whiteboard = require '../whiteboard/controller' | |
module.exports = (io) -> | |
io.on 'connection', (socket) -> | |
socket.on 'get socket', (whiteboardId) -> | |
socket.join whiteboardId | |
socket.on 'currentPage', (pageNumber) -> | |
socket.to(whiteboardId).broadcast.emit 'currentPage', pageNumber | |
socket.on 'new drawing', (data) -> | |
socket.to(whiteboardId).broadcast.emit 'new drawing', data | |
Whiteboard.addDrawing whiteboardId, data.pageNumber, data.drawing | |
socket.on 'undo', (data) -> | |
socket.to(whiteboardId).broadcast.emit 'undo', data.pageNumber | |
Whiteboard.undo data.drawingId | |
socket.on 'redo', (data) -> | |
socket.to(whiteboardId).broadcast.emit 'redo', data.pageNumber | |
Whiteboard.redo data.drawingId | |
socket.on 'new message', (message) -> | |
data = | |
username : socket.username | |
message : message | |
socket.to(whiteboardId).broadcast.emit 'new message', data | |
Whiteboard.addChat whiteboardId, data | |
socket.on 'add user', (username) -> | |
socket.username = username | |
socket.emit 'login' | |
data = | |
username: username | |
socket.to(whiteboardId).broadcast.emit 'user joined', data | |
socket.on 'peerId', (peerId) -> | |
console.log 'peerId', peerId | |
socket.to(whiteboardId).broadcast.emit 'peerId', peerId | |
socket.on 'disconnect', -> | |
data = | |
username: socket.username | |
socket.to(whiteboardId).broadcast.emit 'user left', data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment