summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Roychowdhury <pliablepixels@gmail.com>2015-10-09 14:30:59 -0400
committerArjun Roychowdhury <pliablepixels@gmail.com>2015-10-09 14:30:59 -0400
commit7b0d282994db52cc4bc6b62b33ce05efbb522fae (patch)
tree4c5a456667fdcfe7cd19f804fbc910c3c1eeb9d2
parentf6b0db446db4a45df20be3efd2851dac256d7876 (diff)
websocket handling improved
-rw-r--r--www/js/DataModel.js16
-rw-r--r--www/js/EventServer.js43
-rw-r--r--www/js/LoginCtrl.js13
-rw-r--r--www/js/ModalCtrl.js2
-rw-r--r--www/js/MontageCtrl.js2
-rw-r--r--www/templates/login.html10
6 files changed, 62 insertions, 24 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js
index 24a96776..8c8e84fb 100644
--- a/www/js/DataModel.js
+++ b/www/js/DataModel.js
@@ -33,6 +33,7 @@ angular.module('zmApp.controllers').service('ZMDataModel',
'useSSL':false, // "1" if HTTPS
'keepAwake':true, // don't dim/dim during live view
'isUseAuth':true, // true if user wants ZM auth
+ 'isUseEventServer':false, // true if you configure the websocket event server
'refreshSec':"2", // timer value for frame change in sec
'enableDebug':false, // if enabled with log messages with "debug"
'usePin':false,
@@ -137,6 +138,20 @@ angular.module('zmApp.controllers').service('ZMDataModel',
}
+ if (window.localStorage.getItem("isUseEventServer") != undefined) {
+ loginData.isUseEventServer =
+ window.localStorage.getItem("isUseEventServer");
+
+
+ }
+ else
+ {
+ loginData.isUseEventServer = "0";
+
+ }
+
+
+
if (window.localStorage.getItem("username") != undefined) {
loginData.username =
@@ -335,6 +350,7 @@ angular.module('zmApp.controllers').service('ZMDataModel',
window.localStorage.setItem("isUseAuth", loginData.isUseAuth);
+ window.localStorage.setItem("isUseEventServer", loginData.isUseEventServer);
console.log ("***** SETTING ISUSEAUTH TO " + loginData.isUseAuth);
diff --git a/www/js/EventServer.js b/www/js/EventServer.js
index ad728661..ea156234 100644
--- a/www/js/EventServer.js
+++ b/www/js/EventServer.js
@@ -21,9 +21,15 @@ angular.module('zmApp.controllers')
$rootScope.alarmCount="0";
var loginData = ZMDataModel.getLogin();
- if (loginData.eventServer)
+
+ if (loginData.isUseEventServer =='0' || !loginData.eventServer)
{
- ZMDataModel.zmLog("Initializing Websocket with URL " +
+ ZMDataModel.zmLog("No Event Server present. Not initializing");
+ return;
+ }
+
+
+ ZMDataModel.zmLog("Initializing Websocket with URL " +
loginData.eventServer+" , will connect later...");
ws = $websocket.$new ({
url:loginData.eventServer,
@@ -31,11 +37,7 @@ angular.module('zmApp.controllers')
reconnectInterval:5000,
lazy:true
});
- }
- else
- {
- ZMDataModel.zmLog("No Event Server configured. Skipping initialization");
- }
+
ws.$on ('$open', function() {
@@ -96,23 +98,36 @@ angular.module('zmApp.controllers')
}
-
- // FIXME: needs cleaninup up
- // on iOS this socket will die after switching to background (eventually)
- // on Android it will keep running
- // on Android I need to see why websockets are getting duplicated on server
- // disconnect
+
function refresh()
{
var loginData = ZMDataModel.getLogin();
- if (!loginData.eventServer)
+ if ((!loginData.eventServer) || (loginData.isUseEventServer=="0"))
{
ZMDataModel.zmLog("No Event Server configured, skipping refresh");
+
+ // Let's also make sure that if the socket was open
+ // we close it - this may happen if you disable it after using it
+
+ if (typeof ws !== 'undefined')
+ {
+ if (ws.$status() != ws.$CLOSED)
+ {
+ ZMDataModel.zmDebug("Closing open websocket as event server was disabled");
+ ws.$close();
+ }
+ }
+
return;
}
+ if (typeof ws === 'undefined')
+ {
+ ZMDataModel.zmDebug ("Calling websocket init");
+ init();
+ }
// refresh is called when
// The following situations will close the socket
diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js
index 36ae4d47..a0112969 100644
--- a/www/js/LoginCtrl.js
+++ b/www/js/LoginCtrl.js
@@ -23,10 +23,12 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
$scope.loginData = ZMDataModel.getLogin();
- $scope.auth = {
- isUseAuth: ""
+ $scope.check = {
+ isUseAuth: "",
+ isUseEventServer: ""
};
- $scope.auth.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true : false;
+ $scope.check.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true : false;
+ $scope.check.isUseEventServer = ($scope.loginData.isUseEventServer == '1') ? true : false;
@@ -155,7 +157,8 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
$scope.loginData.streamingurl = $scope.loginData.streamingurl.trim();
$scope.loginData.eventServer = $scope.loginData.eventServer.trim();
- $scope.loginData.isUseAuth = ($scope.auth.isUseAuth) ? "1" : "0";
+ $scope.loginData.isUseAuth = ($scope.check.isUseAuth) ? "1" : "0";
+ $scope.loginData.isUseEventServer = ($scope.check.isUseEventServer) ? "1" : "0";
if ($scope.loginData.url.slice(-1) == '/') {
$scope.loginData.url = $scope.loginData.url.slice(0, -1);
@@ -211,7 +214,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
// Check if isUseAuth is set make sure u/p have a dummy value
- if ($scope.isUseAuth) {
+ if ($scope.check.isUseAuth) {
if (!$scope.loginData.username) $scope.loginData.username = "x";
if (!$scope.loginData.password) $scope.loginData.password = "x";
ZMDataModel.zmLog("Authentication is disabled, setting dummy user & pass");
diff --git a/www/js/ModalCtrl.js b/www/js/ModalCtrl.js
index c1ce47a9..dd3e47de 100644
--- a/www/js/ModalCtrl.js
+++ b/www/js/ModalCtrl.js
@@ -203,7 +203,7 @@ angular.module('zmApp.controllers').controller('ModalCtrl', ['$scope', '$rootSco
function loadModalNotifications() {
- //console.log ("Inside Modal timer...");
+ console.log ("Inside Modal timer...");
$rootScope.modalRand = Math.floor((Math.random() * 100000) + 1);
}
diff --git a/www/js/MontageCtrl.js b/www/js/MontageCtrl.js
index cc6edc1e..1f95f76a 100644
--- a/www/js/MontageCtrl.js
+++ b/www/js/MontageCtrl.js
@@ -216,7 +216,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', '
function loadNotifications() {
$rootScope.rand = Math.floor((Math.random() * 100000) + 1);
- // console.log ("Inside Montage timer...");
+ console.log ("Inside Montage timer...");
}
diff --git a/www/templates/login.html b/www/templates/login.html
index a0195f01..17afa562 100644
--- a/www/templates/login.html
+++ b/www/templates/login.html
@@ -13,9 +13,9 @@
</span>
<div class="item">
- <ion-checkbox ng-model="auth.isUseAuth">use authentication</ion-checkbox>
+ <ion-checkbox ng-model="check.isUseAuth">use authentication</ion-checkbox>
- <div ng-if = "auth.isUseAuth" >
+ <div ng-if = "check.isUseAuth" >
<label class="item item-input item-floating-label" >
<span class="input-label">username</span>
@@ -57,12 +57,16 @@
ng-model="loginData.apiurl">
</label>
- <label class="item item-input item-floating-label" >
+ <ion-checkbox ng-model="check.isUseEventServer">use event server</ion-checkbox>
+
+ <label class="item item-input item-floating-label" ng-if="check.isUseEventServer">
<span class="input-label">Event Server</span>
<input autocapitalize="none"
autocomplete="off" autocorrect="off"
type="text" placeholder="Event notification url"
ng-model="loginData.eventServer">
+
+
</label>
<label>