MCPcopy
hub / github.com/socketio/socket.io / to

Method to

packages/socket.io/lib/broadcast-operator.ts:48–61  ·  view source on GitHub ↗

* Targets a room when emitting. * * @example * // the “foo” event will be broadcast to all connected clients in the “room-101” room * io.to("room-101").emit("foo", "bar"); * * // with an array of rooms (a client will be notified at most once) * io.to(["room-101", "room-102"]).em

(room: Room | Room[])

Source from the content-addressed store, hash-verified

46 * @return a new {@link BroadcastOperator} instance for chaining
47 */
48 public to(room: Room | Room[]) {
49 const rooms = new Set(this.rooms);
50 if (Array.isArray(room)) {
51 room.forEach((r) => rooms.add(r));
52 } else {
53 rooms.add(room);
54 }
55 return new BroadcastOperator<EmitEvents, SocketData>(
56 this.adapter,
57 rooms,
58 this.exceptRooms,
59 this.flags,
60 );
61 }
62
63 /**
64 * Targets a room when emitting. Similar to `to()`, but might feel clearer in some cases:

Callers 1

inMethod · 0.95

Calls 1

addMethod · 0.45

Tested by

no test coverage detected