diff --git a/.gitignore b/.gitignore index 8fee70e2..fbe259c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,13 @@ /node_modules !/modules/node_helper -!/modules/node_helper/** \ No newline at end of file +!/modules/node_helper/** + +/modules/* +!/modules/calendar +!/modules/clock +!/modules/compliments +!/modules/currentweather +!/modules/helloworld +!/modules/newsfeed +!/modules/weatherforecast diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..399a003f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 - Michael Teeuw + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 916241ec..e72ca3e5 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,27 @@ This version of the Magic Mirror software focusses on a modular plugin system. B ##Todo Things that still have to be implemented or changed. + ####Loader - Loading of module uses `eval()`. We might want to look into a better solution. [loader.js#L112](https://github.com/MichMich/MagicMirror/blob/v2-beta/js/loader.js#L112). -##Modules -###[MMM-FRITZ-Box-Callmonitor by PaViRo](https://github.com/paviro/MMM-FRITZ-Box-Callmonitor) +##Modules + +### Default modules +##### Clock +##### Current Weather +##### Weather Forecast +##### News Feed +##### Compliments +##### Hello World + +### 3rd Party Modules + +#####[MMM-FRITZ-Box-Callmonitor by PaViRo](https://github.com/paviro/MMM-FRITZ-Box-Callmonitor) **Features:** FRITZ!Box Callmonitor (displays alert when someone is calling) -####NodeHelper -- The node_helper superclass creates a seperate socket connection for each module. It's preferred to use the overall socket connection of the server. + diff --git a/js/electron.js b/js/electron.js index c83164a4..a736ea50 100755 --- a/js/electron.js +++ b/js/electron.js @@ -15,6 +15,8 @@ const app = electron.app; // Module to create native browser window. const BrowserWindow = electron.BrowserWindow; +var nodeHelpers = []; + // 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; @@ -68,7 +70,7 @@ function loadModule(moduleName) { var Module = require(helperPath); var m = new Module(); m.setName(moduleName); - m.start(); + nodeHelpers.push(m); } } @@ -95,16 +97,26 @@ loadConfig(function(c) { } loadModules(modules); + + var server = new Server(config, function(io) { + console.log('Server started ...'); + + for (var h in nodeHelpers) { + var nodeHelper = nodeHelpers[h]; + nodeHelper.setSocketIO(io); + nodeHelper.start(); + } + + console.log('Sockets connected & modules started ...'); + + }); }); // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.on('ready', function() { - var server = new Server(config, function() { - setTimeout(function() { - createWindow(); - }, 1000); - }); + console.log('Launching application.'); + createWindow(); }); // Quit when all windows are closed. diff --git a/js/server.js b/js/server.js index 32670a46..4440e1aa 100644 --- a/js/server.js +++ b/js/server.js @@ -12,53 +12,6 @@ var io = require('socket.io')(server); var path = require('path'); var Server = function(config, callback) { - - /* createNamespace(namespace) - * Creates a namespace with a wildcard event. - * - * argument namespace string - The name of the namespace. - */ - var createNamespace = function(namespace) { - console.log('Creating socket namespace: ' + namespace); - - io.of(namespace).on('connection', function (socket) { - console.log("New socket connection on namespace: " + namespace); - - // add a catch all event. - var onevent = socket.onevent; - socket.onevent = function (packet) { - var args = packet.data || []; - onevent.call (this, packet); // original call - packet.data = ["*"].concat(args); - onevent.call(this, packet); // additional call to catch-all - }; - - // register catch all. - socket.on('*', function (event, data) { - io.of(namespace).emit(event, data); - }); - }); - }; - - /* createNamespaces() - * Creates a namespace for all modules in the config. - */ - var createNamespaces = function() { - var modules = []; - var m; - - for (m in config.modules) { - var module = config.modules[m]; - if (modules.indexOf(module.module) === -1) { - modules.push(module.module); - } - } - - for (m in modules) { - createNamespace(modules[m]); - } - }; - console.log("Starting server op port " + config.port + " ... "); server.listen(config.port); @@ -73,10 +26,8 @@ var Server = function(config, callback) { res.sendFile(path.resolve(__dirname + '/../index.html')); }); - createNamespaces(); - if (typeof callback === 'function') { - callback(); + callback(io); } }; diff --git a/js/socketclient.js b/js/socketclient.js index a3cb57bd..32142e94 100644 --- a/js/socketclient.js +++ b/js/socketclient.js @@ -1,29 +1,4 @@ -if (typeof window === 'undefined') { - // Only perfom this part if is isn't running in the browser. - - // Load socket client - var io = require('socket.io-client'); - - // Load config - var fs = require('fs'); - - var config = {}; - - var defaults = require(__dirname + '/defaults.js'); - var configFilename = __dirname + '/../config/config.js'; - - try { - fs.accessSync(configFilename, fs.R_OK); - var c = require(configFilename); - config = Object.assign(defaults, c); - } catch (e) { - config = defaults; - } -} - - var MMSocket = function(moduleName) { - var self = this; if (typeof moduleName !== 'string') { @@ -33,37 +8,25 @@ var MMSocket = function(moduleName) { self.moduleName = moduleName; // Private Methods - var socketBase = (typeof window === 'undefined') ? 'http://localhost:'+config.port : ''; - socket = io(socketBase + '/' + self.moduleName); - + socket = io.connect('/' + self.moduleName); var notificationCallback = function() {}; - socket.on('connect', function(s) { - - // add a catch all event. - var onevent = socket.onevent; - socket.onevent = function (packet) { - var args = packet.data || []; - onevent.call (this, packet); // original call - packet.data = ["*"].concat(args); - onevent.call(this, packet); // additional call to catch-all - }; - - // register catch all. - socket.on('*', function (notification, payload) { - if (notification !== '*') { - //console.log('Received notification: ' + notification +', payload: ' + payload); - notificationCallback(notification, payload); - } - }); - + var onevent = socket.onevent; + socket.onevent = function (packet) { + var args = packet.data || []; + onevent.call (this, packet); // original call + packet.data = ["*"].concat(args); + onevent.call(this, packet); // additional call to catch-all + }; + // register catch all. + socket.on('*', function (notification, payload) { + if (notification !== '*') { + //console.log('Received notification: ' + notification +', payload: ' + payload); + notificationCallback(notification, payload); + } }); - var sendNotification = function(notification, payload) { - //console.log('Send notification: ' + notification +', payload: ' + payload); - socket.emit(notification, payload); - }; // Public Methods this.setNotificationCallback = function(callback) { @@ -74,10 +37,6 @@ var MMSocket = function(moduleName) { if (typeof payload === 'undefined') { payload = {}; } - sendNotification(notification, payload); + socket.emit(notification, payload); }; -}; - -if (typeof module !== 'undefined') { - module.exports = MMSocket; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/modules/node_modules/node_helper/index.js b/modules/node_modules/node_helper/index.js index 3ccead17..7d6b1834 100644 --- a/modules/node_modules/node_helper/index.js +++ b/modules/node_modules/node_helper/index.js @@ -6,7 +6,6 @@ */ var Class = require('../../../js/class.js'); -var MMSocket = require('../../../js/socketclient.js'); NodeHelper = Class.extend({ init: function() { @@ -34,24 +33,6 @@ NodeHelper = Class.extend({ */ setName: function(name) { this.name = name; - this.socket(); - }, - - /* socket() - * Returns a socket object. If it doesn't exsist, it's created. - * It also registers the notification callback. - */ - socket: function() { - if (typeof this._socket === 'undefined') { - this._socket = this._socket = new MMSocket(this.name); - } - - var self = this; - this._socket.setNotificationCallback(function(notification, payload) { - self.socketNotificationReceived(notification, payload); - }); - - return this._socket; }, /* sendSocketNotification(notification, payload) @@ -61,7 +42,39 @@ NodeHelper = Class.extend({ * argument payload mixed - The payload of the notification. */ sendSocketNotification: function(notification, payload) { - this.socket().sendNotification(notification, payload); + this.io.of(this.name).emit(notification, payload); + }, + + /* setSocketIO(io) + * Sets the socket io object for this module. + * Binds message receiver. + * + * argument io Socket.io - The Socket io object. + */ + setSocketIO: function(io) { + var self = this; + self.io = io; + + console.log('Connecting socket for: ' + this.name); + var namespace = this.name; + io.of(namespace).on('connection', function (socket) { + // add a catch all event. + var onevent = socket.onevent; + socket.onevent = function (packet) { + var args = packet.data || []; + onevent.call (this, packet); // original call + packet.data = ["*"].concat(args); + onevent.call(this, packet); // additional call to catch-all + }; + + // register catch all. + socket.on('*', function (notification, payload) { + if (notification !== '*') + console.log('received message in namespace: ' + namespace); + self.socketNotificationReceived(notification, payload); + }); + }); + } }); diff --git a/modules/weatherforecast/weatherforecast.css b/modules/weatherforecast/weatherforecast.css index c46c633a..5f62b3e0 100644 --- a/modules/weatherforecast/weatherforecast.css +++ b/modules/weatherforecast/weatherforecast.css @@ -1,6 +1,6 @@ .weatherforecast .day { padding-left: 0px; - padding-right: 20px; + padding-right: 25px; } .weatherforecast .weather-icon { @@ -9,7 +9,7 @@ } .weatherforecast .min-temp { - padding-left: 10px; + padding-left: 20px; padding-right: 0px; } diff --git a/modules/weatherforecast/weatherforecast.js b/modules/weatherforecast/weatherforecast.js index 47ac33db..f9f02867 100644 --- a/modules/weatherforecast/weatherforecast.js +++ b/modules/weatherforecast/weatherforecast.js @@ -21,7 +21,7 @@ Module.create({ fade: true, fadePoint: 0.25, // Start on 1/4th of the list. - initialLoadDelay: 5000, // 5 seconds delay. This delay is used to keep the OpenWeather API happy. + initialLoadDelay: 2500, // 2.5 seconds delay. This delay is used to keep the OpenWeather API happy. retryDelay: 2500, apiVersion: '2.5',