diff options
Diffstat (limited to 'www')
| -rw-r--r-- | www/external/ng-websocket.js | 12 | ||||
| -rw-r--r-- | www/index.html | 2 | ||||
| -rw-r--r-- | www/js/EventServer.js | 81 | ||||
| -rw-r--r-- | www/js/app.js | 5 | ||||
| -rw-r--r-- | www/templates/events.html | 3 | ||||
| -rw-r--r-- | www/templates/help.html | 3 | ||||
| -rw-r--r-- | www/templates/log.html | 5 | ||||
| -rw-r--r-- | www/templates/monitors.html | 2 | ||||
| -rw-r--r-- | www/templates/montage.html | 1 | ||||
| -rw-r--r-- | www/templates/timeline.html | 2 |
10 files changed, 92 insertions, 24 deletions
diff --git a/www/external/ng-websocket.js b/www/external/ng-websocket.js index 8354eb2f..02f92d2b 100644 --- a/www/external/ng-websocket.js +++ b/www/external/ng-websocket.js @@ -119,7 +119,17 @@ }; me.$$init = function (cfg) { - me.$$ws = cfg.mock ? new $$mockWebsocket(cfg.mock, $http) : new WebSocket(cfg.url, cfg.protocols); + //https://github.com/wilk/ng-websocket/issues/11 + //me.$$ws = cfg.mock ? new $$mockWebsocket(cfg.mock, $http) : new WebSocket(cfg.url, cfg.protocols); + if (cfg.mock) { + me.$$ws = new $$mockWebsocket(cfg.mock, $http); + } + else if (cfg.protocols) { + me.$$ws = new WebSocket(cfg.url, cfg.protocols); + } + else { + me.$$ws = new WebSocket(cfg.url); + } me.$$ws.onmessage = function (message) { try { diff --git a/www/index.html b/www/index.html index 0f9d206e..f0bf45ca 100644 --- a/www/index.html +++ b/www/index.html @@ -4,7 +4,7 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> - <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' https://www.google.com 'unsafe-inline' 'unsafe-eval'"> + <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' https://www.google.com 'unsafe-inline' 'unsafe-eval'; "> <title></title> <meta name="format-detection" content="telephone=no"> diff --git a/www/js/EventServer.js b/www/js/EventServer.js index 9e95adb2..57d4658b 100644 --- a/www/js/EventServer.js +++ b/www/js/EventServer.js @@ -9,50 +9,93 @@ angular.module('zmApp.controllers') .factory('EventServer', -[ 'ZMDataModel', '$rootScope','$websocket', function - ( ZMDataModel, $rootScope, $websocket) { +[ 'ZMDataModel', '$rootScope','$websocket', '$ionicPopup', function + ( ZMDataModel, $rootScope, $websocket, $ionicPopup) { + var websocketActive = 0; + var webSocketBadAuth = 0; + var ws; function start() { - if ($rootScope.websocketActive == 1) + if (websocketActive == 1) { ZMDataModel.zmDebug ("Connection established. Not doing WebSocketInit again..."); return; } + + if (webSocketBadAuth == 1) + { + webSocketBadAuth = 0; + ZMDataModel.zmLog("Retrying websocket auth"); + ws.$open(); + return; + } var loginData = ZMDataModel.getLogin(); if (loginData.eventServer) { - var evtsvrUrl=loginData.eventServer+'/?user='+ - loginData.username+'&passwd='+loginData.password; + var evtsvrUrl=loginData.eventServer; // if (ws) ws.$close(); - ZMDataModel.zmLog("Event Server URL constructed as " + evtsvrUrl); - var ws = $websocket.$new ({ - url:evtsvrUrl, - reconnect:true, - reconnectInterval:5000 - }); + + if (typeof ws === 'undefined' || ws.$status == ws.$CLOSED ) + { + ZMDataModel.zmLog ("%%%%%%%%%%%%%%%%%%%%%% NEW WEBSOCKET %%%%%%%%%%"); + //console.log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+ws.$status()); + ZMDataModel.zmLog("Event Server URL constructed as " + evtsvrUrl); + ws = $websocket.$new ({ + url:evtsvrUrl, + reconnect:true, + reconnectInterval:5000 + }); + } ws.$on ('$open', function() { ZMDataModel.zmLog("Websocket open"); - $rootScope.websocketActive=1; + ws.$emit('auth', + {user:loginData.username, + password:loginData.password}); + // we will retry on resume of app + // but since we called close, it won't retry on its own + websocketActive=0; }); ws.$on ('$close', function() { ZMDataModel.zmLog ("Websocket closed"); - $rootScope.websocketActive = 0; + websocketActive = 0; }); ws.$on ('$message', function(str) { - ZMDataModel.zmLog("Real-time event: " + str); - var evt=str.split(":"); - var evtStr = "New Alarm in " + evt[0]+" ("+evt[2]+")"; - ZMDataModel.displayBanner('alarm',[evtStr],6000,6000); - - + ZMDataModel.zmLog("Real-time event: " + JSON.stringify(str)); + if (str.status != 'Success') + { + ZMDataModel.zmLog ("Event Error: " + JSON.stringify(str)); + ws.$close(); + webSocketBadAuth = 1; + ZMDataModel.displayBanner('error',['Event server rejected credentials', 'Please re-check credentials'],2000,6000); + + } + if (str.status == 'Success' && str.events) // new events + { + var eventsToDisplay=[]; + for (var iter=0; iter<str.events.length; iter++) + { + eventsToDisplay.push(str.events[iter].Name+": new event ("+str.events[iter].EventId+")"); + + + } + // lets stack the display so they don't overwrite + if (eventsToDisplay.length > 0) + ZMDataModel.displayBanner('alarm', eventsToDisplay, 5000, 5000*eventsToDisplay.length); + $rootScope.isAlarm = 1; + } + + + + + }); } diff --git a/www/js/app.js b/www/js/app.js index 6f1320f7..5ddaf0f7 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -458,7 +458,7 @@ angular.module('zmApp', [ // First run in ionic //------------------------------------------------------------------ -.run(function ($ionicPlatform, $ionicPopup, $rootScope, zm, $state, $stateParams, ZMDataModel, $cordovaSplashscreen, $http, $interval, zmAutoLogin, $fileLogger, $timeout, $ionicHistory, $window, $ionicSideMenuDelegate, EventServer, $websocket) { +.run(function ($ionicPlatform, $ionicPopup, $rootScope, zm, $state, $stateParams, ZMDataModel, $cordovaSplashscreen, $http, $interval, zmAutoLogin, $fileLogger, $timeout, $ionicHistory, $window, $ionicSideMenuDelegate, EventServer) { $rootScope.zmGlobalCookie = ""; $rootScope.isEventFilterOn = false; @@ -669,10 +669,11 @@ angular.module('zmApp', [ //------------------------------------------------------------------ // My route map connecting menu options to their respective templates and controllers -.config(function ($stateProvider, $urlRouterProvider, $httpProvider) { +.config(function ($stateProvider, $urlRouterProvider, $httpProvider, $ionicConfigProvider) { // If you do this, Allow Origin can't be * //$httpProvider.defaults.withCredentials = true; $httpProvider.interceptors.push('timeoutHttpIntercept'); + $ionicConfigProvider.navBar.alignTitle('center'); $stateProvider .state('login', { diff --git a/www/templates/events.html b/www/templates/events.html index a95cb2eb..b39d10a8 100644 --- a/www/templates/events.html +++ b/www/templates/events.html @@ -7,6 +7,9 @@ <button class="button button-icon icon ion-ios-minus-outline" ng-click="eventList.showDelete = !eventList.showDelete;"></button> + + <button class="animated infinite tada button button-icon button-clear ion-ios-bell" ng-click="$root.isAlarm=!$root.isAlarm;" ng-if="$root.isAlarm"></button> + </ion-nav-buttons> <ion-nav-buttons side="right"> diff --git a/www/templates/help.html b/www/templates/help.html index 0d3a9998..cce7057b 100644 --- a/www/templates/help.html +++ b/www/templates/help.html @@ -2,6 +2,9 @@ <ion-nav-buttons side="left"> <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button> + + <button class="animated infinite tada button button-icon button-clear ion-ios-bell" ng-click="$root.isAlarm=!$root.isAlarm;" ng-if="$root.isAlarm"></button> + </ion-nav-buttons> diff --git a/www/templates/log.html b/www/templates/log.html index 0c91dd90..ff4ce57a 100644 --- a/www/templates/log.html +++ b/www/templates/log.html @@ -2,6 +2,11 @@ <ion-nav-buttons side="left"> <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button> + + <button class="animated infinite tada button button-icon button-clear ion-ios-bell" ng-click="$root.isAlarm=!$root.isAlarm;" ng-if="$root.isAlarm"></button> + +<button class="animated infinite tada button button-icon button-clear ion-ios-bell" ng-click="$root.isAlarm=!$root.isAlarm;" ng-if="$root.isAlarm"></button> + </ion-nav-buttons> <ion-nav-buttons side="right"> diff --git a/www/templates/monitors.html b/www/templates/monitors.html index 5ffcbf19..aec02784 100644 --- a/www/templates/monitors.html +++ b/www/templates/monitors.html @@ -2,6 +2,8 @@ <ion-nav-buttons side="left"> <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"> </button> + + <button class="animated infinite tada button button-icon button-clear ion-ios-bell" ng-click="$root.isAlarm=!$root.isAlarm;" ng-if="$root.isAlarm"></button> </ion-nav-buttons> <ion-content> diff --git a/www/templates/montage.html b/www/templates/montage.html index d0a9d624..aed7fd60 100644 --- a/www/templates/montage.html +++ b/www/templates/montage.html @@ -1,6 +1,7 @@ <ion-view title="Montage" cache-view="false" hide-nav-bar="{{minimal}}"> <ion-nav-buttons side="left"> <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button> + <button class="animated infinite tada button button-icon button-clear ion-ios-bell" ng-click="$root.isAlarm=!$root.isAlarm;" ng-if="$root.isAlarm"></button> </ion-nav-buttons> diff --git a/www/templates/timeline.html b/www/templates/timeline.html index 6436c694..d93c48cb 100644 --- a/www/templates/timeline.html +++ b/www/templates/timeline.html @@ -8,7 +8,7 @@ <button class="button button-icon button-clear ion-arrow-right-c" ng-click="move(-0.2)"></button>--> - +<button class="animated infinite tada button button-icon button-clear ion-ios-bell" ng-click="$root.isAlarm=!$root.isAlarm;" ng-if="$root.isAlarm"></button> </ion-nav-buttons> |
