Skip to content

socket.to(roomId).emit() does not work #5342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KNT59 opened this issue Apr 29, 2025 · 0 comments
Open

socket.to(roomId).emit() does not work #5342

KNT59 opened this issue Apr 29, 2025 · 0 comments
Labels
to triage Waiting to be triaged by a member of the team

Comments

@KNT59
Copy link

KNT59 commented Apr 29, 2025

Describe the bug
On server-side, socket leaves its default room, joins a different room, then socket.to(newRoom).emit() is emitting message back to the calling socket when it shouldn't.

To Reproduce

Socket.IO server version: 4.8.1

Server

import { Server } from "socket.io";

const io = new Server(3000, {});

io.on("connection", (socket) => {
  socket.on("foo", async () => {
    await socket.leave(socket.id);
    await socket.join("7a4ccc57-96b4-45a3-963f-02cc1512ce0d");
   
    // This line emits back to sending socket, which goes against the documentation for socket.to().emit();
    socket.to("7a4ccc57-96b4-45a3-963f-02cc1512ce0d").emit("foo", "response");
  })
});

Socket.IO client version: 4.8.1

Client

import { io } from "socket.io-client";

const socket = io("ws://localhost:3000/", {});

socket.on("foo", () => console.log("received message"));
socket.emit("foo", "backend message");

**Expected behavior**
The emitting socket should not receive a response from the backend socket.

**Platform:**
 - OS: Ubuntu/Linux
@KNT59 KNT59 added the to triage Waiting to be triaged by a member of the team label Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage Waiting to be triaged by a member of the team
Projects
None yet
Development

No branches or pull requests

1 participant