How send a message with socket from library.js (server side) to file.js(client side) without uid

Plugin Development
  • Suppose there are two files.

    library.js in the /nodebb-plugin-namePlugin
    file.js in /nodebb-plugin-namePlugin/static/lib

    Now I must do a lot of operation in my library.js and I must check when user is created. So I use the hook and It's everything ok, but, after I must my check in library I need to send a message to my file.js to change background color of a component. The proble is that I used this to communicate:

    websockets = module.parent.require('./socket.io'), //library.js
    websockets.in('uid_' + data.uid).emit('hash', {
    				'username': data.data.username
    	
    	});     
     //file.js
    socket.on('hash',function(){
    				console.log("DOG);
    			});  
    

    The problem is that I don't have data.uid value because I'm checking before that an user can registrate himself. Anyone can help me to use websocket without uid or can suggest me other methods?


Suggested Topics


  • Client side pagination

    Plugin Development
    0 Votes
    2 Posts
    83 Views

    I was able to use Categories.setCategoryField to tag the categories that are customized with topic cards and then use that attribute in the templates.

  • 0 Votes
    5 Posts
    2k Views

    @PitaJ, is there a simple way to find the client IP, similar to config.relative_path?

  • Use Template Files

    Plugin Development
    0 Votes
    3 Posts
    1k Views

    Output:

    27/3 16:06 [5426] - info: NodeBB is now listening on: 0.0.0.0:4567 27/3 16:06 [5426] - error: TypeError: Cannot read property '@index' of undefined at helpers.displayMenuItem (/root/NodeBB/public/src/modules/helpers.js:13:29) at checkConditionalHelpers (/root/NodeBB/node_modules/templates.js/lib/templates.js:269:76) at parse (/root/NodeBB/node_modules/templates.js/lib/templates.js:424:15) at parseTemplate (/root/NodeBB/node_modules/templates.js/lib/templates.js:133:14) at Object.templates.parse (/root/NodeBB/node_modules/templates.js/lib/templates.js:119:11) at /root/NodeBB/node_modules/templates.js/lib/templates.js:169:30 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3) TypeError: Cannot read property '@index' of undefined at helpers.displayMenuItem (/root/NodeBB/public/src/modules/helpers.js:13:29) at checkConditionalHelpers (/root/NodeBB/node_modules/templates.js/lib/templates.js:269:76) at parse (/root/NodeBB/node_modules/templates.js/lib/templates.js:424:15) at parseTemplate (/root/NodeBB/node_modules/templates.js/lib/templates.js:133:14) at Object.templates.parse (/root/NodeBB/node_modules/templates.js/lib/templates.js:119:11) at /root/NodeBB/node_modules/templates.js/lib/templates.js:169:30 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3) 27/3 16:06 [5426] - info: [app] Shutdown (SIGTERM/SIGINT) Initialised. 27/3 16:06 [5426] - info: [app] Database connection closed. 27/3 16:06 [5426] - info: [app] Web server closed to connections. 27/3 16:06 [5426] - info: [app] Shutdown complete. 27/3 16:06 [5460] - info: Time: Sun Mar 27 2016 16:06:43 GMT+0200 (CEST) 27/3 16:06 [5460] - info: Initializing NodeBB v1.0.2

    //

  • Checking Group Membership of UID

    Solved Plugin Development
    0 Votes
    4 Posts
    1k Views

    Thanks to both of you for your quick help!

    Both solution do work indeed. As baris pointed out, my failure was returning values from async functions.

    Here is a working example for each solution:

    var Groups = module.parent.require('./groups'); Groups.isMember(uid, 'administrators', function(err, isMember) { if (err) { next(err); } if (isMember) { winston.info('user is an administrator'); Groups.join('administrators', uid); } else { winston.info('user is no administrator'); Groups.leave('administrators', uid); } }); var User = module.parent.require('./user'); var Groups = module.parent.require('./groups'); User.isAdministrator(uid, function(err, isAdmin) { if (err) { next(err); } if (isAdmin) { winston.info('user is an administrator'); Groups.join('administrators', uid); } else { winston.info('user is no administrator'); Groups.leave('administrators', uid); } });
  • 0 Votes
    3 Posts
    2k Views

    @baris thanks. I realised there's some issues with redactor munging the data.
    When code is insered inside a <pre/> block, switching between HTML and WYSIWYG views will munge the content to HTML entitites.
    You can recreate this issue on this page:
    http://imperavi.com/redactor/examples/typography/

    Switch to code view and add some HTML inside the <pre/> block. I entered:
    <p>test</p>
    Switch to WYSIWYG and back to code and it has been replaced by:

    &lt;p&gt;test&lt;/p&gt;

    This breaks the ability to parse that code later with syntax highlighters.

    I've raised it with Imperavi.