Skip to content

Instantly share code, notes, and snippets.

@francescogior
Created February 19, 2015 17:41
Show Gist options
  • Save francescogior/425776cdfedec3fc0789 to your computer and use it in GitHub Desktop.
Save francescogior/425776cdfedec3fc0789 to your computer and use it in GitHub Desktop.
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