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

View File

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

View File

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

View File

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