Socket IO's disconnect event is fired internally but you can emit a custom event when it is called.
You need to first listen for the disconnect event. Once this event has been called, you should then emit your own custom event say we call it myCustomEvent
Once this event has been called, your client should then be listening out for your myCustomEvent
and on hearing it, should then output the data you passed it. For example:
io.sockets.on('connection', function (socket) {
const _id = socket.id
console.log('Socket Connected: ' + _id)
// Here we emit our custom event
socket.on('disconnect', () => {
io.emit('myCustomEvent', {customEvent: 'Custom Message'})
console.log('Socket disconnected: ' + _id)
})
})
Your client would then listen for myCustomEvent
like so
socket.on('myCustomEvent', (data) => {
console.log(data)
})
I hope this helps :)