mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
commit
6327670b6f
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,4 +1,13 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
|
|
||||||
!/modules/node_helper
|
!/modules/node_helper
|
||||||
!/modules/node_helper/**
|
!/modules/node_helper/**
|
||||||
|
|
||||||
|
/modules/*
|
||||||
|
!/modules/calendar
|
||||||
|
!/modules/clock
|
||||||
|
!/modules/compliments
|
||||||
|
!/modules/currentweather
|
||||||
|
!/modules/helloworld
|
||||||
|
!/modules/newsfeed
|
||||||
|
!/modules/weatherforecast
|
||||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -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.
|
19
README.md
19
README.md
@ -13,16 +13,27 @@ This version of the Magic Mirror software focusses on a modular plugin system. B
|
|||||||
|
|
||||||
##Todo
|
##Todo
|
||||||
Things that still have to be implemented or changed.
|
Things that still have to be implemented or changed.
|
||||||
|
|
||||||
####Loader
|
####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).
|
- 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)
|
**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.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@ const app = electron.app;
|
|||||||
// Module to create native browser window.
|
// Module to create native browser window.
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
const BrowserWindow = electron.BrowserWindow;
|
||||||
|
|
||||||
|
var nodeHelpers = [];
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// 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.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
@ -68,7 +70,7 @@ function loadModule(moduleName) {
|
|||||||
var Module = require(helperPath);
|
var Module = require(helperPath);
|
||||||
var m = new Module();
|
var m = new Module();
|
||||||
m.setName(moduleName);
|
m.setName(moduleName);
|
||||||
m.start();
|
nodeHelpers.push(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,16 +97,26 @@ loadConfig(function(c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadModules(modules);
|
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
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
var server = new Server(config, function() {
|
console.log('Launching application.');
|
||||||
setTimeout(function() {
|
createWindow();
|
||||||
createWindow();
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
|
51
js/server.js
51
js/server.js
@ -12,53 +12,6 @@ var io = require('socket.io')(server);
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
var Server = function(config, callback) {
|
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 + " ... ");
|
console.log("Starting server op port " + config.port + " ... ");
|
||||||
|
|
||||||
server.listen(config.port);
|
server.listen(config.port);
|
||||||
@ -73,10 +26,8 @@ var Server = function(config, callback) {
|
|||||||
res.sendFile(path.resolve(__dirname + '/../index.html'));
|
res.sendFile(path.resolve(__dirname + '/../index.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
createNamespaces();
|
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback();
|
callback(io);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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 MMSocket = function(moduleName) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (typeof moduleName !== 'string') {
|
if (typeof moduleName !== 'string') {
|
||||||
@ -33,37 +8,25 @@ var MMSocket = function(moduleName) {
|
|||||||
self.moduleName = moduleName;
|
self.moduleName = moduleName;
|
||||||
|
|
||||||
// Private Methods
|
// Private Methods
|
||||||
var socketBase = (typeof window === 'undefined') ? 'http://localhost:'+config.port : '';
|
socket = io.connect('/' + self.moduleName);
|
||||||
socket = io(socketBase + '/' + self.moduleName);
|
|
||||||
|
|
||||||
var notificationCallback = function() {};
|
var notificationCallback = function() {};
|
||||||
|
|
||||||
socket.on('connect', function(s) {
|
var onevent = socket.onevent;
|
||||||
|
socket.onevent = function (packet) {
|
||||||
// add a catch all event.
|
var args = packet.data || [];
|
||||||
var onevent = socket.onevent;
|
onevent.call (this, packet); // original call
|
||||||
socket.onevent = function (packet) {
|
packet.data = ["*"].concat(args);
|
||||||
var args = packet.data || [];
|
onevent.call(this, packet); // additional call to catch-all
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
// Public Methods
|
||||||
this.setNotificationCallback = function(callback) {
|
this.setNotificationCallback = function(callback) {
|
||||||
@ -74,10 +37,6 @@ var MMSocket = function(moduleName) {
|
|||||||
if (typeof payload === 'undefined') {
|
if (typeof payload === 'undefined') {
|
||||||
payload = {};
|
payload = {};
|
||||||
}
|
}
|
||||||
sendNotification(notification, payload);
|
socket.emit(notification, payload);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {
|
|
||||||
module.exports = MMSocket;
|
|
||||||
}
|
|
53
modules/node_modules/node_helper/index.js
generated
vendored
53
modules/node_modules/node_helper/index.js
generated
vendored
@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var Class = require('../../../js/class.js');
|
var Class = require('../../../js/class.js');
|
||||||
var MMSocket = require('../../../js/socketclient.js');
|
|
||||||
|
|
||||||
NodeHelper = Class.extend({
|
NodeHelper = Class.extend({
|
||||||
init: function() {
|
init: function() {
|
||||||
@ -34,24 +33,6 @@ NodeHelper = Class.extend({
|
|||||||
*/
|
*/
|
||||||
setName: function(name) {
|
setName: function(name) {
|
||||||
this.name = 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)
|
/* sendSocketNotification(notification, payload)
|
||||||
@ -61,7 +42,39 @@ NodeHelper = Class.extend({
|
|||||||
* argument payload mixed - The payload of the notification.
|
* argument payload mixed - The payload of the notification.
|
||||||
*/
|
*/
|
||||||
sendSocketNotification: function(notification, payload) {
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
.weatherforecast .day {
|
.weatherforecast .day {
|
||||||
padding-left: 0px;
|
padding-left: 0px;
|
||||||
padding-right: 20px;
|
padding-right: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.weatherforecast .weather-icon {
|
.weatherforecast .weather-icon {
|
||||||
@ -9,7 +9,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.weatherforecast .min-temp {
|
.weatherforecast .min-temp {
|
||||||
padding-left: 10px;
|
padding-left: 20px;
|
||||||
padding-right: 0px;
|
padding-right: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ Module.create({
|
|||||||
fade: true,
|
fade: true,
|
||||||
fadePoint: 0.25, // Start on 1/4th of the list.
|
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,
|
retryDelay: 2500,
|
||||||
|
|
||||||
apiVersion: '2.5',
|
apiVersion: '2.5',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user