Skip to content

Commit

Permalink
consolidate channel code
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Jul 25, 2012
1 parent d44679b commit 503a2b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 48 deletions.
44 changes: 0 additions & 44 deletions client/Channel.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion client/Pulsar.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
isBrowser = typeof window isnt 'undefined'
eio = require (if isBrowser then 'node_modules/engine.io-client/lib/engine.io-client' else 'engine.io-client')
Channel = require './Channel'
Channel = require '../lib/Channel'

class Pulsar extends eio.EventEmitter
constructor: (@options={}) ->
Expand Down
17 changes: 14 additions & 3 deletions lib/Channel.coffee
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
class Channel
constructor: (@name) ->
constructor: (@name, @socket) ->
@listeners = []
@events = {}
if @socket?
@socket.send JSON.stringify
channel: @name
action: 'join'

realEmit: (event, args...) =>
return false unless @events[event]
l args... for l in @events[event]
return true

emit: (event, args...) =>
for socket in @listeners
socket.send JSON.stringify
return false unless @socket? or @listeners?
if @socket?
@socket.send JSON.stringify
channel: @name
event: event
args: args
else
for socket in @listeners
socket.send JSON.stringify
channel: @name
event: event
args: args
return true

addListener: (event, listener) =>
Expand Down

0 comments on commit 503a2b4

Please sign in to comment.