diff --git a/config.xml b/config.xml index 3b859cf59..77963746c 100644 --- a/config.xml +++ b/config.xml @@ -1,5 +1,5 @@ - + zmNinja High performance ZoneMinder client @@ -35,7 +35,7 @@ - + @@ -49,7 +49,6 @@ - NSAllowsArbitraryLoads @@ -85,7 +84,7 @@ - + @@ -99,6 +98,24 @@ + + + + + + + + + + + + + + + + + + @@ -159,15 +176,16 @@ - - - - + + + + + @@ -175,7 +193,4 @@ - - - diff --git a/docs/guides/source.rst b/docs/guides/source.rst index cb2499d2a..c1f62f1a7 100644 --- a/docs/guides/source.rst +++ b/docs/guides/source.rst @@ -138,8 +138,12 @@ it support automatic building of notification extensions. So there is manual wor - Now in XCode Targets, select ``zmNinjaNotification``, and make sure you select a Team and make sure Deployment Target is 11 or above - Change Deployment target to 11 or above (same as zmNinja target) - ``cp etc/NotificationService.m platforms/ios/zmNinjaNotification/`` -- ``cd platforms/ios/`` -- ``pod install`` + +Starting 1.5.0, zmNinja uses the `cordova-plugin-firebasex `__ +library for push notifications. The older cordova-push-plugin is no longer supported by the author. +If you are facing compilation issues that relate to this plugin, please make sure you read it's troubleshooting section, +especially around outdated pods et. al. + You can now do `build_ios.sh`. However, after you build, you will have to go back to XCode after the build to make the following changes: diff --git a/package.json b/package.json index 0972933c5..92edf08e6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zmninjapro", "description": "Home security mobile app for ZoneMinder", - "version": "1.4.010", + "version": "1.5.000", "displayName": "zmNinja", "author": "Pliable Pixels", "license": "custom see LICENSE.md", @@ -35,10 +35,6 @@ "cordova-plugin-advanced-websocket": {}, "cordova-plugin-splashscreen": {}, "cordova-support-google-services": {}, - "phonegap-plugin-push": { - "ANDROID_SUPPORT_V13_VERSION": "27.+", - "FCM_VERSION": "17.0.+" - }, "cordova-plugin-x-socialsharing": { "ANDROID_SUPPORT_V4_VERSION": "24.1.1+", "PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION": "This app requires photo library access to function properly.", @@ -50,16 +46,33 @@ }, "cordova-plugin-android-permissions": {}, "cordova-plugin-app-version": {}, - "cordova-plugin-advanced-http": { - "OKHTTP_VERSION": "3.10.0" - }, "cordova-sqlite-storage": {}, "cordova-plugin-add-swift-support": {}, "cordova-plugin-statusbar": {}, "cordova-plugin-file": {}, - "cordova-plugin-media-pp-fork": {}, "cordova-plugin-photo-library-wkwebview": { "PHOTO_LIBRARY_USAGE_DESCRIPTION": "Save alarmed images to phone " + }, + "cordova-plugin-firebasex": { + "FIREBASE_ANALYTICS_COLLECTION_ENABLED": "false", + "FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "false", + "FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "false", + "ANDROID_ICON_ACCENT": "#FF00FFFF", + "ANDROID_PLAY_SERVICES_AUTH_VERSION": "18.0.0", + "ANDROID_FIREBASE_ANALYTICS_VERSION": "17.4.3", + "ANDROID_FIREBASE_MESSAGING_VERSION": "20.2.1", + "ANDROID_FIREBASE_CONFIG_VERSION": "19.1.4", + "ANDROID_FIREBASE_PERF_VERSION": "19.0.7", + "ANDROID_FIREBASE_AUTH_VERSION": "19.3.1", + "ANDROID_FIREBASE_FIRESTORE_VERSION": "21.4.3", + "ANDROID_FIREBASE_CRASHLYTICS_VERSION": "17.0.1", + "ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION": "17.0.1", + "ANDROID_GSON_VERSION": "2.8.6" + }, + "cordova-plugin-media-pp-fork": {}, + "cordova-plugin-advanced-http": {}, + "cordova-plugin-ionic-webview": { + "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+" } } }, @@ -71,10 +84,12 @@ "cordova-ios": "^5.1.1", "cordova-library-helper-pp-fork": "^1.0.1", "cordova-plugin-add-swift-support": "^2.0.2", - "cordova-plugin-advanced-http": "^2.5.1", + "cordova-plugin-advanced-http": "3.0.1", "cordova-plugin-advanced-websocket": "^1.1.5", "cordova-plugin-android-fingerprint-auth": "^1.5.0", "cordova-plugin-android-permissions": "^1.0.2", + "cordova-plugin-androidx": "^2.0.0", + "cordova-plugin-androidx-adapter": "^1.1.1", "cordova-plugin-app-version": "^0.1.9", "cordova-plugin-cloud-settings": "^1.0.4", "cordova-plugin-customurlscheme": "^4.4.0", @@ -85,6 +100,7 @@ "cordova-plugin-ignore-lint-translation": "0.0.1", "cordova-plugin-insomnia": "^4.3.0", "cordova-plugin-ionic-keyboard": "^2.2.0", + "cordova-plugin-ionic-webview": "git+https://github.com/pliablepixels/cordova-plugin-ionic-webview.git", "cordova-plugin-media-pp-fork": "^1.0.2-dev", "cordova-plugin-multi-window": "0.0.3", "cordova-plugin-network-information": "^2.0.2", @@ -114,19 +130,19 @@ "json-file": "^0.1.0", "jsonfile": "^6.0.1", "keypress": "^0.2.1", + "latest": "^0.2.0", "menu": "^0.2.5", "minimist": "^1.2.5", "mkdirp": "^1.0.4", "node-sass": "^4.14.1", "object-is": "^1.1.2", "object-keys": "^1.1.1", - "phonegap-plugin-multidex": "^1.0.0", - "phonegap-plugin-push": "^2.3.0", "regexp.prototype.flags": "^1.3.0" }, "devDependencies": { "@ionic/v1-toolkit": "^1.0.14", "bower": "^1.8.4", + "cordova-plugin-firebasex": "^10.2.0-cli", "dotenv": "^8.2.0", "electron": "^8.3.0", "electron-builder": "^22.6.0", diff --git a/www/js/EventCtrl.js b/www/js/EventCtrl.js index 40762f6b1..3027de016 100644 --- a/www/js/EventCtrl.js +++ b/www/js/EventCtrl.js @@ -2475,25 +2475,23 @@ angular.module('zmApp.controllers') $scope.popover = popover; }); + // coming to this view clears all notification badges EventServer.sendMessage('push', { type: 'badge', badge: 0, }); + // also clear bells + $rootScope.alarmCount = "0"; + $rootScope.isAlarm = !$rootScope.isAlarm; - - - //reset badge count - if (window.cordova && window.cordova.plugins.notification) { - $cordovaBadge.set(0).then(function () { - // You have permission, badge set. - }, function (err) { - NVR.debug("app does not have badge permissions. Please check your phone notification settings"); - // You do not have permission. - }); + // reset badge count + if (window.FirebasePlugin && $rootScope.platformOS == 'ios') { + NVR.debug ('Clearing app badge count'); + window.FirebasePlugin.setBadgeNumber(0); - $cordovaLocalNotification.clearAll(); } - + + }); $scope.$on('$ionicView.leave', function () { diff --git a/www/js/EventServer.js b/www/js/EventServer.js index 78e081c54..842600720 100644 --- a/www/js/EventServer.js +++ b/www/js/EventServer.js @@ -1,7 +1,7 @@ /* jshint -W041 */ /* jslint browser: true*/ -/* global cordova,StatusBar,angular,console ,PushNotification*/ +/* global cordova,StatusBar,angular,console ,PushNotification, FirebasePlugin*/ //-------------------------------------------------------------------------- // This factory interacts with the ZM Event Server @@ -410,7 +410,8 @@ angular.module('zmApp.controllers') var msg = { 'event': type, - 'data': obj + 'data': obj, + 'token': $rootScope.apnsToken }; var jmsg = JSON.stringify(msg); @@ -435,6 +436,12 @@ angular.module('zmApp.controllers') return; } + if (($rootScope.platformOS != 'desktop') && (!$rootScope.apnsToken) ) { + NVR.debug ('Mobile platform does not have a token yet, adding message to queue'); + pendingMessages.push ({type:type, obj:obj}); + return; + } + if (authState == connState.REJECT && type != 'auth') { NVR.debug ("EventSever: ERROR: ES rejected authentication, not sending message"); return; @@ -510,6 +517,7 @@ angular.module('zmApp.controllers') }*/ } + function pushInit() { NVR.log("EventSever: Setting up push registration"); @@ -522,13 +530,194 @@ angular.module('zmApp.controllers') var plat = $rootScope.platformOS; if ($rootScope.platformOS == 'desktop') { - NVR.log ('Not setting up push as this is desktop.'); + NVR.log ('push: Not setting up push as this is desktop.'); return; } + + // get permission if we need it + FirebasePlugin.hasPermission(function(hasPermission){ + if (!hasPermission) { + window.FirebasePlugin.grantPermission(function(hasPermission){ + if (hasPermission) { + NVR.debug ('push: permission granted, waiting for token'); + } else { + NVR.log('ERROR: push: Permission not granted for push'); + } + }); + } else { + NVR.debug('push: permissions are already enabled'); + } + }); + + if ($rootScope.platformOS == 'android') { + // Define custom channel - all keys are except 'id' are optional. + var channel = { + // channel ID - must be unique per app package + id: "zmninja", + // Channel description. Default: empty string + description: "zmNinja push", + // Channel name. Default: empty string + name: "zmNinja", + //The sound to play once a push comes. Default value: 'default' + //Values allowed: + //'default' - plays the default notification sound + //'ringtone' - plays the currently set ringtone + //'false' - silent; don't play any sound + //filename - the filename of the sound file located in '/res/raw' without file extension (mysound.mp3 -> mysound) + sound: "default", + + //Vibrate on new notification. Default value: true + //Possible values: + //Boolean - vibrate or not + //Array - vibration pattern - e.g. [500, 200, 500] - milliseconds vibrate, milliseconds pause, vibrate, pause, etc. + vibration: true, + // Whether to blink the LED + light: true, + //LED color in ARGB format - this example BLUE color. If set to -1, light color will be default. Default value: -1. + lightColor: parseInt("FF0000FF", 16).toString(), + //Importance - integer from 0 to 4. Default value: 4 + //0 - none - no sound, does not show in the shade + //1 - min - no sound, only shows in the shade, below the fold + //2 - low - no sound, shows in the shade, and potentially in the status bar + //3 - default - shows everywhere, makes noise, but does not visually intrude + //4 - high - shows everywhere, makes noise and peeks + importance: 4, + + //Show badge over app icon when non handled pushes are present. Default value: true + badge: true, + + //Show message on locked screen. Default value: 1 + //Possible values (default 1): + //-1 - secret - Do not reveal any part of the notification on a secure lockscreen. + //0 - private - Show the notification on all lockscreens, but conceal sensitive or private information on secure lockscreens. + //1 - public - Show the notification in its entirety on all lockscreens. + visibility: 1 + }; + + // Create the channel + FirebasePlugin.createChannel(channel, + function(){ + NVR.debug('push: Channel created: ' + channel.id); + }, + function(error){ + NVR.debug('push: Create channel error: ' + error); + }); + } + + + if ($rootScope.platformOS == 'ios') { + if (ld.isUseEventServer) { + NVR.debug ('push: ios, setting badge alarm count at start'); + window.FirebasePlugin.getBadgeNumber(function(cnt) { + if (cnt) { + NVR.debug ('push: ios, badge is:'+cnt); + $rootScope.isAlarm = 1; + $rootScope.alarmCount = cnt; + if ($rootScope.alarmCount > 99) { + $rootScope.alarmCount = '99+'; + } + } + }); + } + } // ios + // called when token is assigned + window.FirebasePlugin.onTokenRefresh( + function (token) { + NVR.debug ("push: got token:"+token); + $rootScope.apnsToken = token; + NVR.debug ('push: setting up onMessageReceived...'); + window.FirebasePlugin.onMessageReceived(function(message) { + $ionicPlatform.ready(function () { + + NVR.debug("push: EventSever: received push notification with payload:"+JSON.stringify(message)); + + if ($rootScope.platformOS == 'ios') { + NVR.debug ("push: clearing badge"); + window.FirebasePlugin.setBadgeNumber(0); + } + + var ld = NVR.getLogin(); + if (ld.isUseEventServer == false) { + NVR.debug("push: EventSever: received push notification, but event server disabled. Not acting on it"); + return; + } + NVR.debug ('push: Message type received is:'+message.messageType); + + sendMessage('push', { + type: 'badge', + badge: 0, + }); + var mid; + var eid = message.eid; + if (message.mid) { + mid = message.mid; + var mi = mid.indexOf(','); + if (mi > 0) { + mid = mid.slice(0, mi); + } + mid = parseInt(mid); + } + + + if (message.tap=='foreground') { + console.log ('push: Foreground'); + $rootScope.tappedNotification = 0; + $rootScope.tappedEid = 0; + $rootScope.tappedMid = 0; + + if (ld.soundOnPush) { + media.play({ + playAudioWhenScreenIsLocked: false + }); + } + if ($rootScope.alarmCount == "99") { + $rootScope.alarmCount = "99+"; + } + if ($rootScope.alarmCount != "99+") { + $rootScope.alarmCount = (parseInt($rootScope.alarmCount) + 1).toString(); + } + $rootScope.isAlarm = 1; + + + + } else if (message.tap == 'background') { + $rootScope.alarmCount = "0"; + $rootScope.isAlarm = 0; + $rootScope.tappedNotification = 1; + $rootScope.tappedMid = mid; + $rootScope.tappedEid = eid; + NVR.log("EventSever: Push notification: Tapped Monitor taken as:" + $rootScope.tappedMid); + + $timeout ( function () { + NVR.debug ("EventServer: broadcasting process-push"); + $rootScope.$broadcast('process-push'); + },100); + + + } else { + NVR.debug ("push: message tap not defined"); + $rootScope.tappedNotification = 0; + $rootScope.tappedEid = 0; + $rootScope.tappedMid = 0; + + } + + }); // ready + }); + }, + function (err) { + NVR.debug ('push: Error getting token:'+err); + + }); + + + + + if (plat == 'ios') { mediasrc = "sounds/blop.mp3"; - push = PushNotification.init( + /* push = PushNotification.init( { "ios": { @@ -541,13 +730,13 @@ angular.module('zmApp.controllers') } } - ); + );*/ } else { mediasrc = "/android_asset/www/sounds/blop.mp3"; var android_media_file = "blop"; - push = PushNotification.init( + /* push = PushNotification.init( { "android": { @@ -559,15 +748,15 @@ angular.module('zmApp.controllers') } } - ); + );*/ } - PushNotification.hasPermission(function (succ) { + /* PushNotification.hasPermission(function (succ) { NVR.debug ("Push permission returned: "+JSON.stringify(succ)); }, function (err) { NVR.debug ("Push permission error returned: "+JSON.stringify(err)); - }); + });*/ // console.log("*********** MEDIA BLOG IS " + mediasrc); try { @@ -578,7 +767,7 @@ angular.module('zmApp.controllers') } - + /* push.on('registration', function (data) { pushInited = true; NVR.debug("EventSever: Push Notification registration ID received: " + JSON.stringify(data)); @@ -640,136 +829,10 @@ angular.module('zmApp.controllers') NVR.log("EventSever: Could not get monitors, can't send push reg"); }); - }); - - push.on('notification', function (data) { - - $ionicPlatform.ready(function () { - NVR.log("EventSever: notification handler device ready"); - NVR.debug("EventSever: received push notification"); - - var ld = NVR.getLogin(); - if (ld.isUseEventServer == false) { - NVR.debug("EventSever: received push notification, but event server disabled. Not acting on it"); - return; - } - - if (data && data.additionalData && data.additionalData.foreground == false) { - // This means push notification tap in background - - NVR.debug("EventSever: PUSH NOTF >>> " + JSON.stringify(data)); - - // set tappedMid to monitor - //*** PUSH DATA>>>>{"sound":"blop","message":"Alarms: Basement (2854) ","additionalData":{"mid":"2","coldstart":false,"collapse_key":"do_not_collapse","foreground":false}} - - if (data.additionalData.dismissed != undefined || data.additionalData.coldstart == true || $rootScope.platformOS == 'ios') // user tapped on notification - // in iOS case, since content-av is not there this notification won't be called unless you tap - { - NVR.debug("Notification Tapped"); - $rootScope.alarmCount = "0"; - $rootScope.isAlarm = 0; - $rootScope.tappedNotification = 1; - - var mid; - var eid; - - // we are using FCM on IOS too - /* if ($rootScope.platformOS == 'ios') { - mid = data.additionalData.gcm.notification.mid; - eid = data.additionalData.gcm.notification.eid; - - } - else {*/ - - mid = data.additionalData.mid; - eid = data.additionalData.eid; - // } - - - - // if Multiple mids, take the first one - if (mid) { - var mi = mid.indexOf(','); - if (mi > 0) { - mid = mid.slice(0, mi); - } - } - - mid = parseInt(mid); - - $rootScope.tappedMid = mid; - $rootScope.tappedEid = eid; - NVR.log("EventSever: Push notification: Tapped Monitor taken as:" + $rootScope.tappedMid); - - if ($rootScope.platformOS == 'ios') { - - NVR.debug("EventSever: iOS only: clearing background push"); - push.finish(function () { - NVR.debug("EventSever: processing of push data is finished"); - }); - } - - } else { - NVR.debug("EventSever: App started via icon, not notification tap"); - $rootScope.tappedNotification = 0; - $rootScope.tappedEid = 0; - $rootScope.tappedMid = 0; - } - // keep this emit not broadcast - // see Portal latch for reason - - //https://stackoverflow.com/a/22651128/1361529 - $timeout ( function () { - NVR.debug ("EventServer: broadcasting process-push"); - $rootScope.$broadcast('process-push'); - },100); - - - } else // app is foreground - { - - // this flag honors the HW mute button. Go figure - // http://ilee.co.uk/phonegap-plays-sound-on-mute/ - - NVR.debug("EventSever: --> *** PUSH IN FOREGROUND"); - - $rootScope.tappedNotification = 0; - $rootScope.tappedEid = 0; - $rootScope.tappedMid = 0; - - if (ld.soundOnPush) { - media.play({ - playAudioWhenScreenIsLocked: false - }); - } - - var str = data.message; - // console.log ("***STRING: " + str + " " +str.status); - var eventsToDisplay = []; - - NVR.displayBanner('alarm', [str], 0, 5000 * eventsToDisplay.length); - - $rootScope.isAlarm = 1; - - // Show upto a max of 99 when it comes to display - // so aesthetics are maintained - if ($rootScope.alarmCount == "99") { - $rootScope.alarmCount = "99+"; - } - if ($rootScope.alarmCount != "99+") { - $rootScope.alarmCount = (parseInt($rootScope.alarmCount) + 1).toString(); - } - - - - } - }); - }); - - push.on('error', function (e) { - NVR.debug("EventSever: Push error: " + JSON.stringify(e)); - // console.log("************* PUSH ERROR ******************"); - }); + }); */ + + // add push code here + } return { diff --git a/www/js/NVR.js b/www/js/NVR.js index bc33af07a..f1c369c30 100644 --- a/www/js/NVR.js +++ b/www/js/NVR.js @@ -21,7 +21,7 @@ angular.module('zmApp.controllers') DO NOT TOUCH zmAppVersion It is changed by sync_version.sh */ - var zmAppVersion = "1.4.010"; + var zmAppVersion = "1.5.000"; var isBackground = false; var justResumed = false; diff --git a/www/js/app.js b/www/js/app.js index 26fef2fb5..f84673a55 100755 --- a/www/js/app.js +++ b/www/js/app.js @@ -34,7 +34,7 @@ angular.module('zmApp', [ .constant('zm', { minAppVersion: '1.28.107', // if ZM is less than this, the app won't work //minAppVersion:'1.44', - minEventServerVersion: '2.4', + minEventServerVersion: '6.0', castAppId: 'BA30FB4C', alarmFlashTimer: 20000, // time to flash alarm gcmSenderId: '710936220256',