From ccc6295356ea3d271ed7d1f7c012823fb74a96c8 Mon Sep 17 00:00:00 2001 From: Michael Scott Hertzberg Date: Sun, 10 May 2020 12:58:48 -0400 Subject: [PATCH] hacky web socket fix https://github.com/Jopyth/MMM-Remote-Control/issues/185\#issuecomment-608600298 --- js/socketclient.js | 86 ++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/js/socketclient.js b/js/socketclient.js index ee30f26..c8209f1 100644 --- a/js/socketclient.js +++ b/js/socketclient.js @@ -1,42 +1,44 @@ -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; - - // Private Methods - self.socket = io("/" + self.moduleName, { - path: window.location.pathname + "socket.io" - }); - var notificationCallback = function() {}; - - var onevent = self.socket.onevent; - self.socket.onevent = function(packet) { - var args = packet.data || []; - onevent.call(this, packet); // original call - packet.data = ["*"].concat(args); - onevent.call(this, packet); // additional call to catch-all - }; - - // register catch all. - self.socket.on("*", function(notification, payload) { - if (notification !== "*") { - notificationCallback(notification, payload); - } - }); - - // Public Methods - this.setNotificationCallback = function(callback) { - notificationCallback = callback; - }; - - this.sendNotification = function(notification, payload) { - if (typeof payload === "undefined") { - payload = {}; - } - self.socket.emit(notification, payload); - }; -}; +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 + + // Private Methods + // self.socket = io("/" + self.moduleName, { + // path: window.location.pathname + "socket.io" + // }); + self.socket = io('/' + self.moduleName) + + var notificationCallback = function () {} + + var onevent = self.socket.onevent + self.socket.onevent = function (packet) { + var args = packet.data || [] + onevent.call(this, packet) // original call + packet.data = ['*'].concat(args) + onevent.call(this, packet) // additional call to catch-all + } + + // register catch all. + self.socket.on('*', function (notification, payload) { + if (notification !== '*') { + notificationCallback(notification, payload) + } + }) + + // Public Methods + this.setNotificationCallback = function (callback) { + notificationCallback = callback + } + + this.sendNotification = function (notification, payload) { + if (typeof payload === 'undefined') { + payload = {} + } + self.socket.emit(notification, payload) + } +}