@largezhou/ddingtalk 1.4.1 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/monitor.ts +19 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@largezhou/ddingtalk",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "OpenClaw DingTalk (钉钉) channel plugin",
5
5
  "main": "index.ts",
6
6
  "type": "module",
package/src/monitor.ts CHANGED
@@ -703,6 +703,25 @@ export function monitorDingTalkProvider(options: MonitorOptions): MonitorResult
703
703
  keepAlive: true,
704
704
  });
705
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
+
706
725
  // ============================================================================
707
726
  // 群聊策略与 Mention 门控
708
727
  // ============================================================================