mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-25 18:13:48 +01:00
re-associate / reconnect to known networks
This commit is contained in:
parent
7db7086a25
commit
46ac18e817
@ -44,8 +44,10 @@
|
|||||||
if(_pageData.encryption === "") {
|
if(_pageData.encryption === "") {
|
||||||
_pageData.encryption = "none";
|
_pageData.encryption = "none";
|
||||||
}
|
}
|
||||||
if(_pageData === undefined ||
|
// if(_pageData === undefined ||
|
||||||
(_pageData.encryption !== "none" && form.length === 0)) {
|
// (_pageData.encryption !== "none" && form.length === 0)) {
|
||||||
|
if (_pageData === undefined) { // || (_pageData.encryption !== "none" && form.length === 0)) {
|
||||||
|
//RC: removed this check because it makes it more difficult to re-associate with a known network
|
||||||
$.mobile.changePage("#boxes");
|
$.mobile.changePage("#boxes");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -85,7 +87,8 @@
|
|||||||
}
|
}
|
||||||
function joinNetwork() {
|
function joinNetwork() {
|
||||||
console.log(PAGE_ID+":joinNetwork");
|
console.log(PAGE_ID+":joinNetwork");
|
||||||
_networkAPI.associate(_pageData.ssid,_formData.password,true);
|
//_networkAPI.associate(_pageData.ssid,_formData.password,true); //recreate=true
|
||||||
|
_networkAPI.associate(_pageData.ssid,_formData.password,false);
|
||||||
_connectedChecking = false;
|
_connectedChecking = false;
|
||||||
}
|
}
|
||||||
function onRefreshing() {
|
function onRefreshing() {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
var _networkAPI = new NetworkAPI();
|
var _networkAPI = new NetworkAPI();
|
||||||
var _boxData = {};
|
var _boxData = {};
|
||||||
var _refreshDelay;
|
var _refreshDelay;
|
||||||
|
var _knownSSIDs;
|
||||||
var _refreshDelayTime = 3000;
|
var _refreshDelayTime = 3000;
|
||||||
var PAGE_ID = "#join_network";
|
var PAGE_ID = "#join_network";
|
||||||
|
|
||||||
@ -26,6 +27,7 @@
|
|||||||
_list = _page.find("ul[data-role=listview]");
|
_list = _page.find("ul[data-role=listview]");
|
||||||
//_joinOtherItem = _list.find("#joinOther");
|
//_joinOtherItem = _list.find("#joinOther");
|
||||||
});
|
});
|
||||||
|
|
||||||
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
||||||
console.log("Join network page pagebeforeshow");
|
console.log("Join network page pagebeforeshow");
|
||||||
_boxData = d3d.util.getPageParams(PAGE_ID);
|
_boxData = d3d.util.getPageParams(PAGE_ID);
|
||||||
@ -37,20 +39,32 @@
|
|||||||
console.log(" _boxData: ",_boxData);
|
console.log(" _boxData: ",_boxData);
|
||||||
|
|
||||||
_networkAPI.init(boxURL);
|
_networkAPI.init(boxURL);
|
||||||
|
|
||||||
|
_networkAPI.knownSSIDs(function(successData) {
|
||||||
|
console.log("known",successData);
|
||||||
|
_knownSSIDs = successData;
|
||||||
refreshNetworks();
|
refreshNetworks();
|
||||||
|
},function(failData) {
|
||||||
|
console.log("known networks fail");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
|
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
|
||||||
console.log("Join network page pagehide");
|
console.log("Join network page pagehide");
|
||||||
clearTimeout(_refreshDelay);
|
clearTimeout(_refreshDelay);
|
||||||
});
|
});
|
||||||
|
|
||||||
function refreshNetworks() {
|
function refreshNetworks() {
|
||||||
//console.log("JoinNetwork:refreshNetworks");
|
//console.log("JoinNetwork:refreshNetworks");
|
||||||
d3d.util.showLoader();
|
d3d.util.showLoader();
|
||||||
_networkAPI.scan(function(data) { // completed
|
_networkAPI.scan(function(data) { // completed
|
||||||
// console.log("JoinNetwork:refreshNetworks:scanned");
|
// console.log("JoinNetwork:refreshNetworks:scanned");
|
||||||
|
// console.log(data);
|
||||||
d3d.util.hideLoader();
|
d3d.util.hideLoader();
|
||||||
_networks = {};
|
_networks = {};
|
||||||
$.each(data.networks, function(index,network) {
|
$.each(data.networks, function(index,network) {
|
||||||
|
network.known = _knownSSIDs.indexOf(network.ssid)>-1;
|
||||||
_networks[network.ssid] = network;
|
_networks[network.ssid] = network;
|
||||||
});
|
});
|
||||||
// update list
|
// update list
|
||||||
@ -60,32 +74,53 @@
|
|||||||
_refreshDelay = setTimeout(refreshNetworks, _refreshDelayTime);
|
_refreshDelay = setTimeout(refreshNetworks, _refreshDelayTime);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateList() {
|
function updateList() {
|
||||||
_list.empty();
|
_list.empty();
|
||||||
var baseConnectingLink = _list.data("connecting-target");
|
var baseConnectingLink = _list.data("connecting-target");
|
||||||
var baseSecuredLink = _list.data("secured-target");
|
var baseSecuredLink = _list.data("secured-target");
|
||||||
var linkParams = $.extend({}, _boxData);
|
var linkParams = $.extend({}, _boxData);
|
||||||
//console.log(" linkParams: ",linkParams);
|
//console.log(" linkParams: ",linkParams);
|
||||||
$.each(_networks, function(index,network) {
|
// $.each(_networks, function(index,network) {
|
||||||
//console.log(" network: ",network);
|
//console.log(" network: ",network);
|
||||||
|
|
||||||
|
var _ssids = $.map(_networks, function(obj) {
|
||||||
|
return obj.ssid;
|
||||||
|
});
|
||||||
|
|
||||||
|
_ssids.sort(function(a, b) {
|
||||||
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||||
|
});
|
||||||
|
|
||||||
|
// $.each(_ssids, function(ssid) {
|
||||||
|
for (var i=0; i<_ssids.length; i++) {
|
||||||
|
var ssid = _ssids[i];
|
||||||
|
|
||||||
|
var network = _networks[ssid];
|
||||||
|
|
||||||
linkParams.ssid = network.ssid;
|
linkParams.ssid = network.ssid;
|
||||||
|
|
||||||
var secured = (network.encryption !== "none" && network.encryption !== "");
|
var secured = (network.encryption !== "none" && network.encryption !== "");
|
||||||
var link;
|
var link;
|
||||||
var icon = "";
|
var icon = secured ? "lock" : "alert";
|
||||||
linkParams.encryption = network.encryption;
|
linkParams.encryption = network.encryption;
|
||||||
if(secured) {
|
|
||||||
link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams);
|
if (!secured || network.known) { //skip the password page
|
||||||
icon = "lock";
|
|
||||||
} else {
|
|
||||||
link = d3d.util.replaceURLParameters(baseConnectingLink,linkParams);
|
link = d3d.util.replaceURLParameters(baseConnectingLink,linkParams);
|
||||||
|
} else {
|
||||||
|
link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var className = (network.known ? 'knownNetwork' : ''); //previously joined
|
||||||
|
|
||||||
//console.log(" link: ",link);
|
//console.log(" link: ",link);
|
||||||
_list.append(
|
_list.append(
|
||||||
$('<li data-icon="'+icon+'"><a href="'+link+'">'+network.ssid+'</a></li>')
|
// $('<li data-icon="'+icon+'"><a href="'+link+'">'+network.ssid+'</a></li>')
|
||||||
|
$('<li class="'+className+'" data-icon="'+icon+'"><a href="'+link+'">'+network.ssid+'</a></li>')
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
//_list.append(_joinOtherItem);
|
//_list.append(_joinOtherItem);
|
||||||
_list.listview('refresh'); // jQuery mobile enhance content
|
_list.listview('refresh'); // jQuery mobile enhance content
|
||||||
}
|
}
|
||||||
|
|
||||||
})(window);
|
})(window);
|
@ -57,7 +57,7 @@ function NetworkAPI() {
|
|||||||
//console.log("NetworkAPI:scan failed: ",response);
|
//console.log("NetworkAPI:scan failed: ",response);
|
||||||
if(failedHandler) failedHandler(response);
|
if(failedHandler) failedHandler(response);
|
||||||
} else {
|
} else {
|
||||||
completeHandler(response.data);
|
if (completeHandler) completeHandler(response.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
@ -65,6 +65,31 @@ function NetworkAPI() {
|
|||||||
if(failedHandler) failedHandler();
|
if(failedHandler) failedHandler();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.knownSSIDs = function(completeHandler,failedHandler) {
|
||||||
|
$.ajax({
|
||||||
|
url: _wifiboxURL + "/network/known",
|
||||||
|
type: "GET",
|
||||||
|
dataType: 'json',
|
||||||
|
timeout: _timeoutTime,
|
||||||
|
success: function(response){
|
||||||
|
console.log("knownSSIDs",response);
|
||||||
|
|
||||||
|
if (response.status == "error" || response.status == "fail") {
|
||||||
|
if (failedHandler) failedHandler(response);
|
||||||
|
} else {
|
||||||
|
if (completeHandler) completeHandler(response.data.networks.map(function(obj) {
|
||||||
|
return obj.ssid;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).fail(function() {
|
||||||
|
console.log("knownSSIDs fail");
|
||||||
|
if (failedHandler) failedHandler();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.status = function(completeHandler,failedHandler) {
|
this.status = function(completeHandler,failedHandler) {
|
||||||
//console.log("NetworkAPI:status");
|
//console.log("NetworkAPI:status");
|
||||||
// After switching wifi network or creating a access point we delay the actual status
|
// After switching wifi network or creating a access point we delay the actual status
|
||||||
@ -144,8 +169,7 @@ function NetworkAPI() {
|
|||||||
console.log(" phrase: ",phrase);
|
console.log(" phrase: ",phrase);
|
||||||
var postData = {
|
var postData = {
|
||||||
ssid:ssid,
|
ssid:ssid,
|
||||||
phrase:phrase,
|
phrase:phrase
|
||||||
recreate:recreate
|
|
||||||
};
|
};
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: _wifiboxCGIBinURL + "/network/associate",
|
url: _wifiboxCGIBinURL + "/network/associate",
|
||||||
|
@ -250,3 +250,6 @@ html head + body .ui-body-a.ui-focus {
|
|||||||
/*color: #93CAF4;*/
|
/*color: #93CAF4;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li.knownNetwork a {
|
||||||
|
color: #5fba7d !important;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user