0

I have a node JS server, with WS server on it, so i a question.

How can I make chat rooms, so that if 1 client sends message to another, only 2 of them can see the message, in their own group/chat?

This is how I send messages now:

const server = new WebSocket.Server({ port: 3000 })
server.on('connection', (ws, request) => {
    ws.on('message', message => {
        if (message === 'exit') {
            ws.close()
        } else {
            server.clients.forEach(client => {
                if (client.readyState === WebSocket.OPEN) {
                    client.send(message)
                }
            })
        }
    })
})

And my node JS server is on port :8000

  • 1
    Maybe some of the answers from [this question](https://stackoverflow.com/questions/62370962/how-to-create-join-chat-room-using-ws-websocket-package-in-node-js) can help you? – node_modules Oct 12 '22 at 13:17

0 Answers0