Online and offline events are not fired correctly in my PhoneGap application under Ripple

StackOverflow https://stackoverflow.com/questions/13636555

  •  03-12-2021
  •  | 
  •  

Question

Using Ripple in Chrome I'd expect my on and off line events to be called as I switch the network from a connected state (WiFi, 4g, etc) to and from None. But this doesn't happen. At best offline is called if I start the emulator offline.

Deploying to a phone (Android) the events seem to be called if I go into Airplane mode then back to online.

Here is my code:

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
   document.addEventListener('deviceready', this.onDeviceReady, false);
},
onOffline: function () {
    var parentElement = document.getElementById("devicestatus");
    var offlineElement = parentElement.querySelector('.offline');
    var onlineElement = parentElement.querySelector('.online');
    onlineElement.setAttribute('style', 'display:none;');
    offlineElement.setAttribute('style', 'display:block;');
},
onOnline: function () {
    var parentElement = document.getElementById("devicestatus");
    var offlineElement = parentElement.querySelector('.offline');
    var onlineElement = parentElement.querySelector('.online');
    offlineElement.setAttribute('style', 'display:none;');
    onlineElement.setAttribute('style', 'display:block;');
},
onDeviceReady: function() {
    var parentElement = document.getElementById("devicestatus");
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');
    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    document.addEventListener('offline', app.onOffline, false);
    document.addEventListener('online', app.onOnline, false);
}
};

Is this a bug in Ripple or something I'm doing wrong?

Was it helpful?

Solution

You are correct, this was a bug in Ripple. It has been fixed in the latest version of Ripple:

https://github.com/blackberry/Ripple-UI/issues/663

Suggest updating to 0.9.11 and testing your code again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top