0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-15 23:27:57 +01:00
doodle3d-client/js/api/NetworkAPI.js

122 lines
3.1 KiB
JavaScript
Raw Normal View History

/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
function NetworkAPI() {
NetworkAPI.STATUS = {
CONNECTING_FAILED: -1,
NOT_CONNECTED: 0,
CONNECTING: 1,
CONNECTED: 2,
CREATING: 3,
CREATED: 4
};
var _wifiboxURL;
var _wifiboxCGIBinURL;
var _timeoutTime = 3000;
var _self = this;
this.init = function(wifiboxURL,wifiboxCGIBinURL) {
2014-02-10 14:46:23 +01:00
//console.log("NetworkAPI:init");
//console.log(" wifiboxURL: ",wifiboxURL);
//console.log(" wifiboxCGIBinURL: ",wifiboxCGIBinURL);
_wifiboxURL = wifiboxURL;
_wifiboxCGIBinURL = wifiboxCGIBinURL;
}
2014-02-10 14:44:17 +01:00
this.scan = function(completeHandler,failedHandler) {
2014-02-04 22:56:58 +01:00
//console.log("NetworkAPI:scan");
$.ajax({
url: _wifiboxURL + "/network/scan",
type: "GET",
dataType: 'json',
timeout: _timeoutTime,
success: function(response){
//console.log("NetworkAPI:scan response: ",response);
if(response.status == "error" || response.status == "fail") {
2014-02-10 14:44:17 +01:00
//console.log("NetworkAPI:scan failed: ",response);
if(failedHandler) failedHandler(response);
} else {
completeHandler(response.data);
}
}
}).fail(function() {
2014-02-10 14:44:17 +01:00
//console.log("NetworkAPI:scan failed");
if(failedHandler) failedHandler();
});
};
this.status = function(completeHandler,failedHandler) {
//console.log("NetworkAPI:status");
$.ajax({
url: _wifiboxURL + "/network/status",
type: "GET",
dataType: 'json',
timeout: _timeoutTime,
success: function(response){
//console.log("NetworkAPI:status response: ",response);
if(response.status == "error" || response.status == "fail") {
2014-02-10 14:44:17 +01:00
if(failedHandler) failedHandler(response);
} else {
completeHandler(response.data);
}
}
}).fail(function() {
2014-02-10 14:44:17 +01:00
if(failedHandler) failedHandler();
});
};
this.associate = function(ssid,phrase,recreate) {
2014-02-10 14:46:23 +01:00
//console.log("NetworkAPI:associate");
var postData = {
ssid:ssid,
phrase:phrase,
recreate:recreate
};
$.ajax({
url: _wifiboxCGIBinURL + "/network/associate",
type: "POST",
data: postData,
dataType: 'json',
timeout: _timeoutTime,
success: function(response){
2014-02-04 22:56:58 +01:00
//console.log("NetworkAPI:associate response: ",response);
}
}).fail(function() {
2014-02-04 22:56:58 +01:00
//console.log("NetworkAPI:associate: timeout (normal behavior)");
});
};
2014-02-04 14:34:03 +01:00
this.openAP = function() {
2014-02-10 14:46:23 +01:00
//console.log("NetworkAPI:openAP");
2014-02-04 14:34:03 +01:00
$.ajax({
url: _wifiboxCGIBinURL + "/network/openap",
type: "POST",
dataType: 'json',
timeout: _timeoutTime,
success: function(response){
2014-02-04 22:56:58 +01:00
//console.log("NetworkAPI:openAP response: ",response);
2014-02-04 14:34:03 +01:00
}
}).fail(function() {
2014-02-04 22:56:58 +01:00
//console.log("NetworkAPI:openAP: timeout (normal behavior)");
2014-02-04 14:34:03 +01:00
});
};
this.signin = function() {
$.ajax({
2014-02-07 12:32:35 +01:00
url: _wifiboxCGIBinURL + "/network/signin",
type: "GET",
dataType: 'json',
2014-02-07 12:32:35 +01:00
timeout: _timeoutTime,
success: function(response){
2014-02-10 14:46:23 +01:00
//console.log("NetworkAPI:signin response: ",response);
}
}).fail(function() {
2014-02-10 14:46:23 +01:00
//console.log("NetworkAPI:signin: failed");
});
};
}