In order to switch communication protocol from HTTP to WebSocket we need to implement a "handshake". Handshake is HTTP request with certain headers which tells the server that we want to connect to it via WebSocket protocol in order to keep further communication upon it.
But the server needs to authorize anyone who wants to connect to it by WebSocket. Therefore the client needs a secret key which will be attached to handshake.
In order to get this secret key the login mechanism is supposed to use HTTP request. After we authorize with login, we get a secret key in response. This key must be used in the "handshake" to let the server know that we have rights for it.
After successful "handshake" we are ready to emit and receive messages.