0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-11-05 07:03:24 +01:00

Search for boxes in access point (hide wired box if found)

This commit is contained in:
peteruithoven 2014-02-16 01:48:40 +01:00
parent 9ecee8b074
commit 4fb58d0878

View File

@ -64,14 +64,22 @@ function retrieveList() {
success: function(response){
//console.log("retrieveList response: ",response);
if(response.status == "success") {
updateList(response.data);
var foundBoxes = response.data;
foundBoxes.push(connectedBox);
updateList(foundBoxes);
}
clearTimeout(retrieveListDelay);
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval);
}
}).fail(function() {
console.log("retrieveList: failed");
updateList([apBox]); //if web is not accessible try to find the box as an accesspoint
// if web is not accessible try to find the box as an accesspoint
// if not found, we look for a wired box
checkBox(apBox, function(alive) {
if(alive) updateList([apBox]);
else updateList([connectedBox]);
});
clearTimeout(retrieveListDelay);
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval); // retry after delay
});
@ -82,9 +90,7 @@ function updateList(boxes) {
numBoxesFound = 0;
if (boxes===undefined) boxes = [];
boxes.push(connectedBox);
// remove displayed, but unlisted boxes
$list.find("a").each(function(index, element) {
var localip = $(element).attr("id");
@ -103,14 +109,15 @@ function updateList(boxes) {
updateIntro();
}
function checkBox(box) {
function checkBox(box,checked) {
numBoxesChecking++;
$.ajax({
url: "http://"+box.localip+"/d3dapi/network/alive",
dataType: "json",
timeout: boxTimeoutTime,
success: function(response){
if(response.status == "success") {
var alive = (response.status == "success");
if(alive) {
numBoxesFound++;
addBox(box);
} else {
@ -118,12 +125,14 @@ function checkBox(box) {
}
numBoxesChecking--;
updateIntro();
if(checked) checked(alive);
}
}).fail(function() {
//console.log("box not alive: "+box.wifiboxid);
numBoxesChecking--;
removeBox(box);
updateIntro();
if(checked) checked(false);
});
}