Search code examples
androidcordovacordova-plugins

Live data usage monitoring in Cordova


I coded a simple Cordova program for my colleagues that streams a video (which is in my pc connected to a work place lan) and all my colleagues are connected to WIFI (work place lan) which made it easy to view my pc's content. The program worked good. I used Polyvi Xface Traffic Monitor plugin to get the data usage.

...
function checkStats(){
xFace.TrafficStats.getWifiTraffic(success, fail);
}
...
function success(result) {
        data = document.querySelector("#dataUsage");
        data.innerHTML = result + "Kb";
    }

    function fail(error) {
        data = document.querySelector("#dataUsage");
        data.innerHTML = error;
    }

This works great if i call checkStats() function (usually from a button's onClick). But how to get the data usage real time with out clicking the button everytime.

I just want to know, Is there anyway to do it?

Any Help would be appreciated.


Solution

  • I found it alas,

    I used window.setInterval(checkStats, 5);in deviceready,

    and it works perfect.