}))
// Open the DevTools.
- mainWindow.webContents.openDevTools()
+ //mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
try {
mainWindow.webContents.send('newTracking',str);
+ if(typeof odas_process == 'undefined') {
+ mainWindow.webContents.send('remote-online');
+ }
}
catch(err) {
function onConnClose() {
console.log('connection from %s closed', remoteAddress);
+ mainWindow.webContents.send('remote-offline');
}
function onConnError(err) {
try {
mainWindow.webContents.send('newPotential',str);
+ if(typeof odas_process == 'undefined') {
+ mainWindow.webContents.send('remote-online', conn.remoteAddress);
+ }
}
catch(err) {
function onConnClose() {
console.log('connection from %s closed', remoteAddress);
+ mainWindow.webContents.send('remote-offline');
}
function onConnError(err) {
console.log('Connection %s error: %s', remoteAddress, err.message);
}
}
+
+
+/*
+ * ODAS Control
+ */
+
+const ipcMain = electron.ipcMain
+const child_process = require('child_process')
+
+let odas_process
+
+ipcMain.on('launch-odas', function(event, core, config) {
+
+ console.log('received launch command')
+ console.log(core)
+ console.log(config)
+
+ odas_process = child_process.spawn(core, ['-c', config])
+
+ event.sender.send('launched-odas', true)
+})
+
+
+ipcMain.on('stop-odas', function(event) {
+
+ odas_process.kill('SIGINT')
+ odas_process = undefined
+
+ console.log('received stop command')
+})
reader.readAsArrayBuffer(msg.data);
};
+
+
+/*
+ * ODAS Launcher
+ */
+
+const dialog = require('electron').remote.dialog
+
+const core_path_field = document.getElementById('odas-core-path')
+const config_path_field = document.getElementById('odas-config-path')
+const launch_btn = document.getElementById('odas-btn')
+
+const odas_local_well = document.getElementById('odas-local')
+const odas_remote_well = document.getElementById('odas-remote')
+
+let odas_core_path
+let odas_config_path
+
+if(localStorage.odas_core_path) {
+ odas_core_path = localStorage.odas_core_path
+ core_path_field.value = odas_core_path
+}
+
+if(localStorage.odas_config_path) {
+ odas_config_path = localStorage.odas_config_path
+ config_path_field.value = odas_config_path
+}
+
+
+core_path_field.addEventListener('click', function() {
+
+ dialog.showOpenDialog(
+ { properties: ['openFile'], title: 'Browse ODAS Core executable'},
+ function (files) {
+
+ if(files) {
+ let path = files[0]
+ odas_core_path = path
+ core_path_field.value = odas_core_path
+ localStorage.odas_core_path = odas_core_path
+ }
+ })
+})
+
+
+config_path_field.addEventListener('click', function() {
+
+ dialog.showOpenDialog(
+ { properties: ['openFile'], title: 'Browse ODAS config file'},
+ function (files) {
+
+ if(files) {
+ let path = files[0]
+ odas_config_path = path
+ config_path_field.value = odas_config_path
+ localStorage.odas_config_path = odas_config_path
+ }
+ })
+})
+
+
+const launchOdas = function() {
+
+ if(typeof odas_core_path == 'undefined') {
+
+ dialog.showMessageBox({
+ type:'info',
+ buttons:['OK'],
+ title:'Error',
+ message:'Core path not set.',
+ detail:'Please set ODAS Core path before launching ODAS.'
+ })
+
+ return
+ }
+
+
+ if(typeof odas_config_path == 'undefined') {
+
+ dialog.showMessageBox({
+ type:'info',
+ buttons:['OK'],
+ title:'Error',
+ message:'Config file path not set.',
+ detail:'Please set ODAS configuration file path before launching ODAS.'
+ })
+
+ return
+ }
+
+ ipcRenderer.send('launch-odas', odas_core_path, odas_config_path)
+ launch_btn.removeEventListener('click', launchOdas)
+ launch_btn.innerHTML = 'Launching...'
+}
+
+
+const stopOdas = function() {
+
+ ipcRenderer.send('stop-odas')
+
+ launch_btn.innerHTML = 'Launch ODAS'
+ launch_btn.removeEventListener('click', stopOdas)
+ launch_btn.addEventListener('click', launchOdas)
+
+ setTimeout(function() {document.dispatchEvent(new Event('clearChart'));}, 1000)
+}
+
+launch_btn.addEventListener('click', launchOdas)
+
+
+ipcRenderer.on('launched-odas', function(sender, ok) {
+
+ if(ok) {
+ launch_btn.innerHTML = 'Stop ODAS'
+ launch_btn.addEventListener('click', stopOdas)
+ }
+})
+
+ipcRenderer.on('remote-online', function(ip) {
+ odas_remote_well.style.display = 'block'
+ odas_local_well.style.display = 'none'
+
+})
+
+ipcRenderer.on('remote-offline', function() {
+ odas_remote_well.style.display = 'none'
+ odas_local_well.style.display = 'block'
+ setTimeout(function() {document.dispatchEvent(new Event('clearChart'));}, 1000)
+})
+
+odas_remote_well.style.display = 'none'
+++ /dev/null
-/*
- * Create web server
- */
-
-// Load modules
-var express = require('express');
-var path = require('path');
-var events = require('events');
-var StringDecoder = require('string_decoder').StringDecoder;
-
-// Prep app and event manager
-var app = express();
-var expressWs = require('express-ws')(app);
-
-var eventEmitter = new events.EventEmitter();
-
-// Deliver static ressources
-app.use(express.static('ressources'));
-
-// Main page route
-app.get('/', function(req, res) {
- res.sendFile(path.join(__dirname+'/views/live_data.html'));
-});
-
-// Config page route
-app.get('/config', function(req, res) {
- res.sendFile(path.join(__dirname+'/views/configure.html'));
-});
-
-// Legal page route
-app.get('/legal', function(req, res) {
- res.sendFile(path.join(__dirname+'/views/legal.html'));
-});
-
-// Websocket to stream tracking
-app.ws('/tracking',function(ws, req) {
-
- // Sends new data to client
- var sendData = function(data) {
-
- try {
- ws.send(data);
- }
-
- catch(e) {
- console.warn('Socket closed');
- }
- };
-
- // Register client to event
- eventEmitter.on('newTracking',sendData);
- console.log('registered tracking');
-
- // Remove listener when connection closes
- ws.on('close', function() {
- eventEmitter.removeListener('newTracking',sendData);
- });
-
-});
-
-// Websocket to stream potential sources
-app.ws('/potential',function(ws, req) {
-
- // Sends new data to client
- var sendData = function(data) {
-
- try {
- ws.send(data);
- }
-
- catch(e) {
- console.warn('Socket closed');
- }
- };
-
- // Register client to event
- eventEmitter.on('newPotential',sendData);
- console.log('registered potential');
-
- // Remove listener when connection closes
- ws.on('close', function() {
- eventEmitter.removeListener('newPotential',sendData);
- });
-
-});
-
-// Websocket to stream system information
-app.ws('/system.info',function(ws, req) {
-
- // Sends new data to client
- var sendData = function(data) {
-
- try {
- ws.send(JSON.stringify(data));
- }
-
- catch(e) {
- console.warn('Socket closed');
- }
- };
-
- // Register client to event
- eventEmitter.on('sysInfo',sendData);
- console.log('registered sysInfo');
-
- // Remove listener when connection closes
- ws.on('close', function() {
- eventEmitter.removeListener('sysInfo',sendData);
- });
-
-});
-
-// Websocket to stream audio
-app.ws('/audio',function(ws, req) {
-
- // Sends new data to client
- var sendData = function(data) {
-
- try {
- ws.send(data);
- console.log(`Sent audio on ${new Date().getTime()}`);
- }
-
- catch(e) {
- console.warn('Socket closed');
- }
- };
-
- // Register client to event
- eventEmitter.on('newAudio',sendData);
- console.log('registered audio');
-
- // Remove listener when connection closes
- ws.on('close', function() {
- eventEmitter.removeListener('newAudio',sendData);
- });
-
-});
-
-// Redirect to main page
-app.use(function(req, res, next){
- res.sendFile(path.join(__dirname+'/live_data.html'));
-});
-
-// Starts web server
-app.listen(8080);
-console.log('Listening...');
-
-
-/*
- * Create TCP server for source tracking
- */
-
-// Load modules
-var net = require('net');
-
-var server = net.createServer();
-server.on('connection', handleConnection);
-
-server.listen(9000, function() {
- console.log('server listening to %j', server.address());
-});
-
-function handleConnection(conn) {
- var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
- console.log('new client connection from %s', remoteAddress);
-
- conn.on('data', onConnData);
- conn.once('close', onConnClose);
- conn.on('error', onConnError);
-
- function onConnData(d) {
-
- var decoder = new StringDecoder();
-
- // Decode received string
- var str = decoder.write(d);
-
- eventEmitter.emit('newTracking',str);
-
- }
-
- function onConnClose() {
- console.log('connection from %s closed', remoteAddress);
- }
-
- function onConnError(err) {
- console.log('Connection %s error: %s', remoteAddress, err.message);
- }
-}
-
-
-/*
- * Create TCP server for potential sources
- */
-
-var potentialServer = net.createServer();
-potentialServer.on('connection', handlePotConnection);
-
-potentialServer.listen(9001, function() {
- console.log('server listening to %j', potentialServer.address());
-});
-
-function handlePotConnection(conn) {
- var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
- console.log('new client connection from %s', remoteAddress);
-
- conn.on('data', onConnData);
- conn.once('close', onConnClose);
- conn.on('error', onConnError);
-
- function onConnData(d) {
-
- var decoder = new StringDecoder();
-
- // Decode received string
- var str = decoder.write(d);
-
- eventEmitter.emit('newPotential',str);
-
- }
-
- function onConnClose() {
- console.log('connection from %s closed', remoteAddress);
- }
-
- function onConnError(err) {
- console.log('Connection %s error: %s', remoteAddress, err.message);
- }
-}
-
-
-/*
- * System monitor
- */
-
-// Load modules
-
-
-/*
- * Audio stream server
- */
-
-var audioServer = net.createServer();
-audioServer.on('connection', handleAudioConnection);
-
-audioServer.listen(10001, function() {
- console.log('server listening to %j', audioServer.address());
-});
-
-function handleAudioConnection(conn) {
-
- var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
- console.log('new client connection from %s', remoteAddress);
-
- conn.on('data', onConnData);
- conn.once('close', onConnClose);
- conn.on('error', onConnError);
-
- function onConnData(d) {
-
- console.log(`Received audio on ${new Date().getTime()}`);
- eventEmitter.emit('newAudio',d);
- }
-
- function onConnClose() {
- console.log('connection from %s closed', remoteAddress);
- }
-
- function onConnError(err) {
- console.log('Connection %s error: %s', remoteAddress, err.message);
- }
-}
-
-var dummyPorts = [];
-
-for(n = 2; n<=16; n++) {
-
- var dummy = net.createServer();
-
- dummy.on('connection', function(conn) {
- // Dummy
- });
-
- dummy.listen(10000+n);
- console.log(`Dummy listen on ${10000+n}`);
-
- dummyPorts.push(dummy);
-
-}