MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. ngnijland
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    N
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Groups 0

    ngnijland

    @ngnijland

    0
    Reputation
    2
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    ngnijland Unfollow Follow

    Latest posts made by ngnijland

    • RE: How to send a function as payload of socket notification?

      @Sean
      Ah ofcourse, thanks for the explanation!

      My function does not have dependencies. I’ll use good old eval to fix this!

      My use case is that I need to use a different function based on the language setting of the mirror. These functions live in a separate folder and I import them in the node_helper.js file (together with some other arrays and objects I need based on language). For now I’ll use this solution, maybe in the future I build in a build step in my module so I can import the files directly into my main module file.

      https://github.com/ngnijland/MMM-text-clock/pull/2

      posted in Development
      N
      ngnijland
    • RE: How to send a function as payload of socket notification?

      @sdetweil thanks for your reply!

      I don’t think I completely understand you. What do you mean with “send the entire function”? Do you mean I can’t import a reference? And should write out the function in the node_helper.js file?

      posted in Development
      N
      ngnijland
    • How to send a function as payload of socket notification?

      Hello,

      When I receive a socket notification in my node_helper.js file I want to sent a socket notification with an object containing a function as value of one of its keys. Like this:

      const NodeHelper = require('node_helper');
      const someFunction = require('./someFunction');
      
      module.exports = NodeHelper.create({
        start: function () {
          console.log('Start node helper');
        },
      
        socketNotificationReceived: function (notification) {
          if (notification === 'FOO') {
            this.sendSocketNotification('FOO', { bar: someFunction });
          }
        },
      });
      

      However, when I receive this notification inside my main module file the function is not present in the payload:

        socketNotificationReceived: function (notification, payload) {
          if (notification === 'FOO') {
            console.log(payload.bar); // This logs 'undefined'
          }
        },
      

      Any other values (object, arrays, etc) I pass in the payload are received correctly.

      Does somebody know why the function I pass with the payload is undefined when I receive the socket notification in my main module file?

      posted in Development socket notification notifications payload nodehelper
      N
      ngnijland