From d6f2000a67cc63aa67414c75ce77de671824ec52 Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Mon, 1 Feb 2016 04:31:03 +1030 Subject: Wrangle the asset build into something that sounds more general --- .../app/assets/javascripts/action_cable.coffee.erb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 actioncable/app/assets/javascripts/action_cable.coffee.erb (limited to 'actioncable/app/assets/javascripts/action_cable.coffee.erb') 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 -- cgit v1.2.3