admin管理员组文章数量:1336728
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}`)
}
})
本文标签: Socketio detect websocket transport close codeStack Overflow
版权声明:本文标题:Socket.io detect websocket transport close code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742402199a2468110.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论