3 Commits db7b44db32 ... f312ff748e

Author SHA1 Message Date
  halphass f312ff748e Merge remote-tracking branch 'origin/master' 7 years ago
  halphass e08afa1416 @adding notification type & url 7 years ago
  halphass cb1ba121cd @adding notification type & url 7 years ago
1 changed files with 31 additions and 5 deletions
  1. 31 5
      www/js/push.js

+ 31 - 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,36 @@ 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);
+                /*
+                    TODO: va aggiunto come si deve comportare l'app
+                 */
+            }
+            else {
+                console.log('NESSUN URL, DEVO VISUALIZZARE DA QUALCHE PARTE MESSAGGIO E TITOLO..');
+                /*
+                 TODO: va aggiunto come si deve comportare l'app
+                 */
+            }
+
+        }
 
     });