• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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 May 22, 2017, 9:52 AM

    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
    • 1 / 1
    1 / 1
    • First post
      1/1
      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