aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/assets/javascripts/action_cable/consumer.coffee
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2015-12-16 15:29:21 +0100
committerDavid Heinemeier Hansson <david@loudthinking.com>2015-12-16 15:29:21 +0100
commit26bcf81a01bfe12e9f2ef06e4ea84e9e5fa02f9c (patch)
tree039e3cdd2794742d7ecfb0e422a0b3f12410a6f7 /actioncable/lib/assets/javascripts/action_cable/consumer.coffee
parent346a7528eff8aabc9618d0b20a32b36f218d8b2f (diff)
downloadrails-26bcf81a01bfe12e9f2ef06e4ea84e9e5fa02f9c.tar.gz
rails-26bcf81a01bfe12e9f2ef06e4ea84e9e5fa02f9c.tar.bz2
rails-26bcf81a01bfe12e9f2ef06e4ea84e9e5fa02f9c.zip
Move Cable to ActionCable for client-side constant to avoid conflicts
Diffstat (limited to 'actioncable/lib/assets/javascripts/action_cable/consumer.coffee')
-rw-r--r--actioncable/lib/assets/javascripts/action_cable/consumer.coffee31
1 files changed, 31 insertions, 0 deletions
diff --git a/actioncable/lib/assets/javascripts/action_cable/consumer.coffee b/actioncable/lib/assets/javascripts/action_cable/consumer.coffee
new file mode 100644
index 0000000000..5cf8978d77
--- /dev/null
+++ b/actioncable/lib/assets/javascripts/action_cable/consumer.coffee
@@ -0,0 +1,31 @@
+#= require action_cable/connection
+#= require action_cable/connection_monitor
+#= require action_cable/subscriptions
+#= require action_cable/subscription
+
+# The ActionCable.Consumer establishes the connection to a server-side Ruby Connection object. Once established,
+# the ActionCable.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 = ActionCable.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 ActionCable.Subscription.
+class ActionCable.Consumer
+ constructor: (@url) ->
+ @subscriptions = new ActionCable.Subscriptions this
+ @connection = new ActionCable.Connection this
+ @connectionMonitor = new ActionCable.ConnectionMonitor this
+
+ send: (data) ->
+ @connection.send(data)
+
+ inspect: ->
+ JSON.stringify(this, null, 2)
+
+ toJSON: ->
+ {@url, @subscriptions, @connection, @connectionMonitor}