Socket.io and right disconnect



  • I ran into a situation where I need to leave the connection open if the laser pressed the F5 in the browser, disconnect must only work if the laser, for example, closed the deposit or the browser. It's necessary, for example, if a man walks into the site, and at the juket conject, I notify everyone online that such a camper has entered the site. In the standard situation, every update of the page will make an event connectionand will notify everyone online every time.

    How do you do that?

    P. S. How to consider https://stackoverflow.com/questions/20260170/handle-browser-reload-socket-io ♪

    But I don't really like this approach, though you can put a timer on. disconnectand in the case of a condect, check in a mass with authorised customers whether there's a sessid like that, and if there is, don't do what's in it. connection

    But I somehow believe that there are more interesting options for the task. Please write off the local guru on this issue.



    1. The front goes every X seconds to the ping server that he's online. Online is checked on the front (the mouse movement in the window, etc.)
    2. Every open deposit sends such a ping.
    3. If there's no ping anywhere from XX seconds, you're making an offline user.
    4. As soon as the user makes any action on the front, there's a ping on the server and you send all the messages that the user is online again.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2