Browse Source

@adding notification type & url

halphass 7 years ago
parent
commit
cb1ba121cd
1 changed files with 25 additions and 5 deletions
  1. 25 5
      www/js/push.js

+ 25 - 5
www/js/push.js

@@ -16,12 +16,13 @@ function onDeviceReadyPush() {
         windows: {}
     });
 
+
     /*
      * registra l'id univoco dell'installazione su xm.bus.pm
      */
     push.on('registration', function(registration) {
         console.log(JSON.stringify(registration));
-        var url = "https://xm.bus.pm/api/d/c?device=" + registration.registrationId;
+        var url = "https://xm.bus.pm/api/d/c?token=" + registration.registrationId + "&token_type=gcm&topic=xm24";
         $.get(url, function( data ) {
             console.log(JSON.stringify(data));
         });
@@ -32,11 +33,30 @@ function onDeviceReadyPush() {
      */
     push.on('notification', function(data) {
         console.log(JSON.stringify(data));
-        // alert(JSON.stringify(data));
 
-        $("body").pagecontainer("change", "#alert");
-        $("#alert-title").html(data.title);
-        $("#alert-message").html(data.message);
+        if(data.additionalData.type === 'alarm')
+        {
+            /*
+             *   QUESTA è una COMUNICAZIONE IMPORTANTE!
+             */
+            $("body").pagecontainer("change", "#alert");
+            $("#alert-title").html(data.title);
+            $("#alert-message").html(data.message);
+        }
+        else
+        {
+            /*
+             *   QUESTO è un SEMPLICE AGGIORNAMENTO!
+             */
+            if(!empty(data.additionalData.url))
+            {
+                console.log('HO UN URL VALIDO '+data.additionalData.url);
+            }
+            else {
+                console.log('NESSUN URL, DEVO VISUALIZZARE DA QUALCHE PARTE MESSAGGIO E TITOLO..');
+            }
+
+        }
 
     });