diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-02 02:57:38 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-02 02:57:38 -0300 |
commit | eb8c713c987480e7a0362ae3de617ba0c0f27d7f (patch) | |
tree | 7f5b9afd7a6326161c75270701f1e880e4f20263 /lib/assets/javascripts/cable/consumer.coffee | |
parent | 0cf1db6be29fb2269d722bedd690641e0f949b36 (diff) | |
download | rails-eb8c713c987480e7a0362ae3de617ba0c0f27d7f.tar.gz rails-eb8c713c987480e7a0362ae3de617ba0c0f27d7f.tar.bz2 rails-eb8c713c987480e7a0362ae3de617ba0c0f27d7f.zip |
.js.coffee -> .coffee
It was initially required, but support for the shorthand has been
supported since sprockets 2.1. Eventually 4.x will only support the
shorthand version. Just want to get new people using the prefer stuff
ASAP.
Diffstat (limited to 'lib/assets/javascripts/cable/consumer.coffee')
-rw-r--r-- | lib/assets/javascripts/cable/consumer.coffee | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/assets/javascripts/cable/consumer.coffee b/lib/assets/javascripts/cable/consumer.coffee new file mode 100644 index 0000000000..05a7398e79 --- /dev/null +++ b/lib/assets/javascripts/cable/consumer.coffee @@ -0,0 +1,31 @@ +#= require cable/connection +#= require cable/connection_monitor +#= require cable/subscriptions +#= require cable/subscription + +# The Cable.Consumer establishes the connection to a server-side Ruby Connection object. Once established, +# the Cable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates. +# The Consumer instance is also the gateway to establishing subscriptions to desired channels through the #createSubscription +# method. +# +# The following example shows how this can be setup: +# +# @App = {} +# App.cable = Cable.createConsumer "ws://example.com/accounts/1" +# App.appearance = App.cable.subscriptions.create "AppearanceChannel" +# +# For more details on how you'd configure an actual channel subscription, see Cable.Subscription. +class Cable.Consumer + constructor: (@url) -> + @subscriptions = new Cable.Subscriptions this + @connection = new Cable.Connection this + @connectionMonitor = new Cable.ConnectionMonitor this + + send: (data) -> + @connection.send(data) + + inspect: -> + JSON.stringify(this, null, 2) + + toJSON: -> + {@url, @subscriptions, @connection, @connectionMonitor} |