mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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:
commit
481192171e
4 changed files with 12 additions and 12 deletions
|
@ -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");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export default {
|
||||
logger: window.console,
|
||||
WebSocket: window.WebSocket
|
||||
logger: self.console,
|
||||
WebSocket: self.WebSocket
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue