aboutsummaryrefslogtreecommitdiffstats
path: root/lib/assets/javascripts/cable/consumer.js.coffee
blob: 27314ee5081e7806307a7f1ad29cd9d5b21a96ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#= require cable/connection
#= require cable/connection_monitor
#= require cable/subscription
#= require cable/subscriber_manager

class Cable.Consumer
  constructor: (@url) ->
    @subscribers = new Cable.SubscriberManager this
    @connection = new Cable.Connection this
    @connectionMonitor = new Cable.ConnectionMonitor this

  createSubscription: (channelName, mixin) ->
    channel = channelName
    params = if typeof channel is "object" then channel else {channel}
    new Cable.Subscription this, params, mixin

  send: (data) ->
    @connection.send(data)

  inspect: ->
    JSON.stringify(this, null, 2)

  toJSON: ->
    {@url, @subscribers, @connection, @connectionMonitor}