aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/assets/javascripts/action_cable.coffee.erb
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.coffee.erb
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.coffee.erb')
-rw-r--r--actioncable/lib/assets/javascripts/action_cable.coffee.erb23
1 files changed, 23 insertions, 0 deletions
diff --git a/actioncable/lib/assets/javascripts/action_cable.coffee.erb b/actioncable/lib/assets/javascripts/action_cable.coffee.erb
new file mode 100644
index 0000000000..7daea4ebcd
--- /dev/null
+++ b/actioncable/lib/assets/javascripts/action_cable.coffee.erb
@@ -0,0 +1,23 @@
+#= require_self
+#= require action_cable/consumer
+
+@ActionCable =
+ INTERNAL: <%= ActionCable::INTERNAL.to_json %>
+
+ createConsumer: (url = @getConfig("url")) ->
+ new ActionCable.Consumer @createWebSocketURL(url)
+
+ getConfig: (name) ->
+ element = document.head.querySelector("meta[name='action-cable-#{name}']")
+ element?.getAttribute("content")
+
+ createWebSocketURL: (url) ->
+ if url and not /^wss?:/i.test(url)
+ a = document.createElement("a")
+ a.href = url
+ # Fix populating Location properties in IE. Otherwise, protocol will be blank.
+ a.href = a.href
+ a.protocol = a.protocol.replace("http", "ws")
+ a.href
+ else
+ url