Using socket.io's "namespace" feature



  • 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! <3


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.