aboutsummaryrefslogblamecommitdiffstats
path: root/actioncable/app/assets/javascripts/action_cable.coffee.erb
blob: 18a48c0610add10f7e106c3a1e066a1ad69fead8 (plain) (tree)
1
2
3
4
5
6
7
8
               
                                  
 
              

                                                
                                              
                                                     



                                                                              










                                                                                    
#= 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