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) {
|
})(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");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default {
|
export default {
|
||||||
logger: window.console,
|
logger: self.console,
|
||||||
WebSocket: window.WebSocket
|
WebSocket: self.WebSocket
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue