Version desktop fonctionnelle avec nouvel ODAS
authorCedric Godin <cedric.godin@usherbrooke.ca>
Tue, 16 Jan 2018 16:10:08 +0000 (11:10 -0500)
committerCedric Godin <cedric.godin@usherbrooke.ca>
Tue, 16 Jan 2018 16:10:08 +0000 (11:10 -0500)
main.js [new file with mode: 0644]
package.json
ressources/js/bootstrap_slider.js
ressources/js/interface.js
ressources/js/legal.js [new file with mode: 0644]
ressources/js/source_sphere.js
ressources/js/tcp_link.js
server.js
views/legal.html
views/live_data.html

diff --git a/main.js b/main.js
new file mode 100644 (file)
index 0000000..b21eb98
--- /dev/null
+++ b/main.js
@@ -0,0 +1,164 @@
+const electron = require('electron')
+
+// Module to control application life.
+const app = electron.app
+app.commandLine.appendSwitch('--ignore-gpu-blacklist');
+
+// Module to create native browser window.
+const BrowserWindow = electron.BrowserWindow
+
+const path = require('path')
+const url = require('url')
+
+// 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
+
+function createWindow () {
+  // Create the browser window.
+  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({
+    pathname: path.join(__dirname, 'views/live_data.html'),
+    protocol: 'file:',
+    slashes: true
+  }))
+
+  // Open the DevTools.
+  mainWindow.webContents.openDevTools()
+
+  // Emitted when the window is closed.
+  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
+  })
+}
+
+// This method will be called when Electron has finished
+// initialization and is ready to create browser windows.
+// Some APIs can only be used after this event occurs.
+app.on('ready', createWindow)
+
+// Quit when all windows are closed.
+app.on('window-all-closed', function () {
+  // On OS X it is common for applications and their menu bar
+  // to stay active until the user quits explicitly with Cmd + Q
+  if (process.platform !== 'darwin') {
+    app.quit()
+  }
+})
+
+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) {
+    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
+ */
+
+// 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);
+    }
+
+    catch(err) {
+      console.log('Window was closed');
+    }
+
+  }
+
+  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);
+
+    try {
+      mainWindow.webContents.send('newPotential',str);
+    }
+
+    catch(err) {
+
+      console.log('Window was closed');
+    }
+
+  }
+
+  function onConnClose() {
+    console.log('connection from %s closed', remoteAddress);
+  }
+
+  function onConnError(err) {
+    console.log('Connection %s error: %s', remoteAddress, err.message);
+  }
+}
index f576bd5ae67cb01dc22f58afcf73f74a89f4a590..102b93b5011275caf053ae252d45f441bf0394ab 100644 (file)
@@ -1,10 +1,23 @@
 {
-  "name": "odas-web",
-  "version": "0.2.0",
-  "description": "Web interface for ODAS platform",
-  "repository": "MARS on GitHub/introlab",
-  "license" : "MIT",
-  "dependencies": {
+  "name": "electron-quick-start",
+  "version": "1.0.0",
+  "description": "A minimal Electron application",
+  "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": {
+    "electron": "~1.7.8",
     "express": "^4.15.2",
     "express-ws": "^3.0.0",
     "systeminformation": "^3.17.3"
index 1b242ae2c2f774460b8f4135deb058ade46ae678..76a98ee71c9390d7e74b0b1245cb0f7ea0b415b3 100644 (file)
@@ -1,8 +1,10 @@
 /*! =======================================================
-                      VERSION  9.8.0              
+                      VERSION  9.8.0
 ========================================================= */
 "use strict";
 
+var rangeSlider;
+
 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
 
 /*! =========================================================
@@ -82,7 +84,7 @@ var windowIsDefined = (typeof window === "undefined" ? "undefined" : _typeof(win
        }
 
        // Reference to Slider constructor
-       var Slider;
+       var Slider;
 
        (function ($) {
 
@@ -1898,7 +1900,7 @@ var windowIsDefined = (typeof window === "undefined" ? "undefined" : _typeof(win
                }
        })($);
 
+       rangeSlider = new Slider('#range_slider', {});
+
        return Slider;
 });
-
-var rangeSlider = new Slider('#range_slider', {});
\ No newline at end of file
index 35fe13a5e03cc91da75374b58fb13e3bc70afeb3..5bf9d75dc94201b0411763f856cb38beeace1c58 100644 (file)
@@ -26,18 +26,18 @@ function energyIsInRange(e) {
 
 // Get gradiant index corresponding to energy
 function scaleEnergy(e) {
-    
+
     var min = rangeSlider.getValue()[0];
     var max = rangeSlider.getValue()[1];
-    
+
     // Rescale according to minimal value
-    
+
     e -= min;
     max -= min;
-    
+
     if( e > max)
         e = max;
-    
+
     // Round energy between 0 and 10
     return Math.round((e/max)*10);
 }
@@ -49,12 +49,12 @@ function scaleEnergy(e) {
 // Single source data
 class Source {
     constructor(index) {
-        
+
         // Web UI info
         this.index = index;
         this.rgbValueString = rgbValueStrings[index];
         this.selected = true;
-        
+
         // Source info
         this.id = null;
         this.active = false;
@@ -77,15 +77,15 @@ class PotentialSource {
 // Single data frame
 class DataFrame {
     constructor() {
-        
+
         this.timestamp = null;
         this.ptimestamp = null;
-        
+
         this.sources = [];
         rgbValueStrings.forEach(function (color,i) {
             this.sources.push(new Source(i));
         }.bind(this));
-        
+
         this.potentialSources = [];
     }
 }
@@ -105,7 +105,7 @@ var sourceManager = new Vue({
     methods : {
         showHide: function(e) {
             document.dispatchEvent(new Event('update-selection'));
-        } 
+        }
     }
 });
 
@@ -127,10 +127,42 @@ var filterManager = new Vue({
     }
 });
 
+/*
+ * System Monitor
+ */
+
 // System monitor model
 var systemMonitor = new Vue({
     el: '#system-monitor',
     data: {
         system : {cpu:'0 %',mem:0,temp:0}
     }
-});
\ No newline at end of file
+});
+
+var si = require('systeminformation');
+
+function updateSi() { // Gather params
+
+    var sysInfo = {cpu:0,mem:0,temp:0};
+
+    si.currentLoad(function(data) {
+        sysInfo.cpu = data.currentload;
+
+        si.mem(function(data) {
+            sysInfo.mem = (data.active/data.total)*100;
+
+            si.cpuTemperature(function(data) {
+                sysInfo.temp = data.main;
+
+                systemMonitor.system.cpu = sysInfo.cpu.toPrecision(3).toString() + ' %';
+                systemMonitor.system.mem = sysInfo.mem.toPrecision(2).toString() + ' %';
+                systemMonitor.system.temp = sysInfo.temp.toPrecision(3).toString() + ' °C';
+
+            });
+        });
+    });
+
+}
+
+// Schedule update
+setInterval(updateSi,500);
diff --git a/ressources/js/legal.js b/ressources/js/legal.js
new file mode 100644 (file)
index 0000000..0f1855d
--- /dev/null
@@ -0,0 +1,34 @@
+const electron = require('electron')
+
+const BrowserWindow = electron.remote.BrowserWindow
+
+const path = require('path')
+const url = require('url')
+
+let legalWindow
+
+function openLegalWindow () {
+  // Create the browser window.
+  legalWindow = new BrowserWindow({width: 800, height: 600, show: false})
+
+
+  // and load the index.html of the app.
+  legalWindow.loadURL(url.format({
+    pathname: path.join(__dirname, 'legal.html'),
+    protocol: 'file:',
+    slashes: true
+  }))
+
+  legalWindow.once('ready-to-show', function () {
+
+    legalWindow.show()
+  })
+
+  // Emitted when the window is closed.
+  legalWindow.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.
+    legalWindow = null
+  })
+}
index b3d459d58a4e795b4e44801345070e79e3a4db53..fa5bd05fd0008b9d1210dec4b4bc966a3f048f64 100644 (file)
@@ -17,13 +17,13 @@ animate();
  */
 
 function init() {
-    
+
     // Canvas
     canvas = document.getElementById("sphere");
-    
+
     canvas.style.height = '100%';
     canvas.style.width = '100%';
-    
+
     // Renderer
     renderer = new THREE.WebGLRenderer( { antialias: true, canvas: canvas });
     renderer.setClearColor( 0xffffff );
@@ -39,112 +39,112 @@ function init() {
     controls.rotateSpeed = 5;
     controls.noZoom = true;
     controls.noPan = true;
-    
+
     controls.dynamicDampingFactor = 0.2;
-    
+
     // Scene
     scene = new THREE.Scene();
 
     // Sphere
-    
+
     // Top
-    var sphereGeometry = new THREE.SphereGeometry( 1, 10, 10,0,Math.PI,0,Math.PI); 
+    var sphereGeometry = new THREE.SphereGeometry( 1, 10, 10,0,Math.PI,0,Math.PI);
     var sphereMaterial = new THREE.MeshBasicMaterial({ color:0x0000ff, transparent: true, opacity:0.25});
-    
+
     var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
     //scene.add(sphere);
-    
+
     var sphereMaterial = new THREE.MeshBasicMaterial({ color:0x0000ff, transparent: true, opacity:0.25, wireframe:true});
-    
+
     var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
     scene.add(sphere);
-    
+
     // Bottom
-    var sphereGeometry = new THREE.SphereGeometry( 1, 10, 10,Math.PI,Math.PI,0,Math.PI); 
+    var sphereGeometry = new THREE.SphereGeometry( 1, 10, 10,Math.PI,Math.PI,0,Math.PI);
     var sphereMaterial = new THREE.MeshBasicMaterial({ color:0x8d4f1a, transparent: true, opacity:0.5});
-    
+
     var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
     //scene.add(sphere);
-    
+
     var sphereMaterial = new THREE.MeshBasicMaterial({ color:0x8d4f1a, transparent: true, opacity:0.5, wireframe:true});
-    
+
     var sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
     scene.add(sphere);
-    
+
     // Ground
     var groundGeometry = new THREE.CircleGeometry(1,10);
     var groundMaterial = new THREE.MeshBasicMaterial({ color:0x328327, transparent: true, opacity:0.5});
     groundMaterial.side = THREE.DoubleSide;
-    
+
     var ground = new THREE.Mesh(groundGeometry, groundMaterial);
     scene.add(ground);
-    
+
     // Cube
     var cubeGeometry = new THREE.BoxGeometry(0.5,0.5,0.1);
     var cubeMaterial = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe:false});
