Complete the code to join a client to a room in a NestJS WebSocket gateway.
handleConnection(client: Socket) {
client.[1]('room1');
}The join method adds the client socket to a room.
Complete the code to emit a message to all clients in a specific room.
this.server.to('room1').[1]('message', 'Hello Room!');
The emit method sends an event with data to clients in the specified room.
Fix the error in the code to broadcast a message to all clients except the sender in a room.
client.[1].to('room1').emit('message', 'Hello others!');
The broadcast property allows sending to all clients except the sender.
Fill both blanks to create a namespace and listen for a connection event.
const namespace = this.server.of('[1]'); namespace.on('[2]', (client) => { console.log('Client connected'); });
The of method creates or accesses a namespace by name (e.g., '/chat'). The event to listen for new clients is connection.
Fill all three blanks to emit a message to a room inside a namespace.
const ns = this.server.of('[1]'); ns.to('[2]').[3]('event', 'data');
First, get the namespace '/updates'. Then target the room 'room42'. Finally, use emit to send the event.