How do I update the amount of socket.io messages in an Angular Ionic3 app to a particular endpoint?

Asked

Viewed 67 times

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:

inserir a descrição da imagem aqui

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

  • Yeah, that’s what I want to do but I don’t know how.

1 answer

0


Next, why do they talk chat?

For the reason that it is basically required socket because the user needs to receive the information without the "refresh", another way you put a timer for it, more weighing otherwise, and a tremendous resource consumption maintain a timer, imagine this for a mobile? the battery chorraria... now why the socket? it makes the connection to the server and keeps it active listening all the time...

pq a chat and the simplest way to learn socket because in it vc can create one room for each page for admin/client or just admin and client and separate the pages by paginaInicial;0;0 and interpret this client side information....

follow there for you a basic socket in Ode with use of cookies for each time the customer opens a page he reuse the connection...

sorry for the Portuguese I am lazy to use introduction, methodology, conclusion

Basic socket

ah reading your post better you will have to rewrite that backend of yours in Ode or make a method of sending this info to the Node and it to return worked or that it just shoots it to all of the desired channel

that’s it, if you’re wrong someone can give a force there

Browser other questions tagged

You are not signed in. Login or sign up in order to post.