I ran into a situation where I need to leave the connection open if the user pressed F5 in the browser, disconnect
should work only if for example the user closed the tab or browser. This is necessary, for example, if a person visits the site, and when connecting a socket, I notify everyone who is online that such and such a user has logged on to the site. In the standard situation, each time the page is refreshed, the connection
event will be triggered and will notify everyone who is online each time.
How to solve this problem?
PS As an option, you can consider this example .
But, I do not really like this approach, although you can set the timer to disconnect
, and when connecting, check in the array with authorized clients, is there such a sessid, and if there is, then do not do the actions in connection
.
But, for some reason, I believe that there are more interesting solutions to the problem. I ask local gurus to unsubscribe about this)