Hi everyone.
Let's continue with the room.
Okay.
So what we will do next right here, after we join room successfully, we want to send a message into particular
room.
And of course in another client.
If we're not there, we will not see this message okay.
We will build that application.
Let me show you how we can build that.
Firstly, let's think about that a little bit.
The input right here will be for send message.
Right.
It means right now we should somehow modify the code inside the send message.
So we see over here right now I will check.
Check
We join room or not okay.
We need to check that, in order to check whether or not we can based on this.
h2 over here.
Okay.
If it's empty, we will send the message into the global chat application.
But if it have a room, we will send that into a particular room.
Let me show you how we can do that right here.
We will check if the room element dot text content if it have any value.
We need to send the message okay.
If and if not we will send inside the global message.
Okay.
And this here will be for room.
Well in order to send room I will create another emit event will be send private message.
Okay I will.
Actually send room message.
Right.
And, we will put the object similar.
Username and message also inside the server.js.
Right here I will listening.
Send message.
And right here we have a message also.
Right here.
In order to send a message to all client connect into the particular room we will use io.to
And right here inside the "to" we will specify the room name will be the, actually right here,
we should put one more thing will be room
Room element dot text content
And inside the server right here, inside the message, we will have a room name.
Right.
Let's see actually only the room
We will send the message into all connections.
Connect into particular room and we will emit as usual
We can change the event like that way
Okay.
And right here I will send back the same event for the client.
will be the message also, similar like that okay.
Only this thing will be different.
And inside the Script.js we will listening also.
Send room message and create element, put directly over here.
So let's see.
I will refresh and maybe I don't need this thing, I think I will remove the event broadcast event over here.
Okay.
Let me remove that.
New user.
And let's see I will refresh, firstly.
I will join a room with friends.
Right now.
I will say hi and send, now you can see in here we don't have any event.
But when we join a room, we join a room.
And right here I will send another thing.
Now you will see right here.
We already got the new message.
Very very cool.
Right.
And of course, right now we can send back the event.
Now.
Very cool.
Right.
It's already work as we expected.
And right here we have a lot of duplication.
Okay.
You can create a separate function to reduce duplicates also.
Okay.
So I think that will be enough for the video.
I will see you in the next one.