mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 17:44:52 -04:00
Standardize: TO JSCS!
This commit is contained in:
parent
18390503b5
commit
426728058c
28 changed files with 623 additions and 653 deletions
|
@ -1,40 +1,39 @@
|
|||
var MMSocket = function(moduleName) {
|
||||
var self = this;
|
||||
|
||||
if (typeof moduleName !== 'string') {
|
||||
throw new Error('Please set the module name for the MMSocket.');
|
||||
if (typeof moduleName !== "string") {
|
||||
throw new Error("Please set the module name for the MMSocket.");
|
||||
}
|
||||
|
||||
self.moduleName = moduleName;
|
||||
|
||||
// Private Methods
|
||||
socket = io.connect('/' + self.moduleName);
|
||||
socket = io.connect("/" + self.moduleName);
|
||||
var notificationCallback = function() {};
|
||||
|
||||
var onevent = socket.onevent;
|
||||
socket.onevent = function (packet) {
|
||||
socket.onevent = function(packet) {
|
||||
var args = packet.data || [];
|
||||
onevent.call (this, packet); // original call
|
||||
onevent.call(this, packet); // original call
|
||||
packet.data = ["*"].concat(args);
|
||||
onevent.call(this, packet); // additional call to catch-all
|
||||
};
|
||||
|
||||
// register catch all.
|
||||
socket.on('*', function (notification, payload) {
|
||||
if (notification !== '*') {
|
||||
socket.on("*", function(notification, payload) {
|
||||
if (notification !== "*") {
|
||||
//console.log('Received notification: ' + notification +', payload: ' + payload);
|
||||
notificationCallback(notification, payload);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Public Methods
|
||||
this.setNotificationCallback = function(callback) {
|
||||
notificationCallback = callback;
|
||||
};
|
||||
|
||||
this.sendNotification = function(notification, payload) {
|
||||
if (typeof payload === 'undefined') {
|
||||
if (typeof payload === "undefined") {
|
||||
payload = {};
|
||||
}
|
||||
socket.emit(notification, payload);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue