Client side
In the previous section, we covered how to set up the web socket on the server side and how to handle the event from the client side.
Now we will see how to set up your client side, in order to use the Nest.js IoAdapter
or our custom WsAdapter
. In order to use the IoAdapter
, we have to get the socket.io-client
library and set up our first HTML file.
The file will define a simple script to connect the socket to the server with the token of the logged in user. This token we will be used to determine if the user is well connected or not.
Check out the following code:
<
script
>
const
socket
=
io
(
'http://localhost:3000'
,
{
query
:
'auth_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJlbWFpbCI6InRlc3QzQHRlc3QuZnIiLCJpYXQiOjE1MjQ5NDk3NTgs
ImV4cCI6MTUyNDk1MzM1OH0.QH_jhOWKockuV-w-vIKMgT_eLJb3dp6a
ByDbMvEY5xc'
});
<
/script>
As you see, we pass at the socket connection a token auth_token
into the query parameter...