From 42f94a112b296ea095190de711650edd7ebde202 Mon Sep 17 00:00:00 2001 From: StefanYohansson Date: Tue, 27 Dec 2016 11:25:35 -0300 Subject: [PATCH] [verto-communicator] - Added change server feature When someone set any wss server and do login VC doesn't record the settings on localStorage, so when we reload the browser, it will try to connect on "wss://" + window.location.hostname + ":8082" and if this wss server is offline for any reason, user will be stuck on splash screen by auto-login step plus reconnect modal blocking any action. - Added button "Change Server" on modal reconnection alert; - Stop jsonRpcClient retry timeout and delete verto instance to create a new one when user login with new wss server; - Record wss server and hostname on localStorage. --- html5/verto/js/src/jquery.jsonrpcclient.js | 5 +++++ .../src/partials/ws_reconnect.html | 2 +- .../src/storageService/services/splash_screen.js | 2 ++ .../vertoControllers/controllers/MainController.js | 14 ++++++++------ .../controllers/ModalWsReconnectController.js | 14 ++++++++++++-- .../src/vertoService/services/vertoService.js | 3 +-- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/html5/verto/js/src/jquery.jsonrpcclient.js b/html5/verto/js/src/jquery.jsonrpcclient.js index 6f4f07c72b..702998cc58 100644 --- a/html5/verto/js/src/jquery.jsonrpcclient.js +++ b/html5/verto/js/src/jquery.jsonrpcclient.js @@ -359,6 +359,11 @@ return self._ws_socket ? true : false; }; + $.JsonRpcClient.prototype.stopRetrying = function() { + if (self.to) + clearTimeout(self.to); + } + $.JsonRpcClient.prototype._getSocket = function(onmessage_cb) { // If there is no ws url set, we don't have a socket. // Likewise, if there is no window.WebSocket. diff --git a/html5/verto/verto_communicator/src/partials/ws_reconnect.html b/html5/verto/verto_communicator/src/partials/ws_reconnect.html index 7879b587f7..dbb2119c27 100644 --- a/html5/verto/verto_communicator/src/partials/ws_reconnect.html +++ b/html5/verto/verto_communicator/src/partials/ws_reconnect.html @@ -2,7 +2,7 @@ diff --git a/html5/verto/verto_communicator/src/storageService/services/splash_screen.js b/html5/verto/verto_communicator/src/storageService/services/splash_screen.js index 9aa4414bf5..a1330be0d6 100644 --- a/html5/verto/verto_communicator/src/storageService/services/splash_screen.js +++ b/html5/verto/verto_communicator/src/storageService/services/splash_screen.js @@ -143,6 +143,8 @@ * not connecting prevent two connects */ if (storage.data.ui_connected && storage.data.ws_connected && !verto.data.connecting) { + verto.data.hostname = storage.data.hostname || verto.data.hostname; + verto.data.wsURL = storage.data.wsURL || verto.data.wsURL; verto.data.name = storage.data.name; verto.data.email = storage.data.email; verto.data.login = storage.data.login; diff --git a/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js b/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js index 877b8f7836..7fc9877e46 100644 --- a/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js +++ b/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js @@ -79,6 +79,8 @@ $scope.$apply(function() { verto.data.connecting = false; if (connected) { + storage.data.hostname = verto.data.hostname; + storage.data.wsURL = verto.data.wsURL; storage.data.ui_connected = verto.data.connected; storage.data.ws_connected = verto.data.connected; storage.data.name = verto.data.name; @@ -200,10 +202,10 @@ $rootScope.$on('ws.close', onWSClose); $rootScope.$on('ws.login', onWSLogin); - var ws_modalInstance; + $rootScope.ws_modalInstance; function onWSClose(ev, data) { - if(ws_modalInstance) { + if($rootScope.ws_modalInstance) { return; }; var options = { @@ -211,7 +213,7 @@ keyboard: false }; if ($scope.showReconnectModal) { - ws_modalInstance = $scope.openModal('partials/ws_reconnect.html', 'ModalWsReconnectController', options); + $rootScope.ws_modalInstance = $scope.openModal('partials/ws_reconnect.html', 'ModalWsReconnectController', options); }; }; @@ -219,12 +221,12 @@ if(storage.data.autoBand) { verto.testSpeed(); } - if(!ws_modalInstance) { + if(!$rootScope.ws_modalInstance) { return; }; - ws_modalInstance.close(); - ws_modalInstance = null; + $rootScope.ws_modalInstance.close(); + $rootScope.ws_modalInstance = null; }; $scope.showAbout = function() { diff --git a/html5/verto/verto_communicator/src/vertoControllers/controllers/ModalWsReconnectController.js b/html5/verto/verto_communicator/src/vertoControllers/controllers/ModalWsReconnectController.js index 374ad18c8d..6536e2f2ca 100644 --- a/html5/verto/verto_communicator/src/vertoControllers/controllers/ModalWsReconnectController.js +++ b/html5/verto/verto_communicator/src/vertoControllers/controllers/ModalWsReconnectController.js @@ -5,10 +5,20 @@ .module('vertoControllers') .controller('ModalWsReconnectController', ModalWsReconnectController); - ModalWsReconnectController.$inject = ['$scope', 'storage', 'verto']; + ModalWsReconnectController.$inject = ['$rootScope', '$scope', 'storage', 'verto']; - function ModalWsReconnectController($scope, storage, verto) { + function ModalWsReconnectController($rootScope, $scope, storage, verto) { console.debug('Executing ModalWsReconnectController'); + + $scope.closeReconnect = closeReconnect; + + function closeReconnect() { + if ($rootScope.ws_modalInstance && verto.data.instance) { + verto.data.instance.rpcClient.stopRetrying(); + $rootScope.ws_modalInstance.close(); + delete verto.data.instance; + } + }; }; diff --git a/html5/verto/verto_communicator/src/vertoService/services/vertoService.js b/html5/verto/verto_communicator/src/vertoService/services/vertoService.js index c5c2fd9025..6b139be0c1 100644 --- a/html5/verto/verto_communicator/src/vertoService/services/vertoService.js +++ b/html5/verto/verto_communicator/src/vertoService/services/vertoService.js @@ -698,7 +698,7 @@ vertoService.service('verto', ['$rootScope', '$cookieStore', '$location', 'stora // Checking if we have a failed connection attempt before // connecting again. if (data.instance && !data.instance.rpcClient.socketReady()) { - clearTimeout(data.instance.rpcClient.to); + data.instance.rpcClient.stopRetrying(); data.instance.logout(); data.instance.login(); return; @@ -736,7 +736,6 @@ vertoService.service('verto', ['$rootScope', '$cookieStore', '$location', 'stora onResCheck: that.refreshVideoResolution }); } - if (data.mediaPerm) { ourBootstrap(); } else {