0
0
NestJSframework~10 mins

Rooms and namespaces in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to join a client to a room in a NestJS WebSocket gateway.

NestJS
handleConnection(client: Socket) {
  client.[1]('room1');
}
Drag options to blanks, or click blank then click option'
AaddRoom
BjoinRoom
Cjoin
DconnectRoom
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like 'joinRoom' or 'addRoom'.
2fill in blank
medium

Complete the code to emit a message to all clients in a specific room.

NestJS
this.server.to('room1').[1]('message', 'Hello Room!');
Drag options to blanks, or click blank then click option'
Asend
Bbroadcast
Cdispatch
Demit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' which is not the correct method for rooms in socket.io.
3fill in blank
hard

Fix the error in the code to broadcast a message to all clients except the sender in a room.

NestJS
client.[1].to('room1').emit('message', 'Hello others!');
Drag options to blanks, or click blank then click option'
Abroadcast
Bemit
Csend
Dto
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'emit' directly on client without 'broadcast' excludes no one.
4fill in blank
hard

Fill both blanks to create a namespace and listen for a connection event.

NestJS
const namespace = this.server.of('[1]');
namespace.on('[2]', (client) => {
  console.log('Client connected');
});
Drag options to blanks, or click blank then click option'
A/chat
Bconnection
Cconnect
D/game
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'connect' event instead of 'connection'.
Using namespace names without leading slash.
5fill in blank
hard

Fill all three blanks to emit a message to a room inside a namespace.

NestJS
const ns = this.server.of('[1]');
ns.to('[2]').[3]('event', 'data');
Drag options to blanks, or click blank then click option'
A/updates
Broom42
Cemit
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' instead of 'emit'.
Missing the slash in namespace name.