angularwebsocketseparation-of-concernscode-separation

Where the best place to put a websocket connector. Angular


I have a private websocket, this websocket brings me information about the user like balance, notification and other things. all application needs to use this websocket. I have a component where I connected in this websocket and i created an emitter to broadcast when a new message is received. example: websocket component receive message and emitter a event to component x.

Is this the best way to implement this?

I`m using angular 6 to build this application.


Solution

  • As I know that's like the best way, put the websocket in a common componente that the application uses.

    Just take care about the information that you use in that websocket, I mean just emmit the information that you need, when your application has a lot of websockets, it could crash, it will depends on how you handle the websockets, if you are emmiting that just to the user that should receive that, if you send just the information that you need, if you don't make not necessary websockets calls.