-    
+
     var cube = new THREE.Mesh(cubeGeometry,cubeMaterial);
-    
+
     scene.add(cube);
-    
+
     // Sources
     sourceGroup = new THREE.Group();
 
     var sourceGeometry = new THREE.SphereGeometry( 0.08, 10, 10);
-    
+
     rgbValueStrings.forEach(function(color) {
-        
+
         var sourceMaterial = new THREE.MeshBasicMaterial( {color: color, wireframe:false} );
         var source = new THREE.Mesh( sourceGeometry, sourceMaterial );
         source.visible = false;
-        
+
         sources3D.push(source);
         sourceGroup.add(source);
     });
 
     scene.add( sourceGroup );
-    
+
     // Potential sources
     potGroup = new THREE.Group();
     scene.add(potGroup);
-    
+
     /*
      * Draw sub canvas with axis
      */
-    
+
     // Canvas
     subCanvas = document.getElementById("axis");
-    
+
     // Renderer
     subRenderer = new THREE.WebGLRenderer( { antialias: true, canvas: subCanvas });
     subRenderer.setClearColor(0xffffff);
     subRenderer.setSize(80,80);
-    
+
     // Scene
     subScene = new THREE.Scene();
-    
+
     // Camera
     subCamera = new THREE.PerspectiveCamera(90,1,0.1,5);
     subCamera.position.z = 3.5;
     subCamera.up = camera.up;
-    
+
     // Axis
     var axis = new THREE.AxisHelper(1.2);
     scene.add( axis );
 
     var subAxis = new THREE.AxisHelper(1.2);
     subScene.add( subAxis );
-    
+
     // Add axes labels
     var loader = new THREE.FontLoader();
-    loader.load( 'fonts/helvetiker_regular.typeface.json', function ( helFont ) {
-        
+    loader.load( './../ressources/fonts/helvetiker_regular.typeface.json', function ( helFont ) {
+
         var  textGeo = new THREE.TextGeometry('X', {
              size: 0.3,
              height: 0.001,
              curveSegments: 6,
              font: helFont,
-             style: "normal"       
+             style: "normal"
         });
 
         var  textMaterial = new THREE.MeshBasicMaterial({ color: "rgb(255,0,0)" });
@@ -154,13 +154,13 @@ function init() {
         labelX.position.y = 0.01;
         labelX.position.z = 0;
         subScene.add(labelX);
-        
+
         var  textGeo = new THREE.TextGeometry('Y', {
              size: 0.3,
              height: 0.001,
              curveSegments: 6,
              font: helFont,
-             style: "normal"       
+             style: "normal"
         });
 
         var  textMaterial = new THREE.MeshBasicMaterial({ color: "rgb(0,255,0)" });
@@ -170,13 +170,13 @@ function init() {
         labelY.position.y = 1.2;
         labelY.position.z = 0;
         subScene.add(labelY);
-        
+
         var  textGeo = new THREE.TextGeometry('Z', {
              size: 0.3,
              height: 0.001,
              curveSegments: 6,
              font: helFont,
-             style: "normal"       
+             style: "normal"
         });
 
         var  textMaterial = new THREE.MeshBasicMaterial({ color: "rgb(0,0,255)" });
@@ -186,7 +186,7 @@ function init() {
         labelZ.position.y = 0.01;
         labelZ.position.z = 1.2;
         subScene.add(labelZ);
-        
+
     } );
 
     window.addEventListener( 'resize', onWindowResize, false );
@@ -196,11 +196,11 @@ function init() {
  * Resize canvas and renderer when page is resized
  */
 function onWindowResize() {
-    
+
     camera.aspect = canvas.offsetWidth/canvas.offsetHeight ;
     camera.updateProjectionMatrix();
     renderer.setSize(canvas.offsetWidth,canvas.offsetHeight);
-    
+
     canvas.style.height = '100%';
     canvas.style.width = '100%';
 }
@@ -210,12 +210,12 @@ function onWindowResize() {
  */
 
 function animate() {
-    
+
     requestAnimationFrame( animate );
-    
+
     if(controls.enabled)
         controls.update();
-    
+
     try {
         subCamera.rotation.copy(camera.rotation);
         subCamera.position.copy(camera.position);
@@ -224,21 +224,21 @@ function animate() {
         labelY.rotation.copy(camera.rotation);
         labelZ.rotation.copy(camera.rotation);
     }
-    
+
     catch(err) {
         // Scene not loaded
     }
-    
+
     finally {
         render();
     }
 }
 
 function render() {
-    
+
     renderer.render( scene, camera );
     subRenderer.render( subScene, subCamera);
-    
+
 }
 
 /*
@@ -257,15 +257,15 @@ rgbValueStrings.forEach(function(color) {
 
 // Update on new event
 document.addEventListener('tracking', function(e) {
-    
+
     // Clear older trail pixels
     if(sources3DTrail.length > 0) {
-        
+
         sources3DTrail.forEach(function(src,i) {
             src.life--;
-            
+
             if(src.life < 1) {  // Dispose of pixel if life is over
-                
+
                 src.obj.material.dispose();
                 src.obj.geometry.dispose();
                 src.obj.parent.remove(src.obj);
@@ -274,19 +274,19 @@ document.addEventListener('tracking', function(e) {
             }
         })
     }
-    
+
     // Update source on sphere
     currentFrame.sources.forEach(function(source,index) {
-        
+
         sources3D[index].visible = filterManager.showSources && source.active && source.selected && !(source.x == 0 && source.y == 0 && source.z == 0);
-        
+
         sources3D[index].position.x = source.x;
         sources3D[index].position.y = source.y;
         sources3D[index].position.z = source.z;
-        
+
         // Add a pixel to the tail if the source is visible
         if( sources3D[index].visible ) {
-            
+
             var geo = new THREE.Geometry();
             var ps = new THREE.Vector3(source.x,source.y,source.z);
             geo.vertices.push(ps);
@@ -300,10 +300,10 @@ document.addEventListener('tracking', function(e) {
 
 // Update visibility when selection is changed
 document.addEventListener('update-selection',function(e){
-    
+
     currentFrame.sources.forEach(function(source,index) {
         sources3D[index].visible =  filterManager.showSources && source.active && source.selected && !(source.x == 0 && source.y == 0 && source.z == 0);
-    });  
+    });
 });
 
 /*
@@ -322,13 +322,13 @@ heatmapColors.forEach(function(color) {
 
 // Update on 'potential' event
 document.addEventListener('potential', function(e) {
-    
+
     // Remove old trail points
     if(potSources3D.length > 0) {
-        
+
         potSources3D.forEach(function(src,i) {
             src.life--;
-            
+
             if(src.life < 1) {  // Dispose if life is over
                 src.obj.material.dispose();
                 src.obj.geometry.dispose();
@@ -338,23 +338,23 @@ document.addEventListener('potential', function(e) {
             }
         })
     }
-    
+
     // Add potential source to sphere if potential source filter is selected
     if(currentFrame.potentialSources.length > 0 && filterManager.showPotentials) {
-        
+
         currentFrame.potentialSources.forEach(function(s) {
-            
+
                        if ( energyIsInRange(s.e) ) {    // Add source if source's energy's in range
                        var geo = new THREE.Geometry();
                        var ps = new THREE.Vector3(s.x,s.y,s.z);
                        geo.vertices.push(ps);
-                       
+
                        var sys = new THREE.Points(geo,potSourceMaterial[scaleEnergy(s.e)]);
                        potSources3D.push({obj:sys,life:50});
                        potGroup.add(sys);
                        }
         });
-        
+
     }
 });
 
@@ -363,27 +363,27 @@ document.addEventListener('potential', function(e) {
  */
 
 document.addEventListener('clearChart',function(e) {
-    
+
     if(potSources3D.length > 0) {
-        
+
         potSources3D.forEach(function(src,i) {
                 src.obj.material.dispose();
                 src.obj.geometry.dispose();
                 src.obj.parent.remove(src.obj);
         });
     }
-    
+
     potSources3D = [];
-    
+
     if(sources3DTrail.length > 0) {
-        
+
         sources3DTrail.forEach(function(src,i) {
                 src.obj.material.dispose();
                 src.obj.geometry.dispose();
                 src.obj.parent.remove(src.obj);
         });
     }
-    
+
     sources3DTrail = [];
 });
 
@@ -393,12 +393,12 @@ document.addEventListener('clearChart',function(e) {
  */
 
 var viewFront = function() {
-    
+
     camera.up.set(0,0,1);
-    
+
     camera.position.x = 0;
     camera.position.y = -camOffset;
     camera.position.z = 0;
-    
+
     controls.reset();
 };
index b312f5c572447998f5b06f2b1e84ff43777d3985..c280b708d2a4e11208173999f6eab5b373e92c71 100644 (file)
@@ -2,46 +2,29 @@
  * Web Socket connection to server
  */
 
-// Generate websocket server URL
-var loc = window.location, new_uri, sys_uri, pot_uri;
-
-if (loc.protocol === "https:") {
-    new_uri = "wss:";
-} else {
-    new_uri = "ws:";
-}
-
-audio_uri = new_uri + "//" + loc.host + "/audio";
-sys_uri = new_uri + "//" + loc.host + "/system.info";
-pot_uri = new_uri + "//" + loc.host + "/potential";
-new_uri += "//" + loc.host + "/tracking";
+ const ipcRenderer = require('electron').ipcRenderer
 
 /*
  * Tracking data socket
  */
 
-// Open socket and create parser
-var socket = new WebSocket(new_uri);
-console.log(new_uri);
-
 // Update current data with received data
 var indexMap = {};
 
-socket.onmessage = function(msg) {
-        
-    try { 
-        var strData = msg.data;
-        var data = JSON.parse(strData);
+const processTracking = function(event, msg) {
+
+    try {
+        var data = JSON.parse(msg);
     }
 
     catch(err) {
 
         // Can't parse frame
         console.error(err);
-        console.log(strData);
+        console.log(msg);
         return;
     }
-    
+
     if(Math.abs(data.timeStamp -  currentFrame.timestamp) > 1)
         console.warn('Frame skipped ' + data.timeStamp.toString());
 
@@ -53,21 +36,21 @@ socket.onmessage = function(msg) {
         indexPool.push(index);
     });
     var hasNewSource = false;
-    
+
     data.src = data.src.filter(function(s) {
         return s.id !== 0;
     });
-    
+
     if(data.src) {    // If frame contains sources
 
         data.src.forEach(function(src) {  // Remove still used index from the pool
-            
+
             if(typeof(indexMap[src.id])!='undefined') {  // If source is not new
                 indexPool.splice(indexPool.indexOf(indexMap[src.id]),1);
                 //console.log(indexPool);
             }
         });
-        
+
         data.src.forEach(function(src) { // Update sources
 
              if(typeof(indexMap[src.id])!='undefined') {  // Source is already registered
@@ -91,75 +74,73 @@ socket.onmessage = function(msg) {
             currentFrame.sources[newMap[src.id]].active = !(src.x==0 && src.y==0 && src.z==0);
 
         });
-        
+
     }
-    
+
     indexMap = newMap;
-    
+
     indexPool.forEach(function(index) { // Clear unused source slot
-        
+
         currentFrame.sources[index].id = null;
-        
+
         currentFrame.sources[index].x = null;
         currentFrame.sources[index].y = null;
         currentFrame.sources[index].z = null;
-        
+
         currentFrame.sources[index].active = false;
         currentFrame.sources[index].selected = true;
     });
 
     // Trigger update
     document.dispatchEvent(new Event('tracking'));
-    
+
     if(hasNewSource)
         document.dispatchEvent(new Event('update-selection'));
 };
 
+ipcRenderer.on('newTracking', processTracking)
+
 /*
  * Potential sources socket
  */
 
-var potentialSocket = new WebSocket(pot_uri);
-console.log(pot_uri);
-
 
 // Update current data with received potential sources
-potentialSocket.onmessage = function(msg) {
-        
-    try { 
-        var strData = msg.data;
-        var data = JSON.parse(strData);
+const processPotential = function(event, msg) {
+
+    try {
+        var data = JSON.parse(msg);
     }
 
     catch(err) {
 
         // Can't parse frame
         console.error(err);
-        console.log(strData);
+        console.log(msg);
         return;
     }
-    
+
     if(Math.abs(data.timeStamp -  currentFrame.ptimestamp) > 1)
         console.warn('Frame skipped ' + data.timeStamp.toString());
 
     currentFrame.ptimestamp = data.timeStamp;
     currentFrame.potentialSources = [];
-    
+
     if(data.src) {    // If frame contains sources
-        
+
         data.src.forEach(function(source) {
-            
+
             var newSource = new PotentialSource();
-            
+
             newSource.e = source.E;
             newSource.x = source.x;
             newSource.y = source.y;
             newSource.z = source.z;
-            
+
             currentFrame.potentialSources.push(newSource);
-            
+
         });
-        
+
     }
 
     // Trigger update
@@ -167,76 +148,62 @@ potentialSocket.onmessage = function(msg) {
 
 };
 
+ipcRenderer.on('newPotential', processPotential)
+
 /*
  * Frame reset when no data is received
  */
 
 document.addEventListener('clearChart', function(e){
-    
+
     currentFrame.timestamp = 0;
     currentFrame.ptimestamp = 0;
-    
+
     currentFrame.sources.forEach(function(source){
         source.id = null;
-        
+
         source.x = null;
         source.y = null;
         source.z = null;
-        
+
         source.active = false;
         source.selected = true;
     });
-    
+
     currentFrame.potentialSources = [];
-    
+
     document.dispatchEvent(new Event('tracking'));
     document.dispatchEvent(new Event('potential'));
     document.dispatchEvent(new Event('update-selection'));
-    
+
     sourceManager.showPotentials = true;
     document.dispatchEvent(new Event('potential-visibility'));
-    
+
     viewFront();
-    
+
     var req = setInterval(function() {
-        
+
         document.dispatchEvent(new Event('request-chart'));
-        
+
         hasPotential = false;
         clearInterval(req);
         console.log('UI cleaned');
-        
+
     },500);
 });
 
-/*
- * System info socket
- */
-
-var systemSocket = new WebSocket(sys_uri);
-
-systemSocket.onmessage = function(msg) {
-    
-    var data = JSON.parse(msg.data);
-    
-    systemMonitor.system.cpu = data.cpu.toPrecision(3).toString() + ' %';
-    systemMonitor.system.mem = data.mem.toPrecision(2).toString() + ' %';
-    systemMonitor.system.temp = data.temp.toPrecision(3).toString() + ' °C';
-};
-
 /*
  * Audio socket
  */
 
-var audioSocket = new WebSocket(audio_uri);
 
-audioSocket.onmessage = function(msg) {
-    
+const processAudio = function(msg) {
+
      var reader = new FileReader();
-    
+
     reader.onloadend = function() {
         document.dispatchEvent(new CustomEvent('audioData', { 'detail': reader.result}));
     };
 
-    reader.readAsArrayBuffer(msg.data);  
-};
\ No newline at end of file
+    reader.readAsArrayBuffer(msg.data);
+};
index dff563cf26de1c7c59b6cee6d7f6fe084f77d4f0..e2f5d4980376249c1134717fba11e11aba64bfe6 100644 (file)
--- a/server.js
+++ b/server.js
@@ -34,23 +34,23 @@ app.get('/legal', function(req, res) {
 
 // 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);
@@ -60,23 +60,23 @@ app.ws('/tracking',function(ws, req) {
 
 // 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);
@@ -86,23 +86,23 @@ app.ws('/potential',function(ws, req) {
 
 // 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);
@@ -112,24 +112,24 @@ app.ws('/system.info',function(ws, req) {
 
 // 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);
@@ -154,14 +154,14 @@ console.log('Listening...');
 // Load modules
 var net = require('net');
 
-var server = net.createServer();  
+var server = net.createServer();
 server.on('connection', handleConnection);
 
-server.listen(9000, function() {  
+server.listen(9000, function() {
   console.log('server listening to %j', server.address());
 });
 
-function handleConnection(conn) {  
+function handleConnection(conn) {
   var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
   console.log('new client connection from %s', remoteAddress);
 
@@ -170,12 +170,12 @@ function handleConnection(conn) {
   conn.on('error', onConnError);
 
   function onConnData(d) {
-      
+
     var decoder = new StringDecoder();
-    
+
     // Decode received string
     var str = decoder.write(d);
-            
+
     eventEmitter.emit('newTracking',str);
 
   }
@@ -194,14 +194,14 @@ function handleConnection(conn) {
  * Create TCP server for potential sources
  */
 
-var potentialServer = net.createServer();  
+var potentialServer = net.createServer();
 potentialServer.on('connection', handlePotConnection);
 
-potentialServer.listen(9001, function() {  
+potentialServer.listen(9001, function() {
   console.log('server listening to %j', potentialServer.address());
 });
 
-function handlePotConnection(conn) {  
+function handlePotConnection(conn) {
   var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
   console.log('new client connection from %s', remoteAddress);
 
@@ -210,12 +210,12 @@ function handlePotConnection(conn) {
   conn.on('error', onConnError);
 
   function onConnData(d) {
-      
+
     var decoder = new StringDecoder();
-    
+
     // Decode received string
     var str = decoder.write(d);
-            
+
     eventEmitter.emit('newPotential',str);
 
   }
@@ -235,43 +235,21 @@ function handlePotConnection(conn) {
  */
 
 // Load modules
-var si = require('systeminformation');
-
-function updateSi() { // Gather params
-    
-    var sysInfo = {cpu:0,mem:0,temp:0};
-    
-    si.currentLoad(function(data) { 
-        sysInfo.cpu = data.currentload;
-        
-        si.mem(function(data) {
-            sysInfo.mem = (data.active/data.total)*100;
-            
-            si.cpuTemperature(function(data) {   
-                sysInfo.temp = data.main;
-                eventEmitter.emit('sysInfo',sysInfo);
-            });
-        });
-    });
-    
-}
 
-// Schedule update
-setInterval(updateSi,500);
 
 /*
  * Audio stream server
  */
 
-var audioServer = net.createServer();  
+var audioServer = net.createServer();
 audioServer.on('connection', handleAudioConnection);
 
-audioServer.listen(10001, function() {  
+audioServer.listen(10001, function() {
   console.log('server listening to %j', audioServer.address());
 });
 
-function handleAudioConnection(conn) {  
-    
+function handleAudioConnection(conn) {
+
   var remoteAddress = conn.remoteAddress + ':' + conn.remotePort;
   console.log('new client connection from %s', remoteAddress);
 
@@ -280,8 +258,8 @@ function handleAudioConnection(conn) {
   conn.on('error', onConnError);
 
   function onConnData(d) {
-      
-   console.log(`Received audio on ${new Date().getTime()}`); 
+
+   console.log(`Received audio on ${new Date().getTime()}`);
        eventEmitter.emit('newAudio',d);
   }
 
@@ -297,16 +275,16 @@ function handleAudioConnection(conn) {
 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);
-    
+
 }
index 29f2803d08949a1c4294fd9aad56e5f23ebf5847..561dd1dc03faca5dc279d3abb732902c3b47cf16 100644 (file)
@@ -5,30 +5,16 @@
         <meta http-equiv="X-UA-Compatible" content="IE=edge">
         <meta name="viewport" content="width=device-width, initial-scale=1">
         <title>Legal</title>
-        <link href="css/bootstrap.css" rel="stylesheet">
-        <link href="css/style.css" rel="stylesheet">
+        <link href="../ressources/css/bootstrap.css" rel="stylesheet">
+        <link href="../ressources/css/style.css" rel="stylesheet">
     </head>
     <body>
         <nav class="navbar navbar-default bg-primary navbar-fixed-top ">
-                <div class="container-fluid"> 
-
+                <div class="container-fluid">
                     <div class="navbar-header">
-                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-content" aria-expanded="false">
-                            <span class="icon-bar"></span>
-                            <span class="icon-bar"></span>
-                            <span class="icon-bar"></span>
-                        </button>
-                        <a class="navbar-brand navbar-logo" width="120" href="https://github.com/introlab/odas"><img src="images/introlab_icon.png"></a>
+                        <a class="navbar-brand navbar-logo" width="120" href="https://github.com/introlab/odas"><img src="../ressources/images/introlab_icon.png"></a>
                         <a class="navbar-brand" width="120" href="https://github.com/introlab/odas"><span>ODAS</span></a>
                     </div>
-
-                <div class="collapse navbar-collapse" id="navbar-content">
-                    <ul class="nav navbar-nav navbar-right">
-                        <li><a href='/'>Live Data</a></li>
-                        <li><a href="/config">Configure</a></li>
-                    </ul>
-                </div>
-
                 </div>
             </nav>
 
@@ -39,7 +25,7 @@
                     <p>
                         The MIT License (MIT)<br>
                         <br>
-                        Copyright 2017 IntRoLab<br>
+                        Copyright <script>document.write(new Date().getFullYear())</script> IntRoLab<br>
                         <br>
                         Permission is hereby granted, free of charge, to any person obtaining a copy
                         of this software and associated documentation files (the "Software"), to deal
                 </div>
             </div>
         </div>
-        
+
         <footer class="footer">
             <div class="container-fluid">
                 <div class="row">
                     <p class="col-xs-10 text-muted">ODAS platform web interface</p>
-                    <a href="/legal" class="col-xs-2 text-right">Legal</a>
+                    <a href="javascript:window.close()" class="col-xs-2 text-right">Close</a>
                 </div>
             </div>
         </footer>
-
-        <script src="js/jquery.min.js"></script>
-        <script src="js/bootstrap.min.js"></script>
     </body>
-</html>
\ No newline at end of file
+</html>
index db69ed754a0189d8ff6ef760a71b9e40a2465d2e..10bc3a308fbaffc184086e8e8f46a6a433f48a4c 100644 (file)
@@ -4,18 +4,18 @@
         <meta charset="utf-8">
         <meta http-equiv="X-UA-Compatible" content="IE=edge">
         <meta name="viewport" content="width=device-width, initial-scale=1">
-        
+
         <title>Live Data</title>
-        <link rel="icon" href="images/introlab_icon.png">
-        
-        <link href="css/bootstrap.css" rel="stylesheet">
-        <link href="css/style.css" rel="stylesheet">
-        <link href="css/bootstrap_slider.css" rel="stylesheet">
+        <link rel="icon" href="./../ressources/images/introlab_icon.png">
+
+        <link href="./../ressources/css/bootstrap.css" rel="stylesheet">
+        <link href="./../ressources/css/style.css" rel="stylesheet">
+        <link href="./../ressources/css/bootstrap_slider.css" rel="stylesheet">
     </head>
     <body>
         <div class="wrapper">
             <nav class="navbar navbar-default bg-primary navbar-fixed-top ">
-                <div class="container-fluid"> 
+                <div class="container-fluid">
 
                     <div class="navbar-header">
                         <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-content" aria-expanded="false">
                         <button type="button" class="navbar-toggle collapsed navbar-button" data-toggle="collapse" data-target="#source-list" aria-expanded="false">
                             Sources
                         </button>
-                        <a class="navbar-brand navbar-logo" width="120" href="https://github.com/introlab/odas"><img src="images/introlab_icon.png"></a>
+                        <a class="navbar-brand navbar-logo" width="120" href="https://github.com/introlab/odas"><img src="./../ressources/images/introlab_icon.png"></a>
                         <a class="navbar-brand" width="120" href="https://github.com/introlab/odas"><span>ODAS</span></a>
                     </div>
 
                 <div class="collapse navbar-collapse" id="navbar-content">
                     <ul class="nav navbar-nav navbar-right">
-                        <li><a href='/'>Live Data</a></li>
-                        <li><a href="/config">Configure</a></li>
+                        <li><a href='#'>Live Data</a></li>
+                        <li><a href="#">Configure</a></li>
                     </ul>
                 </div>
 
@@ -42,7 +42,7 @@
 
             <div class="container-fluid content main">
                 <div class="row content">
-                    <div class="col-md-3 col-lg-2 layout darker">
+                    <div class="col-md-3 layout darker">
                         <h2>ODAS Data</h2>
                         <div class="well" id="system-monitor">
                             <form>
@@ -67,7 +67,7 @@
                             </form>
                         </div>
                     </div>
-                    <div class="col-md-7 col-lg-8 layout">
+                    <div class="col-md-7 layout">
                         <div class="row graph-row">
                             <div class="col-xs-12 content">
                                 <h4 class="abs_head">Source Elevation</h4>
@@ -90,7 +90,7 @@
                     </div>
                     <div class="col-md-2 layout darker">
                         <div class="collapse navbar-collapse" id="source-list">
-                            
+
                             <h2>Sources</h2>
                             <table class="table table-hover" id="source_table">
                                 <tr v-for = "source in sources">
                                     </td>
                                 </tr>
                             </table>
-                            
+
                             <h2>Filters</h2>
                             <table class="table table-hover" id="filter_table">
                                 <tr>
                             <p>Potential sources energy range:</p>
                             <b id="left-marker">0</b>
                             <input id="range_slider" type="text" class="span2" value="" data-slider-min="0" data-slider-max="1" data-slider-step="0.05" data-slider-value="[0,1]"/>
-                            <b id="right-marker">1</b> 
+                            <b id="right-marker">1</b>
                         </div>
                     </div>
                 </div>
                 <div class="container-fluid">
                     <div class="row">
                         <p class="col-xs-10 text-muted">ODAS platform web interface</p>
-                        <a href="/legal" class="col-xs-2 text-right">Legal</a>
+                        <a href="#" class="col-xs-2 text-right" onclick="openLegalWindow()">Legal</a>
                     </div>
                 </div>
             </footer>
         </div>
 
-        <script src="js/jquery.min.js"></script>
-        <script src="js/bootstrap.min.js"></script>
-        
-        <script src="js/vue.js"></script>
-        <script src="js/bootstrap_slider.js"></script>
-        <script src="js/interface.js"></script>
-        
-        
-        <script src="js/tcp_link.js"></script>
-        
-        <script src="js/three.min.js"></script>
-        <script src="js/stats.min.js"></script>
-        <script src="js/TrackballControls.js"></script>
-        
-        <script src="js/Chart.bundle.min.js"></script>
-        <script src="js/graph.js"></script>
-        
-        <script src="js/source_sphere.js"></script>
-        
-        <script src="js/audio_stream.js"></script>
+        <script>window.$ = window.jQuery = require('./../ressources/js/jquery.min.js');</script>
+        <script src="./../ressources/js/bootstrap.min.js"></script>
+
+        <script src="./../ressources/js/vue.js"></script>
+        <script src="./../ressources/js/bootstrap_slider.js"></script>
+        <script src="./../ressources/js/interface.js"></script>
+
+        <script src="./../ressources/js/tcp_link.js"></script>
+
+        <script src="./../ressources/js/three.min.js"></script>
+        <script src="./../ressources/js/stats.min.js"></script>
+        <script src="./../ressources/js/TrackballControls.js"></script>
+
+        <script src="./../ressources/js/Chart.bundle.min.js"></script>
+        <script src="./../ressources/js/graph.js"></script>
+
+        <script src="./../ressources/js/source_sphere.js"></script>
+
+        <script src="./../ressources/js/audio_stream.js"></script>
+
+        <script src="./../ressources/js/legal.js"></script>
     </body>
 </html>