I notice that socket.on('disconnect') fires immediately when I close browser tab. But it fires approximately in a minute after internet connection dies. I'm using socket.io module. How can I fix this issue?
You have to use pingTimeout and pingInterval options on the server side to control this:
const io = require('socket.io').listen(server, {
pingTimeout: 5000,
pingInterval: 10000
});
pingTimeout (Number): how many ms without a pong packet to consider the connection closed (5000)pingInterval (Number): how many ms before sending a new ping packet (25000)More details about params: https://github.com/socketio/engine.io#methods-1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With