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 _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) {
|
||||||
|
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.checkLocal = false;
|
||||||
_connectAPI.boxAppeared = onBoxAppeared;
|
|
||||||
_connectAPI.start();
|
_connectAPI.start();
|
||||||
_connectedChecking = true;
|
_connectedChecking = true;
|
||||||
}
|
}
|
||||||
@ -120,39 +130,58 @@
|
|||||||
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) {
|
||||||
// check if it finished connecting
|
console.log("found _wifiboxid");
|
||||||
var boxURL = "http://"+boxData.localip;
|
checkBox(boxData);
|
||||||
var connectedBoxNetworkAPI = new NetworkAPI();
|
// wifiboxid of older firmware isn't available, fallback to ssid
|
||||||
connectedBoxNetworkAPI.init(boxURL);
|
} else if(_wifiboxSSID !== undefined){
|
||||||
connectedBoxNetworkAPI.updated = function(data) {
|
console.log("no _wifiboxid, falling back to _wifiboxSSID comparison");
|
||||||
data.status = parseInt(data.status,10);
|
var connectedBoxConfigAPI = new ConfigAPI();
|
||||||
console.log(PAGE_ID+":connectedBoxNetworkAPI:onStatusUpdated: ",data.status);
|
connectedBoxConfigAPI.init("http://"+boxData.localip);
|
||||||
// if box finished connecting
|
connectedBoxConfigAPI.save({},function(saveResponseData) {
|
||||||
if(data.status === NetworkAPI.STATUS.CONNECTED) {
|
if(saveResponseData.substituted_ssid === _wifiboxSSID) {
|
||||||
console.log(" found connected box");
|
checkBox(boxData);
|
||||||
_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 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);
|
})(window);
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user