0
I want to implement an icon in a view that brings the amount of messages a user has in their box, but the update of quantity information should occur in real time according to the model below Facebook:
I have an endpoint of an API that brings the mailing list:
http://localhost:8080/clientes/mensagens/
To search this mailing list I created a service that runs perfectly:
buscarMensagens() : Observable<Mensagem[]> {
return this.http.get<Mensagem[]>(`${CONF_API.baseUrl}/clientes/mensagem/`);
}
Inside the view controller I created a variable that receives the amount of messages:
quantificarMensagens(){
this.mensagemService.buscarMensagens().subscribe(response => {
this.qtdMensagem = response.lenght();
})
It perfectly searches the amount of user messages.
The big problem here is that this does not happen dynamically, IE, when it arrives another message to the user the value does not update in real time, because it is necessary a new request.
Studying more deeply informed me that for this situation I must use the Socket, but the examples I found refers to creating a chat using such technology, and I could not understand how to apply this in my situation.
So I ask: How to use Socket to update in real time the amount of messages that arrive in the user’s box using this endpoint? http://localhost:8080/clientes/mensagens/
You are doing a get request and not connecting to the socket.io
– Eduardo Vargas
Yeah, that’s what I want to do but I don’t know how.
– Gonzaga Neto