aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/app/assets/javascripts/action_cable/consumer.coffee
diff options
context:
space:
mode:
authorDaniel Rhodes <rhodes.daniel@gmail.com>2016-03-17 15:05:06 +0100
committerDaniel Rhodes <rhodes.daniel@gmail.com>2016-04-05 15:55:59 +0200
commitcbd15da0274316bae64caae54880fee87853f480 (patch)
tree9911f491e182ab99d64351438f54e74cf21e24b8 /actioncable/app/assets/javascripts/action_cable/consumer.coffee
parent85119f5909db86167b8b4ed6916b5dda6d9462d5 (diff)
downloadrails-cbd15da0274316bae64caae54880fee87853f480.tar.gz
rails-cbd15da0274316bae64caae54880fee87853f480.tar.bz2
rails-cbd15da0274316bae64caae54880fee87853f480.zip
Added protocol negotiation
This is primarily for backwards compatibility for when or if the protocol is changed in future versions. If the server fails to respond with an acceptable protocol, the client disconnects and disables the monitor.
Diffstat (limited to 'actioncable/app/assets/javascripts/action_cable/consumer.coffee')
-rw-r--r--actioncable/app/assets/javascripts/action_cable/consumer.coffee19
1 files changed, 19 insertions, 0 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable/consumer.coffee b/actioncable/app/assets/javascripts/action_cable/consumer.coffee
index 7aae1ed8ed..3298be717f 100644
--- a/actioncable/app/assets/javascripts/action_cable/consumer.coffee
+++ b/actioncable/app/assets/javascripts/action_cable/consumer.coffee
@@ -14,6 +14,19 @@
# App.appearance = App.cable.subscriptions.create "AppearanceChannel"
#
# For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription.
+#
+# When a consumer is created, it automatically connects with the server.
+#
+# To disconnect from the server, call
+#
+# App.cable.disconnect()
+#
+# and to restart the connection:
+#
+# App.cable.connect()
+#
+# Any channel subscriptions which existed prior to disconnecting will
+# automatically resubscribe.
class ActionCable.Consumer
constructor: (@url) ->
@subscriptions = new ActionCable.Subscriptions this
@@ -22,6 +35,12 @@ class ActionCable.Consumer
send: (data) ->
@connection.send(data)
+ connect: ->
+ @connection.open()
+
+ disconnect: ->
+ @connection.close(allowReconnect: false)
+
ensureActiveConnection: ->
unless @connection.isActive()
@connection.open()