77 lines
2.3 KiB
HTML
77 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head><title>WS Debug</title></head>
|
|
<body>
|
|
<h2>XCU WebSocket Debug</h2>
|
|
<div id="log" style="font-family:monospace;white-space:pre;font-size:12px;max-height:80vh;overflow:auto;background:#111;color:#0f0;padding:10px;"></div>
|
|
<script>
|
|
const log = (msg) => {
|
|
const el = document.getElementById('log');
|
|
const time = new Date().toISOString().substr(11,12);
|
|
el.textContent += `[${time}] ${msg}\n`;
|
|
el.scrollTop = el.scrollHeight;
|
|
};
|
|
|
|
const roomName = 'JMP-C9DF-40CD';
|
|
const wsUrl = `wss://${window.location.host}/ws/${roomName}`;
|
|
log(`Connecting to: ${wsUrl}`);
|
|
|
|
const ws = new WebSocket(wsUrl);
|
|
ws.binaryType = 'arraybuffer';
|
|
|
|
const myId = Math.floor(Math.random() * 65534) + 1;
|
|
log(`My participant ID: ${myId}`);
|
|
|
|
ws.onopen = () => {
|
|
log('WebSocket OPEN');
|
|
// Send heartbeat every 2s
|
|
setInterval(() => {
|
|
if (ws.readyState === WebSocket.OPEN) {
|
|
const hb = new Uint8Array(8);
|
|
hb[0] = 5; // heartbeat
|
|
const v = new DataView(hb.buffer);
|
|
v.setUint16(2, myId, true);
|
|
v.setUint32(4, 0, true);
|
|
ws.send(hb);
|
|
}
|
|
}, 2000);
|
|
};
|
|
|
|
ws.onerror = (e) => log(`WebSocket ERROR: ${JSON.stringify(e)}`);
|
|
ws.onclose = (e) => log(`WebSocket CLOSED: code=${e.code} reason=${e.reason}`);
|
|
|
|
let frameCount = 0;
|
|
let myFrames = 0;
|
|
let otherFrames = 0;
|
|
const senders = new Set();
|
|
|
|
ws.onmessage = (event) => {
|
|
if (event.data instanceof ArrayBuffer) {
|
|
const arr = new Uint8Array(event.data);
|
|
if (arr.length >= 8) {
|
|
const type = arr[0];
|
|
const quality = arr[1];
|
|
const dv = new DataView(event.data);
|
|
const senderId = dv.getUint16(2, true);
|
|
const payloadLen = dv.getUint32(4, true);
|
|
|
|
if (senderId === myId) {
|
|
myFrames++;
|
|
} else {
|
|
otherFrames++;
|
|
senders.add(senderId);
|
|
}
|
|
frameCount++;
|
|
|
|
if (frameCount % 30 === 0 || type === 5 || otherFrames <= 3) {
|
|
log(`FRAME #${frameCount} | type=${type} quality=${quality} sender=${senderId} payloadLen=${payloadLen} totalBytes=${arr.length} | MY=${myFrames} OTHER=${otherFrames} senders=[${[...senders].join(',')}]`);
|
|
}
|
|
}
|
|
} else {
|
|
log(`TEXT: ${event.data}`);
|
|
}
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|