Socket.io detect websocket transport close code - Stack Overflow

With a server using Socket.IO 4.7.5, I'd like to be able to log per-client the underlying transpor

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}`)
  }
})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742402200a4437137.html

相关推荐

  • Socket.io detect websocket transport close code - Stack Overflow

    With a server using Socket.IO 4.7.5, I'd like to be able to log per-client the underlying transpor

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信