From 7f533484399e2aa594ec0ad447256f19d3a0b249 Mon Sep 17 00:00:00 2001 From: nihaljhariya Date: Wed, 25 Dec 2024 13:29:28 +0530 Subject: [PATCH] Update 06-broadcasting.md --- docs/tutorial/06-broadcasting.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/tutorial/06-broadcasting.md b/docs/tutorial/06-broadcasting.md index a24d9f34..3206d4ea 100644 --- a/docs/tutorial/06-broadcasting.md +++ b/docs/tutorial/06-broadcasting.md @@ -15,12 +15,14 @@ In order to send an event to everyone, Socket.IO gives us the `io.emit()` method ```js // this will emit the event to all connected sockets +// put this code on index.js file io.emit('hello', 'world'); ``` If you want to send a message to everyone except for a certain emitting socket, we have the `broadcast` flag for emitting from that socket: ```js +// put this code on index.js file io.on('connection', (socket) => { socket.broadcast.emit('hi'); }); @@ -29,6 +31,7 @@ io.on('connection', (socket) => { In this case, for the sake of simplicity we’ll send the message to everyone, including the sender. ```js +replace this line of code from index.js io.on('connection', (socket) => { socket.on('chat message', (msg) => { io.emit('chat message', msg);