Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
socket.io emitting to all clients works, but emitting to room doesn't work

When I try io.emit(), the message gets emitted to everyone but when I try io.to(room).emit(), the message doesn't get emitted (In the 3rd last line of the code).

I manually checked the sockets in the room, and all are present in the room correctly. But the message never gets transmitted.

io.on('connection', (socket) => {
    socket.on("create game", async ( gameID, host ) => {
        socket.join(gameID);
        // some logic
    })
    socket.on("join game", async ( gameID, user ) => {
        socket.join(gameID);
        // some logic
        io.to(gameID).emit("new user", user);
    })
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Is your socket connected to a particular namespace? In my project I had on the client side the following:

const socket = io.connect("/play-online").

So in order to emit to the room I created for that, I had to do:

io.of("/play-online").to(room.roomName).emit("move", move);
about 4 years ago · Juan Pablo Isaza Relatório

0

I was able to fix it using socket.in(gameID).emit("new user", user); instead

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda