0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-25 01:53:48 +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){ success: function(response){
//console.log("retrieveList response: ",response); //console.log("retrieveList response: ",response);
if(response.status == "success") { if(response.status == "success") {
updateList(response.data); var foundBoxes = response.data;
foundBoxes.push(connectedBox);
updateList(foundBoxes);
} }
clearTimeout(retrieveListDelay); clearTimeout(retrieveListDelay);
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval); retrieveListDelay = setTimeout(retrieveList, retrieveListInterval);
} }
}).fail(function() { }).fail(function() {
console.log("retrieveList: failed"); 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); clearTimeout(retrieveListDelay);
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval); // retry after delay retrieveListDelay = setTimeout(retrieveList, retrieveListInterval); // retry after delay
}); });
@ -82,9 +90,7 @@ function updateList(boxes) {
numBoxesFound = 0; numBoxesFound = 0;
if (boxes===undefined) boxes = []; if (boxes===undefined) boxes = [];
boxes.push(connectedBox);
// remove displayed, but unlisted boxes // remove displayed, but unlisted boxes
$list.find("a").each(function(index, element) { $list.find("a").each(function(index, element) {
var localip = $(element).attr("id"); var localip = $(element).attr("id");
@ -103,14 +109,15 @@ function updateList(boxes) {
updateIntro(); updateIntro();
} }
function checkBox(box) { function checkBox(box,checked) {
numBoxesChecking++; numBoxesChecking++;
$.ajax({ $.ajax({
url: "http://"+box.localip+"/d3dapi/network/alive", url: "http://"+box.localip+"/d3dapi/network/alive",
dataType: "json", dataType: "json",
timeout: boxTimeoutTime, timeout: boxTimeoutTime,
success: function(response){ success: function(response){
if(response.status == "success") { var alive = (response.status == "success");
if(alive) {
numBoxesFound++; numBoxesFound++;
addBox(box); addBox(box);
} else { } else {
@ -118,12 +125,14 @@ function checkBox(box) {
} }
numBoxesChecking--; numBoxesChecking--;
updateIntro(); updateIntro();
if(checked) checked(alive);
} }
}).fail(function() { }).fail(function() {
//console.log("box not alive: "+box.wifiboxid); //console.log("box not alive: "+box.wifiboxid);
numBoxesChecking--; numBoxesChecking--;
removeBox(box); removeBox(box);
updateIntro(); updateIntro();
if(checked) checked(false);
}); });
} }