From bd217b10db54c0d838cb0e67937a213026fe362d Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 25 Aug 2015 09:51:32 +0000 Subject: [PATCH 1/2] 'Trying to reconnect..' in UI even though its connected --- client/app/scripts/actions/app-actions.js | 6 ++++++ client/app/scripts/constants/action-types.js | 1 + client/app/scripts/stores/app-store.js | 5 +++++ client/app/scripts/utils/web-api-utils.js | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/client/app/scripts/actions/app-actions.js b/client/app/scripts/actions/app-actions.js index 3db3b7c26..943f6453f 100644 --- a/client/app/scripts/actions/app-actions.js +++ b/client/app/scripts/actions/app-actions.js @@ -30,6 +30,12 @@ module.exports = { WebapiUtils.getNodesDelta(AppStore.getCurrentTopologyUrl()); }, + openWebsocket: function() { + AppDispatcher.dispatch({ + type: ActionTypes.OPEN_WEBSOCKET + }); + }, + closeWebsocket: function() { AppDispatcher.dispatch({ type: ActionTypes.CLOSE_WEBSOCKET diff --git a/client/app/scripts/constants/action-types.js b/client/app/scripts/constants/action-types.js index bf9234a95..663433ecf 100644 --- a/client/app/scripts/constants/action-types.js +++ b/client/app/scripts/constants/action-types.js @@ -4,6 +4,7 @@ module.exports = keymirror({ CLICK_CLOSE_DETAILS: null, CLICK_NODE: null, CLICK_TOPOLOGY: null, + OPEN_WEBSOCKER: null, CLOSE_WEBSOCKET: null, ENTER_EDGE: null, ENTER_NODE: null, diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index 1f5204166..83f4e76fd 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -157,6 +157,11 @@ AppStore.registeredCallback = function(payload) { AppStore.emit(AppStore.CHANGE_EVENT); break; + case ActionTypes.OPEN_WEBSOCKET: + websocketClosed = false; + AppStore.emit(AppStore.CHANGE_EVENT); + break; + case ActionTypes.CLOSE_WEBSOCKET: websocketClosed = true; AppStore.emit(AppStore.CHANGE_EVENT); diff --git a/client/app/scripts/utils/web-api-utils.js b/client/app/scripts/utils/web-api-utils.js index 4add414e7..4400e9033 100644 --- a/client/app/scripts/utils/web-api-utils.js +++ b/client/app/scripts/utils/web-api-utils.js @@ -26,6 +26,10 @@ function createWebsocket(topologyUrl) { socket = new WebSocket(WS_URL + topologyUrl + '/ws?t=' + updateFrequency); + socket.onopen = function() { + AppActions.openWebsocket(); + }; + socket.onclose = function() { clearTimeout(reconnectTimer); socket = null; From 1dccca2be76c7bdbc512b4edf91151245d31d775 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Fri, 28 Aug 2015 13:10:58 +0200 Subject: [PATCH 2/2] fixed action name typo and added test --- client/app/scripts/constants/action-types.js | 2 +- .../stores/__tests__/app-store-test.js | 7 +++++++ client/app/scripts/stores/app-store.js | 19 ++++++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/client/app/scripts/constants/action-types.js b/client/app/scripts/constants/action-types.js index 663433ecf..2450cbccd 100644 --- a/client/app/scripts/constants/action-types.js +++ b/client/app/scripts/constants/action-types.js @@ -4,13 +4,13 @@ module.exports = keymirror({ CLICK_CLOSE_DETAILS: null, CLICK_NODE: null, CLICK_TOPOLOGY: null, - OPEN_WEBSOCKER: null, CLOSE_WEBSOCKET: null, ENTER_EDGE: null, ENTER_NODE: null, HIT_ESC_KEY: null, LEAVE_EDGE: null, LEAVE_NODE: null, + OPEN_WEBSOCKET: null, RECEIVE_NODE_DETAILS: null, RECEIVE_NODES: null, RECEIVE_NODES_DELTA: null, diff --git a/client/app/scripts/stores/__tests__/app-store-test.js b/client/app/scripts/stores/__tests__/app-store-test.js index aa71805f0..de0adf6f0 100644 --- a/client/app/scripts/stores/__tests__/app-store-test.js +++ b/client/app/scripts/stores/__tests__/app-store-test.js @@ -39,6 +39,10 @@ describe('AppStore', function() { type: ActionTypes.HIT_ESC_KEY }; + const OpenWebsocketAction = { + type: ActionTypes.OPEN_WEBSOCKET + }; + const ReceiveEmptyNodesDeltaAction = { type: ActionTypes.RECEIVE_NODES_DELTA, delta: {} @@ -170,6 +174,9 @@ describe('AppStore', function() { expect(AppStore.isWebsocketClosed()).toBeTruthy(); expect(AppStore.getNodes()).toEqual(NODE_SET); + registeredCallback(OpenWebsocketAction); + expect(AppStore.isWebsocketClosed()).toBeFalsy(); + registeredCallback(ReceiveEmptyNodesDeltaAction); expect(AppStore.getNodes()).toEqual({}); }); diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index 83f4e76fd..08731fed9 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -157,11 +157,6 @@ AppStore.registeredCallback = function(payload) { AppStore.emit(AppStore.CHANGE_EVENT); break; - case ActionTypes.OPEN_WEBSOCKET: - websocketClosed = false; - AppStore.emit(AppStore.CHANGE_EVENT); - break; - case ActionTypes.CLOSE_WEBSOCKET: websocketClosed = true; AppStore.emit(AppStore.CHANGE_EVENT); @@ -193,6 +188,14 @@ AppStore.registeredCallback = function(payload) { AppStore.emit(AppStore.CHANGE_EVENT); break; + case ActionTypes.OPEN_WEBSOCKET: + // flush nodes cache after re-connect + nodes = {}; + websocketClosed = false; + + AppStore.emit(AppStore.CHANGE_EVENT); + break; + case ActionTypes.RECEIVE_ERROR: errorUrl = payload.errorUrl; AppStore.emit(AppStore.CHANGE_EVENT); @@ -212,12 +215,6 @@ AppStore.registeredCallback = function(payload) { errorUrl = null; - // flush nodes cache after re-connect - if (websocketClosed) { - nodes = {}; - } - websocketClosed = false; - // nodes that no longer exist _.each(payload.delta.remove, function(nodeId) { // in case node disappears before mouseleave event