最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Socket.io detect websocket transport close code - Stack Overflow

programmeradmin1浏览0评论

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}`)
  }
})
发布评论

评论列表(0)

  1. 暂无评论