Complete the code to emit a message named 'greet' with the text 'Hello'.
socket.[1]('greet', 'Hello');
The emit method sends a message with a specific name and data to the server or client.
Complete the code to listen for a message named 'chat' and log its data.
socket.[1]('chat', (data) => { console.log(data); });
The on method listens for incoming messages with a given name.
Fix the error in the code to correctly emit a message named 'update' with an object.
socket.[1]('update', { status: 'ok' });
To send a named message with data, use emit. Using send sends a default message without a name.
Fill both blanks to listen for a 'message' event and respond by emitting 'reply' with 'Received'.
socket.[1]('message', (msg) => { socket.[2]('reply', 'Received'); });
Use on to listen for the 'message' event, then emit to send the 'reply' event.
Fill all three blanks to emit 'start', listen for 'progress', and emit 'done' when progress reaches 100.
socket.[1]('start'); socket.[2]('progress', (percent) => { if (percent === 100) { socket.[3]('done'); } });
Use emit to send 'start' and 'done' events, and on to listen for 'progress'.