mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Add server (web/socket), create socket system, better helper loader.
- The Magic Mirror is now hosted via a express server, allowing you to load it from an external client (for debugging.) - It now includes a socket system to communicate between the node_helper and the client module. - node_helpers are now only loaded if the module is configured in the config.
This commit is contained in:
40
js/socket.js
Normal file
40
js/socket.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/* exported Log */
|
||||
|
||||
/* Magic Mirror
|
||||
* Socket Connection
|
||||
*
|
||||
* By Michael Teeuw http://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
var MMSocket = function(moduleName) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (typeof moduleName !== 'string') {
|
||||
throw new Error('Please set the module name for the MMSocket.');
|
||||
}
|
||||
|
||||
self.moduleName = moduleName;
|
||||
|
||||
|
||||
self.socket = io('http://localhost:8080');
|
||||
self.socket.on('notification', function (data) {
|
||||
MM.sendNotification(data.notification, data.payload, Socket);
|
||||
});
|
||||
|
||||
return {
|
||||
sendMessage: function(notification, payload, sender) {
|
||||
Log.log('Send socket message: ' + notification);
|
||||
self.socket.emit('notification', {
|
||||
notification: notification,
|
||||
sender: sender,
|
||||
payload: payload
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user