0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-25 18:13:48 +01:00

Connected redirect fallbacks for old firmware

This commit is contained in:
peteruithoven 2014-05-07 23:36:12 +02:00
parent 3ef4829a8e
commit d08a8a55d9
2 changed files with 68 additions and 38 deletions

View File

@ -17,10 +17,11 @@
var _pageData = {}; var _pageData = {};
var _formData; var _formData;
var _wifiboxid; var _wifiboxid;
var _wifiboxSSID;
var _connectedChecking = false; var _connectedChecking = false;
var CONNECTED_REDIRECT_DELAY = 5000; var CONNECTED_REDIRECT_DELAY = 5000;
var BACKUP_REDIRECT_DELAY = 10*1000; // when the wifiboxid isn't retrievable we want to redirect anyway
var PAGE_ID = "#connecting_to_network"; var PAGE_ID = "#connecting_to_network";
var _self = this; var _self = this;
@ -57,9 +58,13 @@
console.log(PAGE_ID+":retrieveWiFiBoxID"); console.log(PAGE_ID+":retrieveWiFiBoxID");
_infoAPI.getInfo(function(infoData) { _infoAPI.getInfo(function(infoData) {
_wifiboxid = infoData.wifiboxid; _wifiboxid = infoData.wifiboxid;
_wifiboxSSID = infoData.substituted_ssid;
console.log(" _wifiboxid: ",_wifiboxid); console.log(" _wifiboxid: ",_wifiboxid);
console.log(" _wifiboxSSID: ",_wifiboxSSID);
completeHandler(); completeHandler();
},function() { },function() {
_wifiboxid = undefined;
_wifiboxSSID = undefined;
// try connecting anyway (making sure wifiboxid retrieval isn't blocking) // try connecting anyway (making sure wifiboxid retrieval isn't blocking)
completeHandler(); completeHandler();
}); });
@ -75,7 +80,7 @@
} }
function onStatusUpdated(data) { function onStatusUpdated(data) {
console.log("ConnectingToNetworkPage:onStatusUpdated"); console.log("ConnectingToNetworkPage:onStatusUpdated");
console.log(" data: ",data); //console.log(" data: ",data);
data.status = parseInt(data.status,10); data.status = parseInt(data.status,10);
console.log(" data.status: ",data.status); console.log(" data.status: ",data.status);
@ -110,9 +115,14 @@
// When the box is connecting we start checking connect.doodle3d.com // When the box is connecting we start checking connect.doodle3d.com
// for a box with the same wifiboxid // for a box with the same wifiboxid
if(data.status === NetworkAPI.STATUS.CONNECTING && !_connectedChecking && _wifiboxid !== undefined) { if(data.status === NetworkAPI.STATUS.CONNECTING && !_connectedChecking) {
_connectAPI.checkLocal = false; if(_wifiboxid !== undefined || _wifiboxSSID !== undefined) {
_connectAPI.boxAppeared = onBoxAppeared; _connectAPI.boxAppeared = onBoxAppeared;
} else {
// if there is no wifiboxid or ssid available we'll check if we're online
_connectAPI.listSuccess = onListSuccess;
}
_connectAPI.checkLocal = false;
_connectAPI.start(); _connectAPI.start();
_connectedChecking = true; _connectedChecking = true;
} }
@ -120,7 +130,22 @@
function onBoxAppeared(boxData) { function onBoxAppeared(boxData) {
console.log(PAGE_ID+":onBoxAppeared: ",boxData.localip,boxData.wifiboxid); console.log(PAGE_ID+":onBoxAppeared: ",boxData.localip,boxData.wifiboxid);
// if same box is found... // if same box is found...
if(boxData.wifiboxid === _wifiboxid) { if(_wifiboxid !== undefined && boxData.wifiboxid === _wifiboxid) {
console.log("found _wifiboxid");
checkBox(boxData);
// wifiboxid of older firmware isn't available, fallback to ssid
} else if(_wifiboxSSID !== undefined){
console.log("no _wifiboxid, falling back to _wifiboxSSID comparison");
var connectedBoxConfigAPI = new ConfigAPI();
connectedBoxConfigAPI.init("http://"+boxData.localip);
connectedBoxConfigAPI.save({},function(saveResponseData) {
if(saveResponseData.substituted_ssid === _wifiboxSSID) {
checkBox(boxData);
}
});
}
}
function checkBox(boxData) {
// check if it finished connecting // check if it finished connecting
var boxURL = "http://"+boxData.localip; var boxURL = "http://"+boxData.localip;
var connectedBoxNetworkAPI = new NetworkAPI(); var connectedBoxNetworkAPI = new NetworkAPI();
@ -154,5 +179,9 @@
}; };
connectedBoxNetworkAPI.startAutoRefresh(); connectedBoxNetworkAPI.startAutoRefresh();
} }
function onListSuccess() {
setTimeout(function () {
$.mobile.changePage("#boxes");
},BACKUP_REDIRECT_DELAY);
} }
})(window); })(window);

View File

@ -37,12 +37,13 @@ function InfoAPI() {
if(failedHandler) failedHandler(response); if(failedHandler) failedHandler(response);
} else { } else {
var infoData = response.data; var infoData = response.data;
// Versions older than 0.10.2 don't include wifiboxid in info response // Versions older than 0.10.2 don't include wifiboxid in info response
// so we use a workaround (saving to config) // so we use a workaround (saving to config to retrieve substituted_wifiboxid or substituted_ssid)
if(infoData.wifiboxid === undefined) { if(infoData.wifiboxid === undefined) {
_configAPI.save({},function(saveResponseData) { _configAPI.save({},function(saveResponseData) {
infoData.wifiboxid = saveResponseData.substituted_wifiboxid; infoData.wifiboxid = saveResponseData.substituted_wifiboxid;
// when no wifiboxid is available we could use the substituted_ssid to compare
infoData.substituted_ssid = saveResponseData.substituted_ssid;
completeHandler(infoData); completeHandler(infoData);
},function() { },function() {
failedHandler(); failedHandler();