Javascript keep appending on page reaload with websocket connection | Sololearn: Learn to code for FREE!

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

8/7/2020 5:34:54 PM

_] | [\]

4 Answers

New Answer

+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.

+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.

+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 😂

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