Using socket.io's "namespace" feature

Plugin Development
  • Hi, I would like to use NodeBB/src/socket.io as much as I can for my own application, but I would like to separate all of my own socketing into a custom namespace (not just method name namespace, but Socket.IO's own namespace feature.)

    To get a server object that listens on a namespace I do

    var socketio = require.main.require('./src/socket.io');
    var nsp_server = socketio.server.of('/custom_namespace');
    

    Now my issue is, if using nsp_server to listen to connections, such as here:

    nsp_server.on('connect', function (socket) {
        console.log(socket.uid);
    }
    

    The socket object does not seem to come already processed by the middleware that the proper NodeBB sockets do (such as the authorize() in src/socket.io/index.js which is what populates the socket.uid value)

    On the other hand, if I am to use src/socket.io/plugins.js, then I won't have to deal with the nsp_server.on('connect', etc... But in that case, I won't be able to use the custom namespace feature (right?)

    So, either, how do I (re)use NodeBB socket middleware without (re)writing it in my own code, or how do I use SocketPlugins with a custom namespace?

    Thanks for reading. I would greatly appreciate any input! lets discuss! ❤


Suggested Topics


  • 1 Votes
    1 Posts
    215 Views

    After install "nodebb-plugin-sso-beer-qq", my server crashed and nginx return code 502.

    After reset all plugins, my server is back to normal again.

  • 0 Votes
    7 Posts
    546 Views

    @baris OK. I changed this and it works now. Thanks!

  • 0 Votes
    7 Posts
    2k Views

    @julian I've made a pull request that creates a test and actually addresses the underlying problem on top of it! https://github.com/NodeBB/NodeBB/pull/4796

    If there's something messed up about it feel free to tell me. Like I said, I'm new to the NodeJS world so I wouldn't be surprised if I did something incorrectly. 🙂

  • 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

    //

  • 0 Votes
    3 Posts
    2k Views

    Hello Julian. Thank you for your very useful answer.
    The plugin was an old version.
    I just did uninstall then reinstall the last nodebb-api-write plugin (version 3.1.5) on our instance, but now I get the following error :
    /admin/plugins/write-api Introuvable (not found)