summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/DataModel.js9
-rw-r--r--www/js/EventCtrl.js12
-rw-r--r--www/js/EventServer.js65
-rw-r--r--www/js/ModalCtrl.js2
-rw-r--r--www/js/MontageCtrl.js2
-rw-r--r--www/js/app.js12
6 files changed, 93 insertions, 9 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js
index 8c8e84fb..51b2c9a3 100644
--- a/www/js/DataModel.js
+++ b/www/js/DataModel.js
@@ -16,6 +16,7 @@ angular.module('zmApp.controllers').service('ZMDataModel',
$ionicPopup) {
var zmAppVersion="unknown";
+ var isBackground = false;
var monitorsLoaded = 0;
var montageSize = 3;
var monitors = [];
@@ -286,6 +287,14 @@ angular.module('zmApp.controllers').service('ZMDataModel',
getAppVersion:function() {
return(zmAppVersion);
},
+
+ setBackground:function(val) {
+ isBackground = val;
+ },
+
+ isBackground: function() {
+ return isBackground;
+ },
diff --git a/www/js/EventCtrl.js b/www/js/EventCtrl.js
index 6ef6c265..e039ad22 100644
--- a/www/js/EventCtrl.js
+++ b/www/js/EventCtrl.js
@@ -7,7 +7,7 @@
// and whether the new API has a better mechanism
angular.module('zmApp.controllers')
- .controller('zmApp.EventCtrl', ['$scope', '$rootScope', 'zm', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$ionicPlatform', '$ionicSlideBoxDelegate', '$ionicPosition', '$ionicPopover', '$ionicPopup', 'EventServer', function ($scope, $rootScope, zm, ZMDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate, $ionicPlatform, $ionicSlideBoxDelegate, $ionicPosition, $ionicPopover, $ionicPopup, EventServer) {
+ .controller('zmApp.EventCtrl', ['$scope', '$rootScope', 'zm', 'ZMDataModel', 'message', '$ionicSideMenuDelegate', '$timeout', '$interval', '$ionicModal', '$ionicLoading', '$http', '$state', '$stateParams', '$ionicHistory', '$ionicScrollDelegate', '$ionicPlatform', '$ionicSlideBoxDelegate', '$ionicPosition', '$ionicPopover', '$ionicPopup', 'EventServer', '$cordovaBadge', '$cordovaLocalNotification', function ($scope, $rootScope, zm, ZMDataModel, message, $ionicSideMenuDelegate, $timeout, $interval, $ionicModal, $ionicLoading, $http, $state, $stateParams, $ionicHistory, $ionicScrollDelegate, $ionicPlatform, $ionicSlideBoxDelegate, $ionicPosition, $ionicPopover, $ionicPopup, EventServer, $cordovaBadge, $cordovaLocalNotification) {
// events in last 5 minutes
// TODO https://server/zm/api/events/consoleEvents/5%20minute.json
@@ -734,6 +734,16 @@ angular.module('zmApp.controllers')
$scope.$on('$ionicView.enter', function () {
console.log("**VIEW ** Events Ctrl Entered");
ZMDataModel.setAwake(false);
+ //reset badge count
+ $cordovaBadge.set(0).then(function() {
+ // You have permission, badge set.
+ }, function(err) {
+ ZMDataModel.zmDebug("zmNinja does not have badge permissions. Please check your phone notification settings");
+ // You do not have permission.
+ });
+
+ $cordovaLocalNotification.clearAll();
+
});
$scope.$on('$ionicView.leave', function () {
diff --git a/www/js/EventServer.js b/www/js/EventServer.js
index ea156234..e5e30f1a 100644
--- a/www/js/EventServer.js
+++ b/www/js/EventServer.js
@@ -9,11 +9,12 @@
angular.module('zmApp.controllers')
.factory('EventServer',
-[ 'ZMDataModel', '$rootScope','$websocket', '$ionicPopup', function
- ( ZMDataModel, $rootScope, $websocket, $ionicPopup) {
+[ 'ZMDataModel', '$rootScope','$websocket', '$ionicPopup', '$cordovaLocalNotification', '$cordovaBadge', function
+ ( ZMDataModel, $rootScope, $websocket, $ionicPopup,$cordovaLocalNotification, $cordovaBadge) {
var ws;
+ var localNotificationId=5;
function init()
{
@@ -62,21 +63,75 @@ angular.module('zmApp.controllers')
ZMDataModel.displayBanner('error',['Event server rejected credentials', 'Please re-check credentials'],2000,6000);
}
+
+ var localNotText = "New Alarms:";
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+")");
+ localNotText = localNotText + str.events[iter].Name+",";
}
+ localNotText = localNotText.substring(0, localNotText.length - 1);
// lets stack the display so they don't overwrite
- if (eventsToDisplay.length > 0)
+
+ if (!ZMDataModel.isBackground())
{
- ZMDataModel.displayBanner('alarm', eventsToDisplay, 5000, 5000*eventsToDisplay.length);
-
+ ZMDataModel.zmDebug("App is in foreground, displaying banner");
+ if (eventsToDisplay.length > 0)
+ {
+
+ ZMDataModel.displayBanner('alarm', eventsToDisplay, 5000, 5000*eventsToDisplay.length);
+
+ }
}
+ else
+ {
+ ZMDataModel.zmDebug("App is in background, displaying localNotification");
+ localNotificationId--;
+
+ if ( localNotificationId == 0) // only slow last 5
+ {
+ localNotificationId = 5;
+
+ }
+
+ if ($cordovaLocalNotification.isPresent(localNotificationId))
+ {
+ $cordovaLocalNotification.clear(localNotificationId);
+ }
+
+ $cordovaLocalNotification.schedule({
+ id: localNotificationId,
+ title: 'ZoneMinder Alarms',
+ text: localNotText,
+ sound:"file://sounds/blop.mp3"
+
+ }).then(function (result) {
+ // do nothing for now
+ });
+
+
+ }
+ // lets set badge of app irrespective of background or foreground
+ $cordovaBadge.hasPermission().then(function(yes) {
+
+ $cordovaBadge.set($rootScope.alarmCount).then(function() {
+ // You have permission, badge set.
+ }, function(err) {
+ // You do not have permission.
+ });
+
+
+ // You have permission
+ }, function(no) {
+ ZMDataModel.zmDebug("zmNinja does not have badge permissions. Please check your phone notification settings");
+ });
+
+
$rootScope.isAlarm = 1;
if ($rootScope.alarmCount == "99")
diff --git a/www/js/ModalCtrl.js b/www/js/ModalCtrl.js
index dd3e47de..c1ce47a9 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 1f95f76a..ac47beaf 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/js/app.js b/www/js/app.js
index 25cca497..113ec21b 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -5,6 +5,7 @@
var appVersion = "0.0.0";
+
// core app start stuff
angular.module('zmApp', [
'ionic',
@@ -459,7 +460,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) {
+.run(function ($ionicPlatform, $ionicPopup, $rootScope, zm, $state, $stateParams, ZMDataModel, $cordovaSplashscreen, $http, $interval, zmAutoLogin, $fileLogger, $timeout, $ionicHistory, $window, $ionicSideMenuDelegate, EventServer, $cordovaLocalNotification) {
$rootScope.zmGlobalCookie = "";
$rootScope.isEventFilterOn = false;
@@ -541,6 +542,13 @@ angular.module('zmApp', [
// generates and error in desktops but works fine
ZMDataModel.zmLog("Device is ready");
console.log("**** DEVICE READY ***");
+
+ if (!$cordovaLocalNotification.hasPermission())
+ {
+ ZMDataModel.zmDebug("Prompting for pushnotification permission");
+ $cordovaLocalNotification.registerPermission();
+ }
+
$fileLogger.checkFile().then(function (resp) {
if (parseInt(resp.size) > zm.logFileMaxSize) {
@@ -628,6 +636,7 @@ angular.module('zmApp', [
// from foreground to background and back
document.addEventListener("resume", function () {
ZMDataModel.zmLog("App is resuming from background");
+ ZMDataModel.setBackground(false);
// don't animate
$ionicHistory.nextViewOptions({
disableAnimate: true,
@@ -657,6 +666,7 @@ angular.module('zmApp', [
document.addEventListener("pause", function () {
console.log("****The application is going into background");
ZMDataModel.zmLog("App is going into background");
+ ZMDataModel.setBackground(true);
zmAutoLogin.stop();
if ($rootScope.zmPopup)