Created
August 10, 2016 10:02
-
-
Save rhyttr/e77e581deff7254a735570a96526e252 to your computer and use it in GitHub Desktop.
angular.ping.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('pingService', []) | |
.factory('ping', ['$http', function($http) { | |
// Pings a URL or IP using HTTP GET request | |
return { | |
ping: function(URL, callback) { | |
var responseTime = 0; | |
var start = (new Date()).getTime(); | |
$http.get(URL + '?rnd=' + (new Date().getTime())) | |
.success(function() { | |
responseTime = (new Date().getTime()) - start; | |
callback(Math.round(responseTime / 10) / 100); | |
}) | |
.error(function() { | |
callback(responseTime); | |
}) | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment