From bd217b10db54c0d838cb0e67937a213026fe362d Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 25 Aug 2015 09:51:32 +0000 Subject: [PATCH] '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;