webXMPP

Check-in [30ef720dc6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Don't waste data and battery on background long polling if you don't have the ability to post notifications. (On Ubuntu Touch, we instead run a notification daemon.)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:30ef720dc6d1807a9c5d47a67aba4ced73b614491295bce681beea5b2efda113
User & Date: ajv-899-334-8894@vsta.org 2017-07-01 00:02:24
Context
2017-07-01
00:03
Merge branch 'master' of https://github.com/vandys/webXMPP check-in: bbd719910e user: ajv-899-334-8894@vsta.org tags: master, trunk
00:02
Don't waste data and battery on background long polling if you don't have the ability to post notifications. (On Ubuntu Touch, we instead run a notification daemon.) check-in: 30ef720dc6 user: ajv-899-334-8894@vsta.org tags: master, trunk
00:01
Failed idea on dealing with NAT, back out. check-in: 0d418f5fb1 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to js/polling.js.

    29     29   
    30     30   // This fires when we've posted a notification event and are now
    31     31   //  idle until the focus returns here.
    32     32   function updateVisibility() {
    33     33       if (document.hidden == false) {
    34     34   	// Start listening for more messages actively
    35     35   	moreMessages();
           36  +    } else {
           37  +	if (!notifiable) {
           38  +	    // When not on-screen and notifications are not
           39  +	    //  available, we can just quiesce.
           40  +	    goOffline();
           41  +	    ourState = 3;
           42  +	}
    36     43       }
    37     44   }
    38     45   
    39     46   // Visibility hook
    40     47   document.addEventListener("visibilitychange", updateVisibility);
    41     48   

Changes to js/ui.js.

    75     75   let lastTM = '';
    76     76   
    77     77   // Latest serial # back from server completion
    78     78   let lastSerial = 0;
    79     79   
    80     80   // Unique value for us
    81     81   let clientID = null;
           82  +
           83  +// Have they OK'ed notifications?  There's things we
           84  +//  won't do if we can't post notifications anyway.
           85  +let notifiable = false;
    82     86   
    83     87   // Returning online (network change, cell->wifi, etc.)
    84     88   function goOnline() {
    85     89       if (curReq != null) {
    86     90   	curReq.abort();
    87     91   	curReq = null;
    88     92       }
................................................................................
   444    448   function ourStart() {
   445    449   
   446    450       // We'll want to send notifications (if the user
   447    451       //  lets us)
   448    452       Notification.requestPermission(function(result) {
   449    453   	if (result == "granted") {
   450    454   	    console.log("Notifications OK");
          455  +	    notifiable = true;
   451    456   	}
   452    457       });
   453    458   
   454    459       // Send our initial update request
   455    460       ourState = 1;
   456    461       curReq = new XMLHttpRequest();
   457    462       curReq.open("GET", "/config.json");