diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-05-27 13:07:13 -0400 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-05-31 13:06:08 -0400 |
commit | 66901c1849efae74c8a58fe0cb36afd487c067cc (patch) | |
tree | ee8c16cfe1668d937fc6f04cf450e9e7f7aacc78 | |
parent | 998bbbcc0e043e16b96613387cdb8f0ee4784ff2 (diff) | |
download | rails-66901c1849efae74c8a58fe0cb36afd487c067cc.tar.gz rails-66901c1849efae74c8a58fe0cb36afd487c067cc.tar.bz2 rails-66901c1849efae74c8a58fe0cb36afd487c067cc.zip |
Add configuration for `WebSocket` and `logger`
[Javan Makhmali, Jon Moss]
4 files changed, 22 insertions, 6 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable.coffee.erb b/actioncable/app/assets/javascripts/action_cable.coffee.erb index 210a3ae17e..e0758dae72 100644 --- a/actioncable/app/assets/javascripts/action_cable.coffee.erb +++ b/actioncable/app/assets/javascripts/action_cable.coffee.erb @@ -4,6 +4,8 @@ @ActionCable = INTERNAL: <%= ActionCable::INTERNAL.to_json %> + WebSocket: window.WebSocket + logger: window.console createConsumer: (url) -> url ?= @getConfig("url") ? @INTERNAL.default_mount_path @@ -33,4 +35,4 @@ log: (messages...) -> if @debugging messages.push(Date.now()) - console.log("[ActionCable]", messages...) + @logger.log("[ActionCable]", messages...) diff --git a/actioncable/app/assets/javascripts/action_cable/connection.coffee b/actioncable/app/assets/javascripts/action_cable/connection.coffee index d6a6397804..29ad676290 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee @@ -27,7 +27,7 @@ class ActionCable.Connection else ActionCable.log("Opening WebSocket, current state is #{@getState()}, subprotocols: #{protocols}") @uninstallEventHandlers() if @webSocket? - @webSocket = new WebSocket(@consumer.url, protocols) + @webSocket = new ActionCable.WebSocket(@consumer.url, protocols) @installEventHandlers() @monitor.start() true diff --git a/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee b/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee index b7f86f18f6..6508984c37 100644 --- a/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee +++ b/actioncable/test/javascript/src/test_helpers/mock_websocket.coffee @@ -1,12 +1,10 @@ #= require mock-socket -NativeWebSocket = window.WebSocket - server = null consumer = null ActionCable.TestHelpers.createConsumer = (url, callback) -> - window.WebSocket = MockWebSocket + ActionCable.WebSocket = MockWebSocket server = new MockServer url consumer = ActionCable.createConsumer(url) callback(consumer, server) @@ -18,4 +16,3 @@ QUnit.testDone -> if server? server.clients().forEach (client) -> client.close() server.close() - window.WebSocket = NativeWebSocket diff --git a/actioncable/test/javascript/src/unit/action_cable_test.coffee b/actioncable/test/javascript/src/unit/action_cable_test.coffee index f9eff64769..3944f3a7f6 100644 --- a/actioncable/test/javascript/src/unit/action_cable_test.coffee +++ b/actioncable/test/javascript/src/unit/action_cable_test.coffee @@ -2,6 +2,23 @@ {testURL} = ActionCable.TestHelpers module "ActionCable", -> + module "Adapters", -> + module "WebSocket", -> + test "default is window.WebSocket", (assert) -> + assert.equal ActionCable.WebSocket, window.WebSocket + + test "configurable", (assert) -> + ActionCable.WebSocket = "" + assert.equal ActionCable.WebSocket, "" + + module "logger", -> + test "default is window.console", (assert) -> + assert.equal ActionCable.logger, window.console + + test "configurable", (assert) -> + ActionCable.logger = "" + assert.equal ActionCable.logger, "" + module "#createConsumer", -> test "uses specified URL", (assert) -> consumer = ActionCable.createConsumer(testURL) |