From e07972711ed9e9404d4e6051c1ad23275a6d6645 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Wed, 14 Oct 2015 17:06:21 -0500 Subject: Improve guard against opening multiple web sockets --- lib/assets/javascripts/cable/connection.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') 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() -- cgit v1.2.3