check if URL or IP address is valid
function cameraOn(ip) {
var timeout = 1500;
var img = new Image();
img.onload = success;
img.onerror = fail;
img.src = "http://" + ip + "/image/brickcom_logo.gif";
// Time out
var timer = setTimeout(fail, timeout);
function cleanup() {
window.clearTimeout(timer);
img.src = null;
}
function success() {
cleanup();
console.log('sucess');
}
function fail() {
cleanup();
console.log('fail');
}
}
function pingIt(ip) {
this.isCameraOn = null;
if(!this.inUse) {
this.inUse = true;
this.ip = ip;
var _that = this;
this.img = new Image();
this.img.onload = function() {good();};
this.img.onerror = function() {bad();};
this.start = new Date().getTime();
this.img.src = "http://" + ip + "/image/brickcom_logo.gif";
this.timer = setTimeout(function() {bad();}, 1500);
}
function cleanup() {
this.inUse = true;
window.clearTimeout(this.timer);
this.img.src = null;
}
function good() {
this.isCameraOn = true;
console.log('sucess ');
cleanup();
}
function bad() {
this.isCameraOn = false;
console.log('fail');
cleanup();
}
}