Ad

Socket.io Dont Update When I Use Chat Rooms

- 1 answer

I have tried for 2 hours to get it working with NO success. const stock = io.of('/stocks'); stock.on('connection', socket => {

When i do that my messages is not updating on the client side..

But when i do this: io.on('connection', socket => { then it works. But i need to have different chat rooms. And i have no idea why the io.of not works.

I have tried with everything that has come to my head. I dont understand why it just works when i dont use the io.of, it is really weird.

What can i do for it to work correctly?

Ad

Answer

custom namespace in socket.io, you have to decare it first, then connect.

const nsp = io.of('/my-namespace');
nsp.on('connection', function(socket){
                       console.log('someone connected');
                                                        });
nsp.emit('hi', 'everyone!');
Ad
source: stackoverflow.com
Ad