aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/app/assets/javascripts/action_cable.coffee.erb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-02-01 04:31:03 +1030
committerMatthew Draper <matthew@trebex.net>2016-02-01 05:03:03 +1030
commitd6f2000a67cc63aa67414c75ce77de671824ec52 (patch)
tree86ddb70130bc3d40fb0a9aeb125108f47b8e07b1 /actioncable/app/assets/javascripts/action_cable.coffee.erb
parentca9603fc35d123d1c8490096dc0447a91f3e3c18 (diff)
downloadrails-d6f2000a67cc63aa67414c75ce77de671824ec52.tar.gz
rails-d6f2000a67cc63aa67414c75ce77de671824ec52.tar.bz2
rails-d6f2000a67cc63aa67414c75ce77de671824ec52.zip
Wrangle the asset build into something that sounds more general
Diffstat (limited to 'actioncable/app/assets/javascripts/action_cable.coffee.erb')
-rw-r--r--actioncable/app/assets/javascripts/action_cable.coffee.erb23
1 files changed, 23 insertions, 0 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable.coffee.erb b/actioncable/app/assets/javascripts/action_cable.coffee.erb
new file mode 100644
index 0000000000..18a48c0610
--- /dev/null
+++ b/actioncable/app/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