MagicMirror/js/socket.js

37 lines
738 B
JavaScript
Raw Normal View History

/* 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;
2016-04-01 22:52:32 +02:00
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
});
}
};
2016-04-01 22:52:32 +02:00
};