diff --git a/js/electron.js b/js/electron.js index b3a857a4..0e1f1532 100755 --- a/js/electron.js +++ b/js/electron.js @@ -7,6 +7,7 @@ const Server = require(__dirname + '/server.js'); const spawn = require('child_process').spawn; const electron = require('electron'); const defaultModules = require(__dirname + '/../modules/default/defaultmodules.js'); +const path = require('path'); // Config var config = {}; @@ -80,6 +81,7 @@ function loadModule(module) { var Module = require(helperPath); var m = new Module(); m.setName(moduleName); + m.setPath(path.resolve(moduleFolder)); nodeHelpers.push(m); } } @@ -108,11 +110,12 @@ loadConfig(function(c) { loadModules(modules); - var server = new Server(config, function(io) { + var server = new Server(config, function(app, io) { console.log('Server started ...'); for (var h in nodeHelpers) { var nodeHelper = nodeHelpers[h]; + nodeHelper.setExpressApp(app); nodeHelper.setSocketIO(io); nodeHelper.start(); } diff --git a/js/server.js b/js/server.js index aac4d839..bdf9738a 100644 --- a/js/server.js +++ b/js/server.js @@ -27,7 +27,7 @@ var Server = function(config, callback) { }); if (typeof callback === 'function') { - callback(io); + callback(app, io); } }; diff --git a/modules/node_modules/node_helper/index.js b/modules/node_modules/node_helper/index.js index 4bc7130e..a94d00ec 100644 --- a/modules/node_modules/node_helper/index.js +++ b/modules/node_modules/node_helper/index.js @@ -6,6 +6,8 @@ */ var Class = require('../../../js/class.js'); +var express = require('express'); +var path = require('path'); NodeHelper = Class.extend({ init: function() { @@ -26,7 +28,7 @@ NodeHelper = Class.extend({ console.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload); }, - /* setName(data) + /* setName(name) * Set the module name. * * argument name string - Module name. @@ -35,6 +37,15 @@ NodeHelper = Class.extend({ this.name = name; }, + /* setPath(path) + * Set the module path. + * + * argument name string - Module name. + */ + setPath: function(path) { + this.path = path; + }, + /* sendSocketNotification(notification, payload) * Send a socket notification to the node helper. * @@ -45,6 +56,20 @@ NodeHelper = Class.extend({ this.io.of(this.name).emit(notification, payload); }, + + /* setExpressApp(app) + * Sets the express app object for this module. + * This allows you to host files from the created webserver. + * + * argument app Express app - The Express app object. + */ + setExpressApp: function(app) { + this.expressApp = app; + + var publicPath = this.path + '/public'; + app.use('/' + this.name, express.static(publicPath)); + }, + /* setSocketIO(io) * Sets the socket io object for this module. * Binds message receiver.