// Module to control application life.
const app = electron.app
-app.commandLine.appendSwitch('--ignore-gpu-blacklist');
+app.commandLine.appendSwitch('--ignore-gpu-blacklist'); // Allows Web GL on Ubuntu
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
-let mainWindow
+let odasStudio = {}
function createWindow () {
// Create the browser window.
- mainWindow = new BrowserWindow({width: 1200, height: 800,
+ odasStudio.mainWindow = new BrowserWindow({width: 1200, height: 800,
'web-preferences': {
'web-security': false,
"webgl": true
// and load the index.html of the app.
- mainWindow.loadURL(url.format({
+ odasStudio.mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'views/live_data.html'),
protocol: 'file:',
slashes: true
//mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
- mainWindow.on('closed', function () {
+ odasStudio.mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
- mainWindow = null
+ odasStudio.mainWindow = null
})
}
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
- if (mainWindow === null) {
+ if (odasStudio.mainWindow === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
-/*
- * Create TCP server for source tracking
- */
+const sockets = require('./servers.js')
+odasStudio.odas = require('./odas.js')
-// Load modules
-const StringDecoder = require('string_decoder').StringDecoder;
-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);
-
- try {
- mainWindow.webContents.send('newTracking',str);
- if(typeof odas_process == 'undefined') {
- mainWindow.webContents.send('remote-online');
- }
- }
-
- catch(err) {
- console.log('Window was closed');
- }
-
- }
-
- 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);
- }
-}
-
-
-/*
- * 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);
-
- try {
- mainWindow.webContents.send('newPotential',str);
- if(typeof odas_process == 'undefined') {
- mainWindow.webContents.send('remote-online', conn.remoteAddress);
- }
- }
-
- catch(err) {
-
- console.log('Window was closed');
- }
-
- }
-
- 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')
-})
+sockets.startTrackingServer(odasStudio)
+sockets.startPotentialServer(odasStudio)
--- /dev/null
+/*
+ * ODAS Control
+ */
+
+exports.odas_process
+
+const electron = require('electron')
+const ipcMain = electron.ipcMain
+const child_process = require('child_process')
+
+ipcMain.on('launch-odas', function(event, core, config) {
+
+ console.log('received launch command')
+ console.log(core)
+ console.log(config)
+
+ exports.odas_process = child_process.spawn(core, ['-c', config])
+
+ event.sender.send('launched-odas', true)
+})
+
+
+ipcMain.on('stop-odas', function(event) {
+
+ exports.odas_process.kill('SIGINT')
+ exports.odas_process = undefined
+
+ console.log('received stop command')
+})
+++ /dev/null
-# Input
-
-input:
-{
-
-# raw: { type = "file"; path = "in.raw"; format = "bin16"; }
- raw: { type = "soundcard"; card = 1; device = 0; format = "bin16"; }
-
-};
-
-# Output:
-
-output:
-{
- raw:
- (
-# { type = "file"; path = "recorded_raw_16.raw"; format = "bin16"; }
-# { type = "file"; path = "recorded_raw_32.raw"; format = "bin32"; },
-# { type = "file"; path = "recorded_raw_24.raw"; format = "bin24"; }
- );
-
- mapping:
- (
-# { type = "file"; path = "recorded_mapping_16.raw"; format = "bin16"; }
-# { type = "file"; path = "recorded_mapping_32.raw"; format = "bin32"; }
- );
-
- resample:
- (
-# { type = "file"; path = "recorded_resample_16.raw"; format = "bin16"; }
-# { type = "file"; path = "recorded_resample_32.raw"; format = "bin32"; }
- );
-
- stft:
- (
-# { type = "file"; path = "recorded_stft.bin"; format = "float"; }
- );
-
- ssl:
- (
- { type = "socket"; ip = "127.0.0.1"; port = 9001; format = "json"; }
- );
-
- sst:
- (
- { type = "socket"; ip = "127.0.0.1"; port = 9000; format = "json"; }
- );
-
- sss:
- (
-# { type = "file"; path = "separated_stft.bin"; format = "float"; }
- );
-
- sspf:
- (
-# { type = "file"; path = "postfiltered_stft.bin"; format = "float"; }
- );
-
-}
{
- "name": "electron-quick-start",
+ "name": "ODAS_Desktop",
"version": "1.0.0",
- "description": "A minimal Electron application",
+ "description": "A desktop GUI for the ODAS library",
"main": "main.js",
"scripts": {
"start": "electron ."
},
- "repository": "https://github.com/electron/electron-quick-start",
- "keywords": [
- "Electron",
- "quick",
- "start",
- "tutorial",
- "demo"
- ],
- "author": "GitHub",
- "license": "CC0-1.0",
- "devDependencies": {
+ "author": "Cedric Godin",
+ "license": "GPL-3.0",
+ "dependencies": {
"electron": "~1.7.8",
- "express": "^4.15.2",
- "express-ws": "^3.0.0",
"ip": "^1.1.5",
- "systeminformation": "^3.17.3"
+ "speaker": "^0.4.0",
+ "systeminformation": "^3.17.3",
+ "wav": "^1.0.1"
+ },
+ "repository" :
+ { "type" : "git"
+ , "url" : "https://github.com/introlab/odas_web.git"
}
}
var watchdog = null;
+/*
+ * Audio socket
+ */
+
+
+const processAudio = function(msg) {
+
+ var reader = new FileReader();
+
+ reader.onloadend = function() {
+ document.dispatchEvent(new CustomEvent('audioData', { 'detail': reader.result}));
+ };
+
+ reader.readAsArrayBuffer(msg.data);
+};
+
document.addEventListener('audioData',function(ev) {
-
+
var data = new Int16Array(ev.detail);
var dataNormalized = new Float32Array(data.length);
-
+
for(var i=0; i<data.length; i++) {
dataNormalized[i] = (data[i]/32768.0);
}
-
+
if(!streamStarted)
startTime = audioCtx.currentTime + startBuffer;
-
+
streamStarted = true;
scheduleBuffer(dataNormalized);
-
+
clearInterval(watchdog);
watchdog = setInterval(function(){
-
+
streamStarted = false;
console.log('Watchdog');
clearInterval(watchdog);
-
+
}, 10000);
});
function scheduleBuffer(audio) {
-
+
var buffer = audioCtx.createBuffer(channels, audio.length, sampleRate);
buffer.copyToChannel(audio,0,0);
-
+
var source = audioCtx.createBufferSource();
source.buffer = buffer;
-
+
var gain = audioCtx.createGain();
gain.gain.value = 15;
-
+
source.connect(gain);
gain.connect(audioCtx.destination);
-
+
source.start(startTime);
-
+
console.log(`Scheduled in ${startTime-audioCtx.currentTime}`);
-
+
startTime += buffer.duration;
}
--- /dev/null
+/*
+ * 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'
},500);
});
-
-/*
- * Audio socket
- */
-
-
-const processAudio = function(msg) {
-
- var reader = new FileReader();
-
- reader.onloadend = function() {
- document.dispatchEvent(new CustomEvent('audioData', { 'detail': reader.result}));
- };
-
- 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
+// Load modules
+const StringDecoder = require('string_decoder').StringDecoder;
+var net = require('net');
+
+let trackingServer
+let potentialServer
+
+/*
+ * Create TCP server for source tracking
+ */
+
+ exports.startTrackingServer = (odasStudio) => {
+
+ trackingServer = net.createServer();
+ trackingServer.on('connection', handleConnection);
+
+ trackingServer.listen(9000, function() {
+ console.log('server listening to %j', trackingServer.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);
+
+ try {
+ odasStudio.mainWindow.webContents.send('newTracking',str);
+ if(typeof odasStudio.odas.odas_process == 'undefined') {
+ odasStudio.mainWindow.webContents.send('remote-online');
+ }
+ }
+
+ catch(err) {
+ console.log('Window was closed');
+ }
+
+ }
+
+ function onConnClose() {
+ console.log('connection from %s closed', remoteAddress);
+ odasStudio.mainWindow.webContents.send('remote-offline');
+ }
+
+ function onConnError(err) {
+ console.log('Connection %s error: %s', remoteAddress, err.message);
+ }
+ }
+
+ }
+
+
+/*
+ * Create TCP server for potential sources
+ */
+
+ exports.startPotentialServer = (odasStudio) => {
+
+ 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);
+
+ try {
+ odasStudio.mainWindow.webContents.send('newPotential',str);
+ if(typeof odasStudio.odas.odas_process == 'undefined') {
+ odasStudio.mainWindow.webContents.send('remote-online', conn.remoteAddress);
+ }
+ }
+
+ catch(err) {
+
+ console.log('Window was closed');
+ }
+
+ }
+
+ function onConnClose() {
+ console.log('connection from %s closed', remoteAddress);
+ odasStudio.mainWindow.webContents.send('remote-offline');
+ }
+
+ function onConnError(err) {
+ console.log('Connection %s error: %s', remoteAddress, err.message);
+ }
+ }
+ }
<script src="./../ressources/js/source_sphere.js"></script>
<script src="./../ressources/js/audio_stream.js"></script>
+ <script src="./../ressources/js/odas_launcher.js"></script>
<script src="./../ressources/js/legal.js"></script>
</body>