0

first of all I want to apologize if my English is not perfect and if the title does not explain my situation very well.

I will summarize:

I created a code allowing to make different chat between several people using express-ws. I decided to make a chat system with several IDs and I came to this conclusion:

let connects = [];
app.ws('/chat/:id', (ws, req) => {
    app.get('/hello/:id', (req, res) => {
        //...
    })
    connects.push(ws);


    ws.on('message', message => {
      console.log('Received a message: ', message);      
    });
    
    ws.on('close', () => {
      console.log('A user disconnected');
      connects = connects.filter(conn => {
        return (conn === ws) ? false : true;
      });
    });
})

The problem is that connects supports all clients and I would like it to only support clients from req.params.id

Regards,

Stan

Stanley
  • 63
  • 7

0 Answers0