There is a chat that runs on sockets, all sockets are in an array. Need an idea for the implementation, example: the user sits in a chat and receives all messages. As soon as he switched to another tab, or turned off the browser altogether, the messages stop coming to him as soon as he returned to the chat - messages come ...

    1 answer 1

    document.addEventListener('visibilitychange', function (e) { if (document.hidden) { socket.message('away', {hidden: true}); } }, false); 

    And on the server to catch the event away. And how on the server we will not help to realize without an example of a code.

    • I understand the event occurs after switching to another tab. If so, then what to do with this event on the server? - skillful
    • I wrote. Until you send a notification to the server, it will not know about it. - yarkov_aleksei
    • @yarkov_aleksei I apologize, do not tell me which event should trigger when the page first loads? - HunterNomad