mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
66901c1849
[Javan Makhmali, Jon Moss]
38 lines
1,004 B
Text
38 lines
1,004 B
Text
#= export ActionCable
|
|
#= require_self
|
|
#= require ./action_cable/consumer
|
|
|
|
@ActionCable =
|
|
INTERNAL: <%= ActionCable::INTERNAL.to_json %>
|
|
WebSocket: window.WebSocket
|
|
logger: window.console
|
|
|
|
createConsumer: (url) ->
|
|
url ?= @getConfig("url") ? @INTERNAL.default_mount_path
|
|
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
|
|
|
|
startDebugging: ->
|
|
@debugging = true
|
|
|
|
stopDebugging: ->
|
|
@debugging = null
|
|
|
|
log: (messages...) ->
|
|
if @debugging
|
|
messages.push(Date.now())
|
|
@logger.log("[ActionCable]", messages...)
|