         publisher: from
         payload: JSON.parse payload.text()
         node: node
-      sub obj for sub in @subscribers
+      sub obj for sub in @listeners
     true # keep handler alive

class Channel
  constructor: (@name, @app) ->
    @pubsub = new PubSub @app.vines.xmpp, @app.pubsub, @name
    @subscribers = []
    @subscription = null

  subscribe: (fn) ->
    @subscribers.push fn
    @subscription ||= @app.vines.xmpp.addHandler(
      ((node) => this.notify node), null, 'message', null, null, @app.pubsub)
    @pubsub.create()

    @pubsub.publish obj

  unsubscribe: ->
    @listeners = []
    @app.vines.xmpp.deleteHandler @subscription
    @subscription = null
    @pubsub.unsubscribe()

  remove: ->
    this.unsubscribe()
    @pubsub.remove()

  notify: (node) ->
    node    = $ node
