With a server using Socket.IO 4.7.5, I'd like to be able to log per-client the underlying transport connection close code whenever we receive "transport close" as the Socket.IO reason for disconnect. I'm looking to answer "Why did the transport close?" For example, if we have a SocketIO connection over Websocket, I'd like to log the WebSocket close code.
The following code is based on the Socket.IO examples, but perhaps the details parameter is only populated for the Socket.IO client?
socket.on("disconnect", async (reason, details) => {
consoleLog.printLog(source, logOverride, `Socket Disconnect Reason: => ${reason} sid: ${socket.id}`)
if (details) {
// This is never hit
consoleLog.printLog(source, logOverride, `Socket Disconnect Message: => ${details.message} sid: ${socket.id}`)
consoleLog.printLog(source, logOverride, `Socket Disconnect Context: => ${details.context} sid: ${socket.id}`)
consoleLog.printLog(source, logOverride, `Socket Disconnect Description: => ${details.description} sid: ${socket.id}`)
} else {
consoleLog.printLog(source, logOverride, `Socket Disconnect 'details' argument is not available: ${socket.id}`)
}
})