socket.io
socket.io copied to clipboard
Empty .to([]) sends to everybody instead of nobody
Describe the bug
io.to([]).emit("hello") sends to everybody instead of nobody
To Reproduce
Socket.IO server version: 4.6.1
Server
import { Server } from "socket.io";
const io = new Server(3000, {});
io.on("connection", () => {
io.to([]).emit("hello");
});
Socket.IO client version: 4.6.1
Client
import { io } from "socket.io-client";
const socket = io("ws://localhost:3000/", {});
socket.on("hello", () => {
console.log("hello received");
});
Expected behavior
I expect no message to be sent when an empty array is passed to .to().
Platform:
- OS: macOS 13.2
Additional context It's easy to work around, but the behavior was unexpected.
I have this problem too, and I have to check every time to see if it's an empty array
@jyustman I could indeed reproduce the behavior, thanks. That is indeed surprising, I guess we can fix this in the next major release.
I can take a look at this one if that's fine?
I observed the same. Could it be due to the following condition in socket.io-adapter?
https://github.com/socketio/socket.io-adapter/blob/28f60b880ad04ff4b48ade0cd529f1970643604f/lib/index.ts#L335-L355