Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for socket.IO rooms.

  • Loading branch information...
commit 236055324adcab7a39afde43f57dc247d752bfa4 1 parent 963dbb2
@shimaore shimaore authored
Showing with 18 additions and 0 deletions.
  1. +18 −0 src/zappa.coffee
View
18 src/zappa.coffee
@@ -326,6 +326,10 @@ zappa.app = (func) ->
socket: socket
id: socket.id
client: c
+ join: (room) ->
+ socket.join room
+ leave: (room) ->
+ socket.leave room
emit: ->
if typeof arguments[0] isnt 'object'
socket.emit.apply socket, arguments
@@ -338,6 +342,20 @@ zappa.app = (func) ->
else
for k, v of arguments[0]
socket.broadcast.emit.apply socket.broadcast, [k, v]
+ broadcast_to: (room, args...) ->
+ if typeof args[0] isnt 'object'
+ socket.broadcast.to(room).emit.apply socket.broadcast, args
+ else
+ for k, v of args[0]
+ socket.broadcast.to(room).emit.apply socket.broadcast, [k, v]
+ broadcast_to_all: (room, args...) ->
+ if typeof args[0] isnt 'object'
+ socket.broadcast.to(room).emit.apply socket.broadcast, args
+ socket.emit.apply socket, args
+ else
+ for k, v of args[0]
+ socket.broadcast.to(room).emit.apply socket.broadcast, [k, v]
+ socket.emit.apply socket, [k, v]
for name, helper of helpers
do (name, helper) ->
Please sign in to comment.
Something went wrong with that request. Please try again.