diff --git a/docs/IM-前后端对接文档.md b/docs/IM-前后端对接文档.md index 65541e1..ee4992f 100644 --- a/docs/IM-前后端对接文档.md +++ b/docs/IM-前后端对接文档.md @@ -240,7 +240,7 @@ WebSocket Upgrade 阶段由 `server/hdl_websock.go` 先调用 `checkAPIKey`。 ##### 0.5.1.1 WebSocket 心跳与在线状态 -当前 IM 长连接心跳使用 WebSocket 协议层 Ping/Pong,不使用业务 JSON 消息做保活。服务端每 30 秒发送一次 WebSocket Ping 帧(`pingPeriod=30s`),并期望客户端在 45 秒读超时窗口内返回 Pong(`idleSessionTimeout=45s`);如果没有收到 Pong,或底层读写失败,服务端会关闭当前 Session。 +当前 IM 长连接心跳使用 WebSocket 协议层 Ping/Pong,不使用业务 JSON 消息做保活。服务端每 15 秒发送一次 WebSocket Ping 帧(`pingPeriod=15s`),并期望客户端在 45 秒读超时窗口内返回 Pong(`idleSessionTimeout=45s`);如果没有收到 Pong,或底层读写失败,服务端会关闭当前 Session。 客户端要求: diff --git a/docs/MESSAGE-PROTOCOL.md b/docs/MESSAGE-PROTOCOL.md index c07ebd9..842e778 100644 --- a/docs/MESSAGE-PROTOCOL.md +++ b/docs/MESSAGE-PROTOCOL.md @@ -41,7 +41,7 @@ ServerComMessage 2. `sess.bkgTimer` — 后台超时定时器 3. `sess.stop` — 停止信号 4. `sess.detach` — 取消订阅 -5. `ticker` — Ping 帧(每 30s 发送一次) +5. `ticker` — Ping 帧(每 15s 发送一次) ### Keep-Alive @@ -49,7 +49,7 @@ ServerComMessage |------|-----|------| | `writeWait` | 10s | 写超时 | | `pongWait` | `idleSessionTimeout` | 期望收到 Pong 的时间(当前默认 45s) | -| `pingPeriod` | 30s | WebSocket Ping 间隔 | +| `pingPeriod` | 15s | WebSocket Ping 间隔 | | 心跳探测 | WebSocket Ping/Pong | 当前 IM 长连接保活以协议层 Ping/Pong 为准;业务 `note kp/kpa/kpv` 不能替代 Pong | ### 缓冲区设置 diff --git a/docs/PROTOCOLS.md b/docs/PROTOCOLS.md index cd07d37..776f6b9 100644 --- a/docs/PROTOCOLS.md +++ b/docs/PROTOCOLS.md @@ -174,8 +174,8 @@ Tinode 的心跳配置: ```go const ( writeWait = 10 * time.Second // 写操作超时 - pongWait = idleSessionTimeout // 等待 Pong 超时(默认 60 秒) - pingPeriod = (pongWait * 9) / 10 // 发送 Ping 周期(54 秒) + pongWait = idleSessionTimeout // 等待 Pong 超时(默认 45 秒) + pingPeriod = 15 * time.Second // 发送 Ping 周期(15 秒) ) ``` @@ -190,7 +190,7 @@ const ( │ ┌─────────────────────────────────────────────────────────────────────┐ │ │ │ for { │ │ │ │ select { │ │ -│ │ case <-ticker.C: // 每 54 秒 │ │ +│ │ case <-ticker.C: // 每 15 秒 │ │ │ │ ws.WriteMessage(PingMessage, nil) // 发送 Ping │ │ │ │ case msg <- sess.send: // 有消息待发送 │ │ │ │ ws.WriteMessage(TextMessage, msg) // 发送消息 │ │ @@ -554,8 +554,8 @@ func (sess *Session) writeLoop() { | 参数 | 值 | 说明 | |------|-----|------| | `writeWait` | 10秒 | 写操作超时 | -| `pongWait` | 配置项 | 等待 Pong 超时(默认 60 秒) | -| `pingPeriod` | `pongWait * 0.9` | 发送 Ping 周期 | +| `pongWait` | `idleSessionTimeout` | 等待 Pong 超时(默认 45 秒) | +| `pingPeriod` | 15 秒 | 发送 Ping 周期 | ### 消息格式 @@ -1290,7 +1290,7 @@ func largeFileRunGarbageCollection(period time.Duration, blockSize int) chan<- b "listen": ":6060", "grpc_listen": ":16060", "max_message_size": 262144, - "idle_session_timeout": 60000, + "idle_session_timeout": 45000, "ws_compression": true, "api_key_salt": "your-hmac-salt", @@ -1350,4 +1350,4 @@ curl "http://localhost:6060/v0/channels/lp?sid=SESSION_ID" | `pbx/model.proto` | gRPC 协议定义 | | `server/http.go` | HTTP 服务器 | | `server/session.go` | 会话管理 | -| `server/datamodel.go` | 消息结构定义 | \ No newline at end of file +| `server/datamodel.go` | 消息结构定义 | diff --git a/server/hdl_websock.go b/server/hdl_websock.go index c55cc03..7ead35a 100644 --- a/server/hdl_websock.go +++ b/server/hdl_websock.go @@ -28,7 +28,7 @@ const ( pongWait = idleSessionTimeout // Send pings to peer with this period. Must be less than pongWait. - pingPeriod = 30 * time.Second + pingPeriod = 15 * time.Second ) func (sess *Session) closeWS() {