aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/assets/javascripts/cable.coffee.erb
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/lib/assets/javascripts/cable.coffee.erb')
-rw-r--r--actioncable/lib/assets/javascripts/cable.coffee.erb13
1 files changed, 12 insertions, 1 deletions
diff --git a/actioncable/lib/assets/javascripts/cable.coffee.erb b/actioncable/lib/assets/javascripts/cable.coffee.erb
index 25a9fc79c2..a722f27ac1 100644
--- a/actioncable/lib/assets/javascripts/cable.coffee.erb
+++ b/actioncable/lib/assets/javascripts/cable.coffee.erb
@@ -5,8 +5,19 @@
INTERNAL: <%= ActionCable::INTERNAL.to_json %>
createConsumer: (url = @getConfig("url")) ->
- new Cable.Consumer url
+ new Cable.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