From d0d3aaf7af63afa041e9af145267b0bb04ee729f Mon Sep 17 00:00:00 2001 From: Arjun Roychowdhury Date: Sat, 10 Oct 2015 11:28:44 -0400 Subject: Notifications now have a blop sound, also handling application badges --- www/js/EventServer.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'www/js/EventServer.js') 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 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") -- cgit v1.2.3