How can I keep looking for a network connection?

Is there a way to constantly check the network state while the app runs in a browser or on an RDK device, such as using an event listener?
We want the screen to display “No Internet” when the network connection fails. Any assistance would be greatly appreciated.
Thanks from pub tv

Hi Jameswbush,

Lightning apps run in a browser, which means that generally you have access to standard browser web api’s. The navigator.onLine web api can give you information on the online status of the device and you can also set listeners. See: Navigator.onLine - Web APIs | MDN

Whether this API is exposed and / or fully functional on the device that you’re targeting depends on the stack implementation. In some cases this functionality might be abstracted away in a platform SDK (i.e. Firebolt). From a Lightning perspective we have little control over this part. So it’s best to pick this up with the platform team of the device / operator that you are targetting.


Alternatively to Michiel’s suggestion you can look into the Beacon (not Bacon) API:

Or just an old fashioned XMLHttpRequest / Fetch on a well known API that you know that’s running in the background would also do the trick and more guaranteed to work with older browsers. Though highly recommend to run in a web worker to avoid blocking network requests / stacking too much of them. Make sure you only run 1 instance of the network request and not stagger multiple.