Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

socketclient.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* global io */
  2. /* Magic Mirror
  3. * TODO add description
  4. *
  5. * By Michael Teeuw https://michaelteeuw.nl
  6. * MIT Licensed.
  7. */
  8. const MMSocket = function (moduleName) {
  9. if (typeof moduleName !== "string") {
  10. throw new Error("Please set the module name for the MMSocket.");
  11. }
  12. this.moduleName = moduleName;
  13. // Private Methods
  14. let base = "/";
  15. if (typeof config !== "undefined" && typeof config.basePath !== "undefined") {
  16. base = config.basePath;
  17. }
  18. this.socket = io("/" + this.moduleName, {
  19. path: base + "socket.io"
  20. });
  21. let notificationCallback = function () {};
  22. const onevent = this.socket.onevent;
  23. this.socket.onevent = (packet) => {
  24. const args = packet.data || [];
  25. onevent.call(this.socket, packet); // original call
  26. packet.data = ["*"].concat(args);
  27. onevent.call(this.socket, packet); // additional call to catch-all
  28. };
  29. // register catch all.
  30. this.socket.on("*", (notification, payload) => {
  31. if (notification !== "*") {
  32. notificationCallback(notification, payload);
  33. }
  34. });
  35. // Public Methods
  36. this.setNotificationCallback = (callback) => {
  37. notificationCallback = callback;
  38. };
  39. this.sendNotification = (notification, payload) => {
  40. if (typeof payload === "undefined") {
  41. payload = {};
  42. }
  43. this.socket.emit(notification, payload);
  44. };
  45. };