diff options
author | Javan Makhmali <javan@javan.us> | 2015-10-14 17:06:21 -0500 |
---|---|---|
committer | Javan Makhmali <javan@javan.us> | 2015-10-14 17:06:21 -0500 |
commit | e07972711ed9e9404d4e6051c1ad23275a6d6645 (patch) | |
tree | 63fdbfd88276ef13103590c88c023cab26898aca /lib/assets/javascripts/cable | |
parent | 60d2f4becbf85bcecd243d9d0a529658d52b24fe (diff) | |
download | rails-e07972711ed9e9404d4e6051c1ad23275a6d6645.tar.gz rails-e07972711ed9e9404d4e6051c1ad23275a6d6645.tar.bz2 rails-e07972711ed9e9404d4e6051c1ad23275a6d6645.zip |
Improve guard against opening multiple web sockets
Diffstat (limited to 'lib/assets/javascripts/cable')
-rw-r--r-- | lib/assets/javascripts/cable/connection.coffee | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/assets/javascripts/cable/connection.coffee b/lib/assets/javascripts/cable/connection.coffee index 2259ddcedd..8256f731c5 100644 --- a/lib/assets/javascripts/cable/connection.coffee +++ b/lib/assets/javascripts/cable/connection.coffee @@ -10,12 +10,13 @@ class Cable.Connection else false - open: -> - if @isOpen() - throw new Error("Must close existing connection before opening") + open: => + if @webSocket and not @isState("closed") + throw new Error("Existing connection must be closed before opening") else @webSocket = new WebSocket(@consumer.url) @installEventHandlers() + true close: -> @webSocket?.close() |