summaryrefslogtreecommitdiff
path: root/www/js/EventServer.js
diff options
context:
space:
mode:
authorArjun Roychowdhury <pliablepixels@gmail.com>2015-10-28 13:34:09 -0400
committerArjun Roychowdhury <pliablepixels@gmail.com>2015-10-28 13:34:09 -0400
commit4218008533f0d70bbe84c1b6866e2a455ab9eaf4 (patch)
treee93f90d9b5c525f9afd3b31b92f417fcb0595e26 /www/js/EventServer.js
parent075060b46a841cdd6d0c15234b66861644e323f2 (diff)
https://github.com/pliablepixels/zmNinja/issues/53 - added disablePush handling as well as https://github.com/pliablepixels/zmNinja/issues/54 - I had JSON format wrongly coded
Diffstat (limited to 'www/js/EventServer.js')
-rw-r--r--www/js/EventServer.js67
1 files changed, 60 insertions, 7 deletions
diff --git a/www/js/EventServer.js b/www/js/EventServer.js
index ab0e593e..a333f2dd 100644
--- a/www/js/EventServer.js
+++ b/www/js/EventServer.js
@@ -11,8 +11,8 @@
angular.module('zmApp.controllers')
-.factory('EventServer', ['ZMDataModel', '$rootScope', '$websocket', '$ionicPopup', '$timeout', '$q', 'zm', '$ionicPlatform', function
- (ZMDataModel, $rootScope, $websocket, $ionicPopup, $timeout, $q, zm, $ionicPlatform, $cordovaBadge) {
+.factory('EventServer', ['ZMDataModel', '$rootScope', '$websocket', '$ionicPopup', '$timeout', '$q', 'zm', '$ionicPlatform', '$cordovaMedia', function
+ (ZMDataModel, $rootScope, $websocket, $ionicPopup, $timeout, $q, zm, $ionicPlatform, $cordovaMedia) {
var ws;
@@ -65,11 +65,17 @@ angular.module('zmApp.controllers')
if ($rootScope.apnsToken != '') {
var plat = $ionicPlatform.is('ios') ? 'ios':'android';
+ var ld = ZMDataModel.getLogin();
+ var pushstate = "enabled";
+ if (ld.disablePush=="1")
+ pushstate = "disabled";
+ ZMDataModel.zmDebug("openHandShake: state of push is " + pushstate);
ws.$emit('push', {
type: 'token',
platform: plat,
- token: $rootScope.apnsToken
+ token: $rootScope.apnsToken,
+ state: pushstate
});
}
@@ -329,7 +335,44 @@ angular.module('zmApp.controllers')
function pushInit()
{
ZMDataModel.zmLog ("Setting up push registration");
- var push = PushNotification.init(
+ var push;
+
+ var src = "sounds/blop.mp3";
+ var media = $cordovaMedia.newMedia(src);
+
+
+ var plat = $ionicPlatform.is('ios') ? 'ios':'android';
+
+
+ if (plat == 'ios')
+ {
+ push = PushNotification.init(
+
+ { "ios":
+ {"alert": "true",
+ "badge": "true",
+ "sound": "true"}
+ }
+
+ );
+
+ }
+ else
+ {
+ push = PushNotification.init(
+
+ { "android":
+ {"senderID":zm.gcmSenderId,
+ "icon":"ic_stat_notification"
+ }
+ }
+
+ );
+
+ }
+
+
+ /* var push = PushNotification.init(
{ "android":
{"senderID":zm.gcmSenderId,
"icon":"ic_stat_notification"
@@ -342,21 +385,29 @@ angular.module('zmApp.controllers')
"sound": "true"}
}
- );
+ );*/
+
+
+
-
push.on('registration', function(data) {
ZMDataModel.zmDebug("Push Notification registration ID received: " + JSON.stringify(data));
$rootScope.apnsToken = data.registrationId;
var plat = $ionicPlatform.is('ios') ? 'ios':'android';
+ var ld = ZMDataModel.getLogin();
+ var pushstate = "enabled";
+ if (ld.disablePush == '1')
+ pushstate = "disabled";
sendMessage('push',
{
type:'token',
platform:plat,
- token:$rootScope.apnsToken});
+ token:$rootScope.apnsToken,
+ state:pushstate
+ });
});
@@ -380,6 +431,8 @@ angular.module('zmApp.controllers')
// data.image,
// data.additionalData
+ media.play();
+
if (data.additionalData.foreground == false)
{
// This means push notification tap in background