Merge pull request #34941 from rmacklin/allow-actioncable-to-run-in-web-workers

Avoid ReferenceError exceptions if ActionCable is used in a web worker
This commit is contained in:
Javan Makhmali 2019-01-16 17:10:57 -05:00 committed by GitHub
commit 481192171e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 12 deletions

View File

@ -3,8 +3,8 @@
})(this, function(exports) { })(this, function(exports) {
"use strict"; "use strict";
var adapters = { var adapters = {
logger: window.console, logger: self.console,
WebSocket: window.WebSocket WebSocket: self.WebSocket
}; };
var logger = { var logger = {
log: function log() { log: function log() {
@ -49,7 +49,7 @@
this.startedAt = now(); this.startedAt = now();
delete this.stoppedAt; delete this.stoppedAt;
this.startPolling(); this.startPolling();
document.addEventListener("visibilitychange", this.visibilityDidChange); addEventListener("visibilitychange", this.visibilityDidChange);
logger.log("ConnectionMonitor started. pollInterval = " + this.getPollInterval() + " ms"); logger.log("ConnectionMonitor started. pollInterval = " + this.getPollInterval() + " ms");
} }
}; };
@ -57,7 +57,7 @@
if (this.isRunning()) { if (this.isRunning()) {
this.stoppedAt = now(); this.stoppedAt = now();
this.stopPolling(); this.stopPolling();
document.removeEventListener("visibilitychange", this.visibilityDidChange); removeEventListener("visibilitychange", this.visibilityDidChange);
logger.log("ConnectionMonitor stopped"); logger.log("ConnectionMonitor stopped");
} }
}; };

View File

@ -1,4 +1,4 @@
export default { export default {
logger: window.console, logger: self.console,
WebSocket: window.WebSocket WebSocket: self.WebSocket
} }

View File

@ -21,7 +21,7 @@ class ConnectionMonitor {
this.startedAt = now() this.startedAt = now()
delete this.stoppedAt delete this.stoppedAt
this.startPolling() this.startPolling()
document.addEventListener("visibilitychange", this.visibilityDidChange) addEventListener("visibilitychange", this.visibilityDidChange)
logger.log(`ConnectionMonitor started. pollInterval = ${this.getPollInterval()} ms`) logger.log(`ConnectionMonitor started. pollInterval = ${this.getPollInterval()} ms`)
} }
} }
@ -30,7 +30,7 @@ class ConnectionMonitor {
if (this.isRunning()) { if (this.isRunning()) {
this.stoppedAt = now() this.stoppedAt = now()
this.stopPolling() this.stopPolling()
document.removeEventListener("visibilitychange", this.visibilityDidChange) removeEventListener("visibilitychange", this.visibilityDidChange)
logger.log("ConnectionMonitor stopped") logger.log("ConnectionMonitor stopped")
} }
} }

View File

@ -6,14 +6,14 @@ const {module, test} = QUnit
module("ActionCable", () => { module("ActionCable", () => {
module("Adapters", () => { module("Adapters", () => {
module("WebSocket", () => { module("WebSocket", () => {
test("default is window.WebSocket", assert => { test("default is self.WebSocket", assert => {
assert.equal(ActionCable.adapters.WebSocket, window.WebSocket) assert.equal(ActionCable.adapters.WebSocket, self.WebSocket)
}) })
}) })
module("logger", () => { module("logger", () => {
test("default is window.console", assert => { test("default is self.console", assert => {
assert.equal(ActionCable.adapters.logger, window.console) assert.equal(ActionCable.adapters.logger, self.console)
}) })
}) })
}) })