WiseLoop JavaScript Network Speed Tester 2.1.2
JavaScript Bandwidth Checker
Measuring ping time

A very basic JavaScript AngularJS app using our bandwidth measurement module should look like:

 <html ng-app="demo-app" ng-controller="demoAppController">
    <head>
        <script type="text/javascript" src="../bins/lib/angular/angular.min.js"></script>
        <script type="text/javascript" src="../bins/wl-ng-network-speed-tester.js"></script>
        <script type="text/javascript">
            //must set the bins url
            angular.module('wl-ng-network-speed-tester').value('bins', '../bins');

            //create an AngularJS module with a dependency to our bandwidth tester
            var demoApp = angular.module('demo-app', ['wl-ng-network-speed-tester']);
            //declare a controller with a dependency on network speed tester service (wlNgNSTService)
            demoApp.controller('demoAppController', function(wlNgNSTService) {
                //call the ping method of the service
                wlNgNSTService.ping()
                .then(function(pingTime) {
                    //on success display the ping time
                    alert('Ping time: ' + pingTime + ' seconds');
                }, function(error) {
                    //on error ...
                    alert('Oops!');
                });
            });
        </script>
    </head>
</html>

Looking at the JavaScript code above, after setting up our bandwidth module, we created a basic AngularJS module (application) called demo-app with a dependency to our bandwidth module wl-ng-network-speed-tester:

var demoApp = angular.module('demo-app', ['wl-ng-network-speed-tester']);

Then, we created a controller inside the demo application having a dependency to our network speed tester (wlNgNSTService):

demoApp.controller('demoAppController', function(wlNgNSTService) {
    wlNgNSTService.ping()
        .then(function(pingTime) {
            alert(pingTime);
        }, function(error) {
            alert('Oops!');
        });
});

The code above is pretty much self explanatory: ping() method of the service is called and if everything goes fine, the ping time is displayed inside an alert box.

tut-service-ping.png
Ping
Note:
Please note that the the directive will call this service method multiple times (see iteration attribute) and will offer an average result increasing the accuracy of the measurement.