diff options
Diffstat (limited to 'actioncable/app/javascript/action_cable/connection.js')
-rw-r--r-- | actioncable/app/javascript/action_cable/connection.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/actioncable/app/javascript/action_cable/connection.js b/actioncable/app/javascript/action_cable/connection.js index 4ad436f2c0..8aa4fe1266 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 { @@ -86,8 +88,8 @@ class Connection { getState() { if (this.webSocket) { - for (let state in WebSocket) { - if (WebSocket[state] === this.webSocket.readyState) { + for (let state in adapters.WebSocket) { + if (adapters.WebSocket[state] === this.webSocket.readyState) { return state.toLowerCase() } } @@ -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") } } |