mercredi 26 juillet 2023

Should i send socketmessages directly from client or go my through restapi-server?

I have my frontend mobile-application and my backend. I am building a chat-application and I wonder how I should structure my socketmessages. For example is a user sends a message, I call my backend to create the message in the database, but right now my backend will also send a socketmessage to my socketserver which will broadcast it to the user I sent the message to. I wonder, is it better to send the message to the socketserver directly from the frontend, so the frontend basically does two things when sending a message, calling my backend to create the message in db, and then also calling the socket to broadcast the message? Same goes for "isTyping"-state. For me it makes sense to not go via https and just directly send it to the socket, but what if I would like to also send a notification when user is typing, then it would make more sense to call the backend and let it send the info to the socketserver.

Aucun commentaire:

Enregistrer un commentaire