2016-03-30 12:20:46 +02:00
|
|
|
/* Magic Mirror
|
|
|
|
* Socket Connection
|
|
|
|
*
|
|
|
|
* By Michael Teeuw http://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.");
|
2016-03-30 12:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
self.moduleName = moduleName;
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
self.socket = io("http://localhost:8080");
|
|
|
|
self.socket.on("notification", function(data) {
|
2016-03-30 12:20:46 +02:00
|
|
|
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", {
|
2016-03-30 12:20:46 +02:00
|
|
|
notification: notification,
|
|
|
|
sender: sender,
|
|
|
|
payload: payload
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-04-03 19:52:13 +02:00
|
|
|
};
|