Skip to content
Browse files

channels

  • Loading branch information...
1 parent 21340c6 commit 9b98c6bfd504276c0ab888c2a29cdf9965fd1df1 @mustardamus committed Aug 22, 2011
Showing with 23 additions and 19 deletions.
  1. +2 −0 app/client/client.coffee
  2. +17 −13 lib/quasi/client.coffee
  3. +4 −6 lib/quasi/index.coffee
View
2 app/client/client.coffee
@@ -1,4 +1,6 @@
quasi.ready ->
+ console.log 'i am ready', @sessionId
+
@trigger 'new_client' #tell the server i am here
@bind 'new_client_count', (clientCount) ->
View
30 lib/quasi/client.coffee
@@ -3,26 +3,30 @@ class Quasi
@sessionId = null
@binds = []
@readyCallback = ->
- @socket = io.connect 'localhost'
+ @quasiSock = io.connect 'http://localhost/quasi'
+ @messagesSock = io.connect 'http://localhost/messages'
- @handleSocketMessages()
+ @handleQuasiSock()
+ @handleMessagesSock()
- handleSocketMessages: ->
- @socket.on 'message', (message) =>
- if message.name is 'quasi.hello'
- @sessionId = message.data.sessionId
- jQuery => @readyCallback()
- else
- for bind in @binds
- if bind.name is message.name
- bind.func.call @, message.data
- break
+ handleQuasiSock: ->
+ @quasiSock.on 'hello', (sessionId) =>
+ @sessionId = sessionId
+ jQuery => @readyCallback()
+
+ handleMessagesSock: ->
+ @messagesSock.on 'message', (message) =>
+ console.log 'message', message
+ for bind in @binds
+ if bind.name is message.name
+ bind.func.call @, message.data
+ break
ready: (func) ->
@readyCallback = func
trigger: (name, data) ->
- @socket.emit 'message'
+ @messagesSock.emit 'message'
name : name
data : data
sessionId: @sessionId
View
10 lib/quasi/index.coffee
@@ -11,13 +11,11 @@ executeFunc = (name, data) =>
func.func.call @, data
break
-io.sockets.on 'connection', (client) ->
+io.of('/quasi').on 'connection', (client) ->
clients.push client
-
- client.emit 'message'
- name: 'quasi.hello'
- data: { sessionId: client.id }
+ client.emit 'hello', client.id
+io.of('/messages').on 'connection', (client) ->
client.on 'message', (message) ->
executeFunc message.name, message.data if message.name
@@ -28,6 +26,6 @@ exports.bind = (name, func) ->
funcs.push { name: name, func: func }
exports.trigger = (name, data, sessionId) ->
- io.sockets.emit 'message'
+ io.of('/messages').emit 'message'
name: name
data: data

0 comments on commit 9b98c6b

Please sign in to comment.
Something went wrong with that request. Please try again.