From 6516e9bf6801f7c9ec247b2397503a834c93d790 Mon Sep 17 00:00:00 2001
From: JoramWilander <jwawilander@gmail.com>
Date: Thu, 24 Mar 2016 20:12:36 -0400
Subject: Fix websocket trying to reconnect after a logout

---
 webapp/action_creators/websocket_actions.jsx | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

(limited to 'webapp/action_creators/websocket_actions.jsx')

diff --git a/webapp/action_creators/websocket_actions.jsx b/webapp/action_creators/websocket_actions.jsx
index 611d53bf7..009bb9e96 100644
--- a/webapp/action_creators/websocket_actions.jsx
+++ b/webapp/action_creators/websocket_actions.jsx
@@ -21,6 +21,7 @@ const WEBSOCKET_RETRY_TIME = 3000;
 var conn = null;
 var connectFailCount = 0;
 var pastFirstInit = false;
+var manuallyClosed = false;
 
 export function initialize() {
     if (window.WebSocket && !conn) {
@@ -35,6 +36,8 @@ export function initialize() {
             console.log('websocket connecting to ' + connUrl); //eslint-disable-line no-console
         }
 
+        manuallyClosed = false;
+
         conn = new WebSocket(connUrl);
 
         conn.onopen = () => {
@@ -69,12 +72,14 @@ export function initialize() {
             ErrorStore.setConnectionErrorCount(connectFailCount);
             ErrorStore.emitChange();
 
-            setTimeout(
-                () => {
-                    initialize();
-                },
-                WEBSOCKET_RETRY_TIME
-            );
+            if (!manuallyClosed) {
+                setTimeout(
+                    () => {
+                        initialize();
+                    },
+                    WEBSOCKET_RETRY_TIME
+                );
+            }
         };
 
         conn.onerror = (evt) => {
@@ -147,6 +152,7 @@ export function sendMessage(msg) {
 }
 
 export function close() {
+    manuallyClosed = true;
     if (conn && conn.readyState === WebSocket.OPEN) {
         conn.close();
     }
-- 
cgit v1.2.3-1-g7c22

