MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    sendSocketNotification is not working from node_helper to main module

    Scheduled Pinned Locked Moved Development
    1 Posts 1 Posters 1.1k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P Offline
      priya
      last edited by

      Hi,

      I am new to node.js.I am trying to create new sample module “test”.I am sending notification from test module to node_helper and trying to receive notification back to test module.From test module to node_helper notification works fine, but test module does not receive any notification from node_helper.

      Here is my module code:
      test.js:

      Module.register("test",{
      
      	defaults:{
      		text:"Happy Birthday!!!!"
      	},
      	
      	getDom: function() {
      		var wrapper = document.createElement("div");
      		wrapper.innerHTML =this.config.text;
      		return wrapper;
      	},
      	
      	start:function(){
      		this.sendSocketNotification("main",{message:"test1"});
      	},
      	
      	
      	socketNotificationReceived: function(notification, payload) {
      		console.log('socketNotificationReceived() in main module..'+notification);
      		if (notification === "test2") {
      			console.log('test2 socket notification received...');
      		}
      	}
      	
      });
      
      

      Here is node_helper.js:

      var NodeHelper = require("node_helper");
      
      module.exports = NodeHelper.create({
      	// Override start method.
      	start: function() {
      		
      	},
      
      	// Override socketNotificationReceived method.
      	socketNotificationReceived: function(notification, payload) {
      		var self=this;
      		console.log('*Starting socketNotificationReceived()*'+notification);
      		if (notification === "main") {
      			console.log(notification+' socket notification received...');
      			this.function1();
      		}
      	},
      	
      	function1:function(){
      		console.log('inside function1');
      		this.sendSocketNotification("test2",{message:"test2"});
      	}
      });
      

      Here is config.js:

      var config = {
      	port: 8080,
      	ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses.
      
      	language: "en",
      	timeFormat: 24,
      	units: "metric",
      
      	modules: [
      		
      		{
      			module: "test",
      			position: "top_right"
      		}
              ]
         };
      
      

      I am stuck there since last 3-4 days.If something is missing or wrong please correct me.Any help appreciated

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • 1 / 1
      • First post
        Last post
      Enjoying MagicMirror? Please consider a donation!
      MagicMirror created by Michael Teeuw.
      Forum managed by Sam, technical setup by Karsten.
      This forum is using NodeBB as its core | Contributors
      Contact | Privacy Policy