mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-25 01:53:48 +01:00
Connected redirect fallbacks for old firmware
This commit is contained in:
parent
3ef4829a8e
commit
d08a8a55d9
@ -17,10 +17,11 @@
|
||||
var _pageData = {};
|
||||
var _formData;
|
||||
var _wifiboxid;
|
||||
var _wifiboxSSID;
|
||||
var _connectedChecking = false;
|
||||
|
||||
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 _self = this;
|
||||
@ -57,9 +58,13 @@
|
||||
console.log(PAGE_ID+":retrieveWiFiBoxID");
|
||||
_infoAPI.getInfo(function(infoData) {
|
||||
_wifiboxid = infoData.wifiboxid;
|
||||
_wifiboxSSID = infoData.substituted_ssid;
|
||||
console.log(" _wifiboxid: ",_wifiboxid);
|
||||
console.log(" _wifiboxSSID: ",_wifiboxSSID);
|
||||
completeHandler();
|
||||
},function() {
|
||||
_wifiboxid = undefined;
|
||||
_wifiboxSSID = undefined;
|
||||
// try connecting anyway (making sure wifiboxid retrieval isn't blocking)
|
||||
completeHandler();
|
||||
});
|
||||
@ -75,7 +80,7 @@
|
||||
}
|
||||
function onStatusUpdated(data) {
|
||||
console.log("ConnectingToNetworkPage:onStatusUpdated");
|
||||
console.log(" data: ",data);
|
||||
//console.log(" data: ",data);
|
||||
data.status = parseInt(data.status,10);
|
||||
console.log(" data.status: ",data.status);
|
||||
|
||||
@ -110,9 +115,14 @@
|
||||
|
||||
// When the box is connecting we start checking connect.doodle3d.com
|
||||
// for a box with the same wifiboxid
|
||||
if(data.status === NetworkAPI.STATUS.CONNECTING && !_connectedChecking && _wifiboxid !== undefined) {
|
||||
if(data.status === NetworkAPI.STATUS.CONNECTING && !_connectedChecking) {
|
||||
if(_wifiboxid !== undefined || _wifiboxSSID !== undefined) {
|
||||
_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.boxAppeared = onBoxAppeared;
|
||||
_connectAPI.start();
|
||||
_connectedChecking = true;
|
||||
}
|
||||
@ -120,39 +130,58 @@
|
||||
function onBoxAppeared(boxData) {
|
||||
console.log(PAGE_ID+":onBoxAppeared: ",boxData.localip,boxData.wifiboxid);
|
||||
// if same box is found...
|
||||
if(boxData.wifiboxid === _wifiboxid) {
|
||||
// check if it finished connecting
|
||||
var boxURL = "http://"+boxData.localip;
|
||||
var connectedBoxNetworkAPI = new NetworkAPI();
|
||||
connectedBoxNetworkAPI.init(boxURL);
|
||||
connectedBoxNetworkAPI.updated = function(data) {
|
||||
data.status = parseInt(data.status,10);
|
||||
console.log(PAGE_ID+":connectedBoxNetworkAPI:onStatusUpdated: ",data.status);
|
||||
// if box finished connecting
|
||||
if(data.status === NetworkAPI.STATUS.CONNECTED) {
|
||||
console.log(" found connected box");
|
||||
_statusField.html("Connected to "+_pageData.ssid);
|
||||
_actionField.html("Congratulations the box is connected to <b>"+_pageData.ssid+"</b>. You will be redirected in a moment...");
|
||||
_actionField.attr("class","info");
|
||||
// prevent status changes by wired box
|
||||
_networkAPI.stopAutoRefresh();
|
||||
|
||||
setTimeout(function () {
|
||||
// redirect to it's box page
|
||||
console.log(" redirect to box");
|
||||
var linkParams = {localip: boxData.localip,wifiboxid: boxData.wifiboxid};
|
||||
var link = "#box";
|
||||
link = d3d.util.replaceURLParameters(link,linkParams);
|
||||
$.mobile.changePage(link);
|
||||
connectedBoxNetworkAPI.stopAutoRefresh();
|
||||
|
||||
// disable warnings that are enabled on boxes page
|
||||
d3d.util.disableRefreshPrevention();
|
||||
d3d.util.disableLeaveWarning();
|
||||
},CONNECTED_REDIRECT_DELAY);
|
||||
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);
|
||||
}
|
||||
};
|
||||
connectedBoxNetworkAPI.startAutoRefresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
function checkBox(boxData) {
|
||||
// check if it finished connecting
|
||||
var boxURL = "http://"+boxData.localip;
|
||||
var connectedBoxNetworkAPI = new NetworkAPI();
|
||||
connectedBoxNetworkAPI.init(boxURL);
|
||||
connectedBoxNetworkAPI.updated = function(data) {
|
||||
data.status = parseInt(data.status,10);
|
||||
console.log(PAGE_ID+":connectedBoxNetworkAPI:onStatusUpdated: ",data.status);
|
||||
// if box finished connecting
|
||||
if(data.status === NetworkAPI.STATUS.CONNECTED) {
|
||||
console.log(" found connected box");
|
||||
_statusField.html("Connected to "+_pageData.ssid);
|
||||
_actionField.html("Congratulations the box is connected to <b>"+_pageData.ssid+"</b>. You will be redirected in a moment...");
|
||||
_actionField.attr("class","info");
|
||||
// prevent status changes by wired box
|
||||
_networkAPI.stopAutoRefresh();
|
||||
|
||||
setTimeout(function () {
|
||||
// redirect to it's box page
|
||||
console.log(" redirect to box");
|
||||
var linkParams = {localip: boxData.localip,wifiboxid: boxData.wifiboxid};
|
||||
var link = "#box";
|
||||
link = d3d.util.replaceURLParameters(link,linkParams);
|
||||
$.mobile.changePage(link);
|
||||
connectedBoxNetworkAPI.stopAutoRefresh();
|
||||
|
||||
// disable warnings that are enabled on boxes page
|
||||
d3d.util.disableRefreshPrevention();
|
||||
d3d.util.disableLeaveWarning();
|
||||
},CONNECTED_REDIRECT_DELAY);
|
||||
}
|
||||
};
|
||||
connectedBoxNetworkAPI.startAutoRefresh();
|
||||
}
|
||||
function onListSuccess() {
|
||||
setTimeout(function () {
|
||||
$.mobile.changePage("#boxes");
|
||||
},BACKUP_REDIRECT_DELAY);
|
||||
}
|
||||
})(window);
|
@ -37,12 +37,13 @@ function InfoAPI() {
|
||||
if(failedHandler) failedHandler(response);
|
||||
} else {
|
||||
var infoData = response.data;
|
||||
|
||||
// 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) {
|
||||
_configAPI.save({},function(saveResponseData) {
|
||||
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);
|
||||
},function() {
|
||||
failedHandler();
|
||||
|
Loading…
Reference in New Issue
Block a user