0

Javascript keep appending on page reaload with websocket connection

I have an apl with chat using python and websockets. If user successfully authenticate his/her status in the database turns online. Database query collects the online status users every minutes and send a message to front end where I want to update the list from the websocket message. everything works fine until I log in with another account from a different browser. The first window keep appending the names not matter which browser I refresh this is happening only with the first opened browser window/tab. Any ideas how to collect data and append to front end with vanilla js and keep the data until its changes in the database so the new authenticated user append to list and every online members show up in the sidebar properly. Like the messenger sidebar. If you could please help. I appreciate

7th Aug 2020, 5:34 PM
_] | [\]
_] | [\] - avatar
4 Respuestas
+ 5
Why not refresh the whole local userlist array so it is always in sync with the backend userlist array? P. S. I downvoted your question to discourage you from self-upvoting.
7th Aug 2020, 5:46 PM
Gordon
Gordon - avatar
+ 2
You'll need to set a timer, say every 3 minutes or so, performs check on the activity of the users, and kicks the idle ones.
7th Aug 2020, 6:04 PM
Gordon
Gordon - avatar
+ 1
thanks! currently have 190 users in database and only around 20 online at the same time JS appends the list same with the whole array so the sidebar grows quickly 😂
7th Aug 2020, 5:49 PM
_] | [\]
_] | [\] - avatar
0
the trick was to make query to online status users from database save them in a list with variable like _last_online and after 1minute it creates a new variable _current_online and compare them to a set() do it always eleminating the duplicates it is not the best but working on the development server
12th Aug 2020, 6:23 AM
_] | [\]
_] | [\] - avatar