Hi everyone!
In this video we will explore the one more powerful API of the socket.io will be the broadcasting.
Well, what exactly about broadcasting?
Well, we have a two different types of same message with the broadcasting.
The first will be send message to all clients okay.
And the second one will be send a message to all clients.
But except myself, what do I mean by now?
In order to send a message into all the client, we will use the IO over here.
Okay.
What exactly about IO the socket IO library?
It will manage all client inside the "io" object.
Okay, so for that reason, in order to send the message for all client, we will use the "io".
But how about the second one?
We will send message to all client except myself.
Well, for example, I am a client one.
I want to send a message into the server and at the same time we have a multiple connection.
Right here.
When I send a message.
I want the server here will be sent back to all client.
But accept me, okay?
It will accept me because
I send a message, right?
So what?
I want to accept myself.
So in order to do that, let me show you one more use case.
For example, in lecture, when a new user connecting to the client, I want to send a message for other
the client will be the new user had join into the chat application.
Okay, I want to send a simple message like that.
Well, in order to do that right now, inside the connection okay, I will send the socket.
Okay.
In order emit.
Send message for all clients
Except myself.
In order to do that, we will use the socket okay.
And we have a broadcast.
And right here we can emit event as normal.
Okay.
For example right here will be new user.
And right here I will use a new user has been joined.
To the application.
Okay I will send a message like that inside the script over here.
We will listening on that.
Okay.
And in this case I will create a p element and I will append that also let me copy.
Right here p element create and text content.
In here I will use the.
message directly, because this is just a string
Okay, so for that reason, the message right here will be also the string.
And let me show you like I will refresh.
Now we don't see anything in the client right now I will connect.
We will not see anything.
But if I go back to the first client, you can see it will console.log a new user has been joined into
this application.
Very very cool.
Right?
Let me create another client.
This client will not have anything.
But right here you can see it has a console log, right.
It has some text okay.
That's about the broadcasting event.
So I hope you understand this video and I will see you in the next one.