From a77d3cb115320fd66b9e67de0cb475c91a66610e Mon Sep 17 00:00:00 2001 From: Arjun Roychowdhury Date: Thu, 22 Oct 2015 16:08:58 -0400 Subject: unified GCM and APNS --- www/js/app.js | 199 +++++++--------------------------------------------------- 1 file changed, 21 insertions(+), 178 deletions(-) (limited to 'www/js') diff --git a/www/js/app.js b/www/js/app.js index 4a49a999..cb1c374e 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -30,7 +30,8 @@ angular.module('zmApp', [ .constant('zm', { minAppVersion: '1.28.107', // if ZM is less than this, the app won't work - minEventServerVersion: '0.2', + minEventServerVersion: '0.3', + gcmSenderId:'710936220256', httpTimeout: 15000, largeHttpTimeout: 60000, logFile: 'zmNinjaLog.txt', @@ -461,7 +462,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, $cordovaLocalNotification,$ionicContentBanner) { +.run(function ($ionicPlatform, $ionicPopup, $rootScope, zm, $state, $stateParams, ZMDataModel, $cordovaSplashscreen, $http, $interval, zmAutoLogin, $fileLogger, $timeout, $ionicHistory, $window, $ionicSideMenuDelegate, EventServer,$ionicContentBanner) { //$cordovaPush @@ -476,7 +477,8 @@ angular.module('zmApp', [ $rootScope.loggedIntoZm = 0; $rootScope.apnsToken = ''; $rootScope.tappedNotification = 0; - var eventsToDisplay=[]; + //var eventsToDisplay=[]; + $rootScope.alarmCount="0"; //console.log ("HERE"); @@ -543,8 +545,22 @@ angular.module('zmApp', [ } }); + + /* + function successHandler(result) { + console.log("************** Token: " + result.gcm); +} + function errorHandler(error) { + console.log("************** Error: " + error); +} - + + + window.onNotification = function(notification) + { + console.log ("******** HOLY GOT MESSAGE " + JSON.stringify(notification)); + }; +*/ $ionicPlatform.ready(function () { @@ -552,181 +568,8 @@ angular.module('zmApp', [ ZMDataModel.zmLog("Device is ready"); var ld = ZMDataModel.getLogin(); - if (!$cordovaLocalNotification.hasPermission()) - { - ZMDataModel.zmDebug("Prompting for pushnotification permission"); - $cordovaLocalNotification.registerPermission(); - } - - - - if ($ionicPlatform.is('ios') ) - { - ZMDataModel.zmLog ("iOS detected. Setting up APNS..."); - - - - var push = PushNotification.init( - { "ios": - {"alert": "true", - "badge": "true", - "sound": "true"} - } - ); - - push.on('registration', function(data) { - ZMDataModel.zmDebug("Push Notification registration ID received: " + JSON.stringify(data)); - $rootScope.apnsToken = data.registrationId; - - - EventServer.sendMessage('push', - { - type:'token', - platform:'ios', - token:$rootScope.apnsToken}); - - - }); - - - push.on('notification', function(data) { - - var ld = ZMDataModel.getLogin(); - if (ld.isUseEventServer=="0") - { - ZMDataModel.zmDebug("received push notification, but event server disabled. Not acting on it"); - return; - } - console.log ("************* PUSH RECEIVED ******************"); - // console.log (JSON.stringify(data)); - - // data.message, - // data.title, - // data.count, - // data.sound, - // data.image, - // data.additionalData - - if (data.additionalData.foreground == false) - { - // This means push notification tap in background - - ZMDataModel.zmDebug("**** NOTIFICATION TAPPED SETTING TAPPED TO 1 ****"); - $rootScope.alarmCount="0"; - $rootScope.isAlarm = 0; - $rootScope.tappedNotification = 1; - } - else - { - // alarm received in foregroun - var str=data.additionalData.alarm_details; - // console.log ("***STRING: " + str + " " +str.status); - eventsToDisplay=[]; - - console.log ("PUSH IS " + JSON.stringify(str.events)); - var alarmtext = ""; - for (var iter=0; iter zm.logFileMaxSize) { console.log("Deleting old log file as it exceeds " + zm.logFileMaxSize + " bytes"); -- cgit v1.2.3