#= require_self
#= require cable/consumer

@Cable =
  INTERNAL: <%= ActionCable::INTERNAL.to_json %>

  createConsumer: (url = @getConfig("url")) ->
    new Cable.Consumer webSocketURL(url)

  getConfig: (name) ->
    element = document.head.querySelector("meta[name='action-cable-#{name}']")
    element?.getAttribute("content")

  webSocketURL = (url) ->
    if url and not /^wss?:/i.test(url)
      a = document.createElement("a")
      a.href = url
      # in internet explorer, the next line properly populates the protocol
      a.href = a.href
      a.protocol = a.protocol.replace("http", "ws")
      a.href
    else
      url

#= require_self
#= require cable/consumer

@Cable =
  INTERNAL: <%= ActionCable::INTERNAL.to_json %>

  createConsumer: (url = @getConfig("url")) ->
    new Cable.Consumer @webSocketURL(url)

  getConfig: (name) ->
    element = document.head.querySelector("meta[name='action-cable-#{name}']")
    element?.getAttribute("content")

  webSocketURL: (url) ->
    if url and not /^wss?:/i.test(url)
      a = document.createElement("a")
      a.href = url
      # in internet explorer, the next line properly populates the protocol
      a.href = a.href
      a.protocol = a.protocol.replace("http", "ws")
      a.href
    else
      url

Fix URL helper object property
Fix URL helper object property
