fix(sockets): probe_railgun.js WS 上行改异步读 Blob(此前 hex 恒为空)
游戏 send 的是 Blob,slice 后 new Uint8Array(Blob) 长度为 0,导致 SEND 行 hex 全空;改为 blob.arrayBuffer() 异步读前 24 字节。
This commit is contained in:
1 parent
46b6a1c412
commit
c17e408348
1 file changed
+15
-7
@@ -51,24 +51,32 @@
|
||||
if (Buf.length >= 40) flush();
|
||||
};
|
||||
|
||||
// ---- ③ WS 上行记录 ----
|
||||
// ---- ③ WS 上行记录(游戏发的是 Blob,必须异步读,否则 hex 恒为空)----
|
||||
var Hex = function (u) {
|
||||
var h = '';
|
||||
for (var i = 0; i < u.length; i++) h += (u[i] < 16 ? '0' : '') + u[i].toString(16);
|
||||
return h;
|
||||
};
|
||||
try {
|
||||
var W = window.WebSocket;
|
||||
if (W && W.prototype && !W.prototype.__probeWrapped__) {
|
||||
var Orig = W.prototype.send;
|
||||
W.prototype.send = function (d) {
|
||||
try {
|
||||
if (d && d.byteLength !== undefined) {
|
||||
var u = new Uint8Array(d.slice ? d.slice(0, 16) : d, 0, Math.min(16, d.byteLength));
|
||||
var h = '';
|
||||
for (var i = 0; i < u.length; i++) h += (u[i] < 16 ? '0' : '') + u[i].toString(16);
|
||||
Buf.push('[+' + Now() + 'ms] SEND len=' + d.byteLength + ' hex=' + h);
|
||||
if (d instanceof Blob) {
|
||||
var size = d.size;
|
||||
d.slice(0, 24).arrayBuffer().then(function (ab) {
|
||||
Buf.push('[+' + Now() + 'ms] SEND blob len=' + size + ' hex=' + Hex(new Uint8Array(ab)));
|
||||
}).catch(function () {});
|
||||
} else if (d && d.byteLength !== undefined) {
|
||||
var u = new Uint8Array(d.slice ? d.slice(0, 24) : d, 0, Math.min(24, d.byteLength));
|
||||
Buf.push('[+' + Now() + 'ms] SEND len=' + d.byteLength + ' hex=' + Hex(u));
|
||||
}
|
||||
} catch (e) {}
|
||||
return Orig.apply(this, arguments);
|
||||
};
|
||||
W.prototype.__probeWrapped__ = true;
|
||||
Buf.push('WS send 已挂(记帧长+前16字节)');
|
||||
Buf.push('WS send 已挂(Blob 异步读,记前 24 字节)');
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user