diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-12-05 14:29:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-05 14:29:52 -0500 |
commit | d9816546494f66e76bd5012a91b872dc2096a06c (patch) | |
tree | 152ca7fc5496aedffeea9633c2c6a71a2c0fbfd3 /actioncable/app | |
parent | 884310fdd031ed8121944f9ea07c8b7723c4e6b6 (diff) | |
parent | 58dbc1c2ed0e372d9cae4c9e3baebb679a726dc3 (diff) | |
download | rails-d9816546494f66e76bd5012a91b872dc2096a06c.tar.gz rails-d9816546494f66e76bd5012a91b872dc2096a06c.tar.bz2 rails-d9816546494f66e76bd5012a91b872dc2096a06c.zip |
Merge pull request #34194 from staugaard/staugaard/actioncable_unauthorized
Stop trying to reconnect on unauthorized cable connections
Diffstat (limited to 'actioncable/app')
-rw-r--r-- | actioncable/app/assets/javascripts/action_cable.js | 14 | ||||
-rw-r--r-- | actioncable/app/javascript/action_cable/connection.js | 5 |
2 files changed, 17 insertions, 2 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable.js b/actioncable/app/assets/javascripts/action_cable.js index ee11c62eb6..65e32d6c3f 100644 --- a/actioncable/app/assets/javascripts/action_cable.js +++ b/actioncable/app/assets/javascripts/action_cable.js @@ -136,10 +136,16 @@ var INTERNAL = { message_types: { welcome: "welcome", + disconnect: "disconnect", ping: "ping", confirmation: "confirm_subscription", rejection: "reject_subscription" }, + disconnect_reasons: { + unauthorized: "unauthorized", + invalid_request: "invalid_request", + server_restart: "server_restart" + }, default_mount_path: "/cable", protocols: [ "actioncable-v1-json", "actioncable-unsupported" ] }; @@ -251,12 +257,18 @@ if (!this.isProtocolSupported()) { return; } - var _JSON$parse = JSON.parse(event.data), identifier = _JSON$parse.identifier, message = _JSON$parse.message, type = _JSON$parse.type; + var _JSON$parse = JSON.parse(event.data), identifier = _JSON$parse.identifier, message = _JSON$parse.message, reason = _JSON$parse.reason, reconnect = _JSON$parse.reconnect, type = _JSON$parse.type; switch (type) { case message_types.welcome: this.monitor.recordConnect(); return this.subscriptions.reload(); + case message_types.disconnect: + logger.log("Disconnecting. Reason: " + reason); + return this.close({ + allowReconnect: reconnect + }); + case message_types.ping: return this.monitor.recordPing(); diff --git a/actioncable/app/javascript/action_cable/connection.js b/actioncable/app/javascript/action_cable/connection.js index 8aa4fe1266..b2910cb2a6 100644 --- a/actioncable/app/javascript/action_cable/connection.js +++ b/actioncable/app/javascript/action_cable/connection.js @@ -117,11 +117,14 @@ Connection.reopenDelay = 500 Connection.prototype.events = { message(event) { if (!this.isProtocolSupported()) { return } - const {identifier, message, type} = JSON.parse(event.data) + const {identifier, message, reason, reconnect, type} = JSON.parse(event.data) switch (type) { case message_types.welcome: this.monitor.recordConnect() return this.subscriptions.reload() + case message_types.disconnect: + logger.log(`Disconnecting. Reason: ${reason}`) + return this.close({allowReconnect: reconnect}) case message_types.ping: return this.monitor.recordPing() case message_types.confirmation: |