B
B
Banan442020-05-29 21:51:48
JavaScript
Banan44, 2020-05-29 21:51:48

How not to disconnect the user after reloading the socket io page?

I am writing a chat using the socket io library. The disconnect event fires when the page is reloaded, thus disconnecting the user from the chat. I don't want to do this, I want the user to disconnect only after closing the tab or browser window. The first thing that came to mind was to use sessionStorage, setTimeout, but how to implement it as competently as possible? Maybe in the library itself there is something to simplify the task?
disconnect sends a message to all participants in the conversation (room) that the user has disconnected

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
p3trukh1n, 2020-05-29
@Banan44

It will not work to remove the sending of the disconnect during the disconnect itself.
Alternatively, you can do this:
The server receives a disconnect, waits for some time (for example, 10 seconds), and if the user has not reconnected during this time (the socket id changes, do not forget), then sends a message to all users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question