MagicMirror/js/socket.js

35 lines
733 B
JavaScript
Raw Normal View History

2020-05-02 10:39:09 +02:00
/* global io */
/* Magic Mirror
* Socket Connection
*
2020-04-28 23:05:28 +02:00
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var MMSocket = function(moduleName) {
var self = this;
2016-04-05 14:35:11 -04:00
if (typeof moduleName !== "string") {
throw new Error("Please set the module name for the MMSocket.");
}
self.moduleName = moduleName;
2016-04-05 14:35:11 -04: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) {
2016-04-05 14:35:11 -04:00
Log.log("Send socket message: " + notification);
self.socket.emit("notification", {
notification: notification,
sender: sender,
payload: payload
});
}
};
};