Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Network quality indicator on a webapp

Is there a way we could indicate the client's current network quality (a bar of some sort, similar to the n/w quality bar on a phone) on a web application?

A web app of ours, that deals with data transfer, has most transfer failures because of network issues with clients, who obviously don't know about it. Clients keep reporting failures whereas the actual issue is with their n/w connectivity, and I'm looking for a way that can indicate the same (inside my web app) to them when they are using the application.

I know there are other tools for investigating that, but layman user setups don't have them (at least our users).

Thanks.

like image 565
Saket Avatar asked Oct 21 '22 19:10

Saket


1 Answers

One way would be to use window.navigator.onLine for example:

if (navigator.onLine) {
  alert('online')
} else {
  alert('offline');
}

or capture the change:

window.addEventListener("offline", function(e) {
  alert("offline");
}, false);

window.addEventListener("online", function(e) {
  alert("online");
}, false);

You could take averages on certain time intervals and develop an algorithm to quantify the connectivity as 10%, 50%, etc...

You could also just set up an AJAX poll and watch for timeouts, but be careful to not increase traffic too much:

$.ajax({
  type: "GET",
  url: "yourserver.com",
  success: function(data){
    alert("Connection active!")
  }
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    if(textStatus == 'timeout') {
       alert('Connection seems dead!');
    }
  }
});
like image 194
Kyle Weller Avatar answered Nov 03 '22 00:11

Kyle Weller