In this part, we are going to a prayer, the service, I quote, such that you said, go to this page,
enjoy the chat room inside the service side.
So first we are going to create a helper functions in the server.
So we go back to the surface side and under the server folder, we create a helper.
Yes.
And inside the server.
Inside these Ultragaz we are going to create that uses a raid, and initially this is empty.
And then we are going to create a at USA functions, which is equal to.
Socket IP, because we are going to pass the socket IP, the user name, the user IP and also the IP.
So for us, we are going to check whether the user already exists in this room.
So we create a constant and then we are going to use the user to find and then to use it and then to
find out the user thought, well, ID is equal, equal to the ID that we passed to these functions.
And the user thought user ID use ICO to do with the idea that we pass to these functions.
So the first thing is if we are going to return to error and the error is the user already sees in this
role, if not exist, we are going to create the user of the topic that we passed in, including the
socket ID and name the user ID and also the room ID.
Not we create the user are going to push the user user list and then we are going to we turned to use
the user object, but since they are the same name, they're going to just simply use we turn user and
at last we are going to exploit this by using more exports is equal to act it, and now we just create
one helper functions.
So actually what we do here is there is a user list here.
If there is a new user like this name is drawn and the user is one to fee and the rheumatiz one to a
fee, and if the function see that is already exists, then it will return to Earth.
Otherwise it will happen to this array.
So we delete this and we back to the index.
And first we are going to import these helper functions and then we create content that user is equal
to require helper.
And then here we are going to descend the joint U.
N When the user joins these chat room, we are going to post name and the room ID and also the user
ID and then it will be turned to Iraq and or the user if we are going to add user.
So we have the property of socket IP, which is equal to the socket ID and the name.
And since the name property and the where they are using the same path or the same string.
So we just use one word, only part of the named name.
And then also this is the same, we just use my ID and also they do the IP.
So we are going to check if there's no error, if there's error and we are going to load the joint or
else load the joint user and then display the user.
So now we are going to add a kind of side to impeach the joint event.
So we back to the chat and first, like home, we are going to import the eye of the socket.
I'll change and also add that to the socket.
And also we have to import the endpoint.
And also, we have to use that, in fact.
So now here we use to use effort and we are going to image first we are going to create a socket and
then we use to emit and then we pass the name, which is the user name here and the room ID maybe we
have to delete it and put it under the ID so it will have the bomb ID first and also the user I.D. equal
to a user I.D..
So I think we already said all the things and we can tried to enter the chat room.
I think to make it more clear we should go to the help function and then we can also download the user
these and then we display the users here and then we stop the server and then we.
We stopped the surfer because we just want to clear the U.S. at least so now we sent Astron and then
we go to Rome one and then we go to another Browsr and ask Tom and also go to Rome one.
Now you can see the user list has gone and also, Tom.
Now, if we open one more user and then we ask John again and go to one one now you can see there is
an error.
The user already exists in this room.
So this already works.