@yeaft/webchat-agent 0.0.28 → 0.0.30

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/connection.js +9 -12
  2. package/package.json +1 -1
package/connection.js CHANGED
@@ -95,16 +95,6 @@ async function parseMessage(data) {
95
95
 
96
96
  async function handleMessage(msg) {
97
97
  switch (msg.type) {
98
- case 'ping':
99
- // 应用层心跳:server 发 ping,agent 回 pong
100
- sendToServer({ type: 'pong' });
101
- return;
102
-
103
- case 'pong':
104
- // 应用层心跳响应:更新 lastPongAt
105
- ctx.lastPongAt = Date.now();
106
- return;
107
-
108
98
  case 'registered':
109
99
  if (msg.sessionKey) {
110
100
  ctx.sessionKey = decodeKey(msg.sessionKey);
@@ -486,6 +476,13 @@ export function startAgentHeartbeat() {
486
476
  stopAgentHeartbeat();
487
477
  ctx.lastPongAt = Date.now();
488
478
 
479
+ // 监听 pong 帧
480
+ if (ctx.ws) {
481
+ ctx.ws.on('pong', () => {
482
+ ctx.lastPongAt = Date.now();
483
+ });
484
+ }
485
+
489
486
  ctx.agentHeartbeatTimer = setInterval(() => {
490
487
  if (!ctx.ws || ctx.ws.readyState !== WebSocket.OPEN) return;
491
488
 
@@ -498,7 +495,7 @@ export function startAgentHeartbeat() {
498
495
  }
499
496
 
500
497
  try {
501
- sendToServer({ type: 'ping' });
498
+ ctx.ws.ping();
502
499
  } catch (e) {
503
500
  console.warn('[Heartbeat] Failed to send ping:', e.message);
504
501
  }
@@ -542,7 +539,7 @@ export function connect() {
542
539
  ctx.ws.on('open', () => {
543
540
  console.log('Connected to server, waiting for auth challenge...');
544
541
  clearTimeout(ctx.reconnectTimer);
545
- // 启动 agent 端心跳: 每 25 秒发一次应用层 ping
542
+ // 启动 agent 端心跳: 每 25 秒发一次 ping
546
543
  startAgentHeartbeat();
547
544
  });
548
545
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",