@largezhou/ddingtalk 1.4.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/monitor.ts +23 -0
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -693,12 +693,35 @@ export function monitorDingTalkProvider(options: MonitorOptions): MonitorResult
|
|
|
693
693
|
});
|
|
694
694
|
|
|
695
695
|
// 创建钉钉 Stream 客户端
|
|
696
|
+
// keepAlive: true 启用 WebSocket ping/pong 心跳检测(每 8s),
|
|
697
|
+
// 当连接"半死不活"(TCP 未关闭但数据已无法传输)时能主动检测到并 terminate,
|
|
698
|
+
// 配合 autoReconnect(默认 true)触发自动重连,避免长时间静默断连。
|
|
696
699
|
const client = new DWClient({
|
|
697
700
|
clientId,
|
|
698
701
|
clientSecret,
|
|
699
702
|
debug: false,
|
|
703
|
+
keepAlive: true,
|
|
700
704
|
});
|
|
701
705
|
|
|
706
|
+
// ============================================================================
|
|
707
|
+
// 🔧 修复 dingtalk-stream SDK 的 keepAlive 重连 bug
|
|
708
|
+
// SDK 的 close 事件处理中没有 clearInterval(heartbeatIntervallId),
|
|
709
|
+
// 导致重连时旧的 heartbeat interval 还在运行,会 terminate 正在建立的新连接。
|
|
710
|
+
// 这里通过 monkey-patch _connect,在每次连接前先清理旧 interval。
|
|
711
|
+
// ============================================================================
|
|
712
|
+
const originalInternalConnect = (client as any)._connect.bind(client);
|
|
713
|
+
(client as any)._connect = function (this: any) {
|
|
714
|
+
// 清理上一轮的 heartbeat interval,防止它干扰新连接
|
|
715
|
+
if (this.heartbeatIntervallId !== undefined) {
|
|
716
|
+
clearInterval(this.heartbeatIntervallId);
|
|
717
|
+
this.heartbeatIntervallId = undefined;
|
|
718
|
+
logger.info('[PATCH] Cleared stale heartbeat interval before reconnect');
|
|
719
|
+
}
|
|
720
|
+
// 重置心跳状态,给新连接一个干净的起点
|
|
721
|
+
this.isAlive = false;
|
|
722
|
+
return originalInternalConnect();
|
|
723
|
+
};
|
|
724
|
+
|
|
702
725
|
// ============================================================================
|
|
703
726
|
// 群聊策略与 Mention 门控
|
|
704
727
|
// ============================================================================
|