aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/app/javascript/action_cable/connection.js
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/app/javascript/action_cable/connection.js')
-rw-r--r--actioncable/app/javascript/action_cable/connection.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/actioncable/app/javascript/action_cable/connection.js b/actioncable/app/javascript/action_cable/connection.js
index 4ad436f2c0..e3ff8bde24 100644
--- a/actioncable/app/javascript/action_cable/connection.js
+++ b/actioncable/app/javascript/action_cable/connection.js
@@ -1,5 +1,7 @@
-import ActionCable from "./index"
+import adapters from "./adapters"
+import ConnectionMonitor from "./connection_monitor"
import INTERNAL from "./internal"
+import logger from "./logger"
// Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation.
@@ -13,7 +15,7 @@ class Connection {
this.open = this.open.bind(this)
this.consumer = consumer
this.subscriptions = this.consumer.subscriptions
- this.monitor = new ActionCable.ConnectionMonitor(this)
+ this.monitor = new ConnectionMonitor(this)
this.disconnected = true
}
@@ -28,12 +30,12 @@ class Connection {
open() {
if (this.isActive()) {
- ActionCable.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`)
+ logger.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`)
return false
} else {
- ActionCable.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${protocols}`)
+ logger.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${protocols}`)
if (this.webSocket) { this.uninstallEventHandlers() }
- this.webSocket = new ActionCable.WebSocket(this.consumer.url, protocols)
+ this.webSocket = new adapters.WebSocket(this.consumer.url, protocols)
this.installEventHandlers()
this.monitor.start()
return true
@@ -46,15 +48,15 @@ class Connection {
}
reopen() {
- ActionCable.log(`Reopening WebSocket, current state is ${this.getState()}`)
+ logger.log(`Reopening WebSocket, current state is ${this.getState()}`)
if (this.isActive()) {
try {
return this.close()
} catch (error) {
- ActionCable.log("Failed to reopen WebSocket", error)
+ logger.log("Failed to reopen WebSocket", error)
}
finally {
- ActionCable.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`)
+ logger.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`)
setTimeout(this.open, this.constructor.reopenDelay)
}
} else {
@@ -132,16 +134,16 @@ Connection.prototype.events = {
},
open() {
- ActionCable.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`)
+ logger.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`)
this.disconnected = false
if (!this.isProtocolSupported()) {
- ActionCable.log("Protocol is unsupported. Stopping monitor and disconnecting.")
+ logger.log("Protocol is unsupported. Stopping monitor and disconnecting.")
return this.close({allowReconnect: false})
}
},
close(event) {
- ActionCable.log("WebSocket onclose event")
+ logger.log("WebSocket onclose event")
if (this.disconnected) { return }
this.disconnected = true
this.monitor.recordDisconnect()
@@ -149,7 +151,7 @@ Connection.prototype.events = {
},
error() {
- ActionCable.log("WebSocket onerror event")
+ logger.log("WebSocket onerror event")
}
}