websocket connection I am using the hashmap where key will be the userid and value will be the user socket channel
I want the user to connect the same account from multiple phones so when the user login again the socket channel gets replaced by the latest user login
How do I solve this issue
Isn’t hashmap a good idea to store the connection ? If not how do I store it.
What abput the other phones? How do they get the messages they are logged in for? When you do this, you are implementing an hidden one device rule that the few users with multiple devices confuse.
I want like how telegram does it When we logged in other phone we will get all messages
Telegram wakes up in the background and fetches messages. When the App is open there is an permanent connection for updates. If i have the desktop and tge phone app open, both get the updates, your approach would be that the latest approach gets the update. I would implement the server side in a way that there are two api-endpoint where updates are get: 1. An query for past messages, it returns all the messages past an point of time, for first logins and when an device was not online for a time, if its implemented so it can stream the data it can be implemented more responsive 2. An websocket based one that returns messages from an pub-sub system that saves messages before submitting incoming in an database for endpoint 1. I would implement the pub sub system that it uses groups for each chat/group and that each websocket connection subscribes to the groups. This way you can implement it with redudancy from the start.
Обсуждают сегодня