fix: 增强后端Socket连接诊断日志
- connection事件记录远程IP/传输方式/是否携带auth token - Web客户端注册记录请求来源IP,便于排查连接问题
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"savedAt": "2026-02-14T07:46:12.968Z",
|
||||
"savedAt": "2026-02-15T07:13:12.135Z",
|
||||
"users": [
|
||||
{
|
||||
"id": "admin_1762534368537",
|
||||
@@ -16,7 +16,7 @@
|
||||
"passwordHash": "$2b$10$3c/70RbBH4y7zhYwxk8ldOcls3Bj6kt3cSMidTeaMUVb1EJXH4GMy",
|
||||
"role": "superadmin",
|
||||
"createdAt": "2025-11-07T16:53:46.677Z",
|
||||
"lastLoginAt": "2026-02-14T07:46:12.968Z"
|
||||
"lastLoginAt": "2026-02-15T07:13:12.135Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
devices.db
BIN
devices.db
Binary file not shown.
@@ -1171,7 +1171,10 @@ class RemoteControlServer {
|
||||
|
||||
private setupSocketHandlers(): void {
|
||||
this.io.on('connection', (socket: any) => {
|
||||
this.logger.info(`新连接建立: ${socket.id} (传输: ${socket.conn.transport.name})`)
|
||||
const remoteAddr = socket.handshake?.address || 'unknown'
|
||||
const transport = socket.conn?.transport?.name || 'unknown'
|
||||
const hasAuth = !!socket.handshake?.auth?.token
|
||||
this.logger.info(`[Conn] New connection: ${socket.id} (transport: ${transport}, ip: ${remoteAddr}, hasAuth: ${hasAuth})`)
|
||||
|
||||
// 🔧 移除强制认证检查 - 让设备端可以正常连接,认证只在web客户端注册时进行
|
||||
// 🔧 增强连接监控,帮助诊断误断开问题
|
||||
@@ -1661,7 +1664,9 @@ class RemoteControlServer {
|
||||
*/
|
||||
private handleWebClientRegister(socket: any, data: any): void {
|
||||
try {
|
||||
// 🔐 Web客户端认证验证:检查认证token
|
||||
this.logger.info(`[WebClient] Register request from ${socket.id} (ip: ${socket.handshake?.address || 'unknown'})`)
|
||||
|
||||
// Web client auth: check token
|
||||
const token = socket.handshake.auth?.token
|
||||
if (!token) {
|
||||
this.logger.warn(`🔐 Web客户端注册缺少认证token: ${socket.id}`)
|
||||
|
||||
Reference in New Issue
Block a user