* 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[])
| 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: |