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:
37
js/module.js
37
js/module.js
@@ -88,7 +88,15 @@ var Module = Class.extend({
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/* socketNotificationReceived(notification, payload)
|
||||
* This method is called when a socket notification arrives.
|
||||
*
|
||||
* argument notification string - The identifier of the noitication.
|
||||
* argument payload mixed - The payload of the notification.
|
||||
*/
|
||||
socketNotificationReceived: function(notification, payload) {
|
||||
Log.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload);
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -118,6 +126,23 @@ var Module = Class.extend({
|
||||
this.config = Object.assign(this.defaults, config);
|
||||
},
|
||||
|
||||
/* 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;
|
||||
},
|
||||
|
||||
/* file(file)
|
||||
* Retrieve the path to a module fike.
|
||||
*
|
||||
@@ -170,6 +195,16 @@ var Module = Class.extend({
|
||||
*/
|
||||
sendNotification: function(notification, payload) {
|
||||
MM.sendNotification(notification, payload, this);
|
||||
},
|
||||
|
||||
/* sendSocketNotification(notification, payload)
|
||||
* Send a socket notification to the node helper.
|
||||
*
|
||||
* argument notification string - The identifier of the noitication.
|
||||
* argument payload mixed - The payload of the notification.
|
||||
*/
|
||||
sendSocketNotification: function(notification, payload) {
|
||||
this.socket().sendNotification(notification, payload);
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user