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;