changed the way server address is taken

GPrathap 9 years ago
parent 7037dd99a8
commit 86530bc374

@ -15,21 +15,19 @@
* specific language governing permissions and limitations
* under the License.
*/
//TODO this needs to a private resource
var config_api = function () {
var config_api = this;
var domain = "localhost";
var port = "9793";
var context_controller = "/drone_analyzer/controller/send_command";
config_api.config_3dobject_holder = "#virtualDrone";
config_api.realtime_plotting_update_interval = 30;
config_api.realtime_plotting_totalPoints = 30;
config_api.realtime_plotting_data_window = {};
config_api.effectController = {uy: 70.0, uz: 15.0, ux: 10.0, fx: 2.0, fz: 15.0, Tmax: 1};
config_api.drone_control = "http://" + domain + ":" + port + "/" + context_controller;
config_api.drone_control = context_controller;
config_api.drone_controlType = "POST";
config_api.drone_controlDataType = "json";
config_api.web_socket_endpoint = "wss://localhost:9443/drone_analyzer/datastream/drone_status";
config_api.web_socket_endpoint = "/drone_analyzer/datastream/drone_status";
config_api.modules_status = {
"realtimePlotting": false,
"sensorReadings": false,

@ -58,7 +58,6 @@ $('.btn-minimize').click(function (e) {
if ($target.is(':visible')) {
if ($(this).parent().attr('id') === "RealtimePlotting") {
plotting.forceToRedraw(function (status) {
d3.select("#realtimechart").select("svg").remove();
plotting.realtime_plotting("#realtimechart", "#range_min", "#range_max", "#window_update_value",
600, $("#realtimechart").height(), "#window_size_current_value",
@ -71,33 +70,40 @@ $('.btn-minimize').click(function (e) {
$('#connectionOpen').on('click', function () {
$('#connectionOpen').toggleClass('active');
});
$("#xmppConnectionOpen").on('click', function () {
$('#xmppConnectionOpen').toggleClass('active');
if ($('#xmppConnectionOpen').html() === "Start") {
sendMessage();
$('#xmppConnectionOpen').html("Stop");
sendMessage("Start the process", function(state){
console.log("sending message to server..."+ state);
if(state<2){
$('#xmppConnectionOpen').html("Stop");
}else{
$('#xmppConnectionOpen').html("Start");
}
});
} else if ($('#xmppConnectionOpen').html() === "Stop") {
closeSocket();
$('#xmppConnectionOpen').html("Start");
$("#connectionOpen").html("Connect to server").removeClass("btn btn-info").addClass("btn btn-primary");
closeSocket(function(state){
console.log("closing WebSocket..."+ state);
if(state<2){
$('#xmppConnectionOpen').html("Stop");
}else{
$('#xmppConnectionOpen').html("Start");
}
});
$("#connectionOpen").html("Connect to XMPP Server").removeClass("btn btn-info").addClass("btn btn-primary");
}
});
$('.btn-minimize').parent().parent().next('.box-content').hide();
var webSocket;
config_api.realtime_plotting_data_window["attitude"] = new Queue();
var current_status = {};
function openSocket() {
if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) {
function openSocket(wssAddress) {
if (webSocket !== undefined && webSocket.readyState == 1) {
writeResponse("WebSocket is already opened.");
} else {
webSocket = new WebSocket(config_api.web_socket_endpoint);
webSocket = new WebSocket(wssAddress+config_api.web_socket_endpoint);
}
webSocket.onopen = function (event) {
if (event === undefined) {
@ -121,15 +127,20 @@ function openSocket() {
writeResponse("Message has been corrupted.");
}
};
}
function sendMessage(message) {
webSocket.send(message);
function sendMessage(message, callback) {
if(webSocket.readyState<2){
webSocket.send(message);
}
callback(webSocket.readyState);
}
function closeSocket() {
webSocket.close();
function closeSocket(callback) {
if(webSocket.readyState<2){
webSocket.close();
}
callback(webSocket.readyState);
}
function writeResponse(text) {
@ -137,8 +148,6 @@ function writeResponse(text) {
}
window.onbeforeunload = function () {
webSocket.onclose = function () {
};
webSocket.close()
webSocket.close();
};

@ -17,7 +17,7 @@
*/
$("#module_control button").click(function (index) {
console.log("Asking Server to send the " + $(this).attr('id') + " command to Ar Drone");
var url = config_api.drone_control + "?action=" + $(this).attr('id') + "&speed=6&duration=7";
var url = config_api.drone_control;
ajax_handler.ajaxRequest(url, config_api.drone_controlType, {action: $(this).attr('id'), speed: 7, duration: 7},
config_api.drone_controlDataType, function (data, status) {
console.log(JSON.stringify(data));

@ -6,7 +6,7 @@
<div>
<div class="col-md-2 col-sm-2 col-xs-1">
<button class="btn btn-primary" data-dismiss="modal" id="connectionOpen"
onclick="openSocket();">Connect to server</button>
onclick="openSocket('{{wssAddress}}');">Connect to XMPP Server</button>
</div>
<div class="col-md-2 col-sm-2 col-xs-1">
<button class="btn btn-primary" data-dismiss="modal" id="xmppConnectionOpen">Start</button>
@ -25,7 +25,7 @@
</div>
</div>
</div>
<div class="row">
<!-- <div class="row">
<div class="box col-md-12">
<div class="box-inner">
<div class="box-header well">
@ -85,7 +85,7 @@
</div>
</div>
</div>
</div>
</div>-->
<div class="row">
<div class="box col-md-12">
<div class="box col-md-4">
@ -230,8 +230,6 @@
</div>
</div>
</div>
{{#zone "bottomJs"}}
{{js "/js/d3.min.js" }}
{{js "/js/3dobject_controller/three.min.js" }}

@ -16,27 +16,10 @@
* under the License.
*/
function onRequest (context) {
/*var log = new Log("detail.js");
var deviceType = request.getParameter("type");
var deviceId = request.getParameter("id");
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/modules/device.js").deviceModule;
var device = deviceModule.viewDevice(deviceType, deviceId);
if (device) {
var viewModel = {};
var deviceInfo = device.properties.DEVICE_INFO;
if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) {
deviceInfo = parse(stringify(deviceInfo));
viewModel.system = device.properties.IMEI;
viewModel.machine = "Virtual Firealarm";
viewModel.vendor = device.properties.VENDOR;
}
device.viewModel = viewModel;
}
context.device = device;
return context;
}*/
var log = new Log("statistics.js");
var serverAddress = require("/app/modules/serverAddress.js").serverAddress;
var wssAddress = serverAddress.getWSSAddress();
var httpsAddress = serverAddress.getHPPSTSAddress();
var device = context.unit.params.device;
return { "device": device, "wssAddress": wssAddress, "httpsAddress": httpsAddress};
}
Loading…
Cancel
Save