mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
New node_helper loading.
This commit is contained in:
72
modules/node_modules/node_helper/index.js
generated
vendored
Normal file
72
modules/node_modules/node_helper/index.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/* Magic Mirror
|
||||
* Node Helper Superclass
|
||||
*
|
||||
* By Michael Teeuw http://michaelteeuw.nl
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
var Class = require('../../../js/class.js');
|
||||
var MMSocket = require('../../../js/socketclient.js');
|
||||
|
||||
NodeHelper = Class.extend({
|
||||
init: function() {
|
||||
console.log('Initializing new module helper ...');
|
||||
},
|
||||
|
||||
start: function() {
|
||||
console.log('Staring module helper: ' + this.name);
|
||||
},
|
||||
|
||||
/* 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);
|
||||
},
|
||||
|
||||
/* setName(data)
|
||||
* Set the module name.
|
||||
*
|
||||
* argument name string - Module name.
|
||||
*/
|
||||
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)
|
||||
* 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);
|
||||
}
|
||||
});
|
||||
|
||||
NodeHelper.create = function(moduleDefinition) {
|
||||
return NodeHelper.extend(moduleDefinition);
|
||||
};
|
||||
|
||||
module.exports = NodeHelper;
|
Reference in New Issue
Block a user