From a83f2a5407f09b04d3a6f04da9e3c2d3bceffdfa Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 19 Oct 2026 22:36:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(ws-hook):=20=E6=8E=A7=E5=88=B6=E5=8F=B0?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E6=89=93=E5=8D=B0=E6=AF=8F=E4=B8=AA=20WebSoc?= =?UTF-8?q?ket=20=E7=9A=84=E5=9C=B0=E5=9D=80=E3=80=81=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=A0=81=E4=B8=8E=E5=AD=98=E6=B4=BB=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sockets/ws_hook.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sockets/ws_hook.js b/sockets/ws_hook.js index d98b221..ee8e01c 100644 --- a/sockets/ws_hook.js +++ b/sockets/ws_hook.js @@ -93,8 +93,17 @@ }); } WrapAccessor('onmessage', function (W, Ev) { Record(W, 's2c', Ev.data); }); - WrapAccessor('onopen', function (W) { Info(W).openTime = Date.now(); }); - WrapAccessor('onclose', function (W, Ev) { Info(W).closeCode = Ev && Ev.code; }); + WrapAccessor('onopen', function (W) { + var I = Info(W); + I.openTime = Date.now(); + // 直接在控制台可见:用来确认客户端有没有按服务端下发的 host/port 切换服务器 + console.log('[WS] 打开 ' + (I.url || '(未知)')); + }); + WrapAccessor('onclose', function (W, Ev) { + var I = Info(W); + I.closeCode = Ev && Ev.code; + console.log('[WS] 关闭 ' + (I.url || '(未知)') + ' code=' + I.closeCode + ' 存活=' + (I.openTime ? ((Date.now() - I.openTime) + 'ms') : '?')); + }); function Serialize() { return JSON.stringify({