Migrate client to TCP-only streaming and add diagnostics
This commit is contained in:
parent
d7ae409846
commit
b3f5902c44
2 changed files with 147 additions and 178 deletions
75
scripts/test-network.js
Normal file
75
scripts/test-network.js
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
const WebSocket = require('ws');
|
||||
|
||||
const SERVER = process.argv[2] || 'wss://meet.srtk.in/ws';
|
||||
const ROOM = 'diag-test';
|
||||
const NAME = 'diag-bot-' + Math.floor(Math.random() * 1000);
|
||||
|
||||
console.log(`--- Network Diagnostic Tool ---`);
|
||||
console.log(`Connecting to: ${SERVER}`);
|
||||
console.log(`Room: ${ROOM}, Identity: ${NAME}`);
|
||||
|
||||
const url = `${SERVER}?room=${ROOM}&name=${NAME}`;
|
||||
const ws = new WebSocket(url);
|
||||
|
||||
let startTime = Date.now();
|
||||
let textPings = 0;
|
||||
let binaryPings = 0;
|
||||
let textAcks = 0;
|
||||
let binaryAcks = 0;
|
||||
|
||||
ws.on('open', () => {
|
||||
console.log('✅ WebSocket Connected');
|
||||
|
||||
// 1. Join
|
||||
ws.send(JSON.stringify({
|
||||
type: 'Join',
|
||||
data: { room_code: ROOM, display_name: NAME }
|
||||
}));
|
||||
|
||||
// 2. Start Test Cycle
|
||||
setInterval(() => {
|
||||
// Send Text Ping
|
||||
ws.send(JSON.stringify({ type: 'Heartbeat' }));
|
||||
textPings++;
|
||||
|
||||
// Send Binary Ping (1KB)
|
||||
const dummy = Buffer.alloc(1024);
|
||||
dummy[0] = 0xAA; // Diagnostic marker
|
||||
ws.send(dummy);
|
||||
binaryPings++;
|
||||
|
||||
console.log(`Stats: TX[Text:${textPings}, Bin:${binaryPings}] RX[Text:${textAcks}, Bin:${binaryAcks}]`);
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
ws.on('message', (data, isBinary) => {
|
||||
if (isBinary) {
|
||||
binaryAcks++;
|
||||
} else {
|
||||
try {
|
||||
const msg = JSON.parse(data.toString());
|
||||
if (msg.type === 'Heartbeat') {
|
||||
textAcks++;
|
||||
} else if (msg.type === 'Joined') {
|
||||
console.log('✅ Joined successfully! Self ID:', msg.data.self_id);
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
});
|
||||
|
||||
ws.on('error', (err) => {
|
||||
console.error('❌ WebSocket Error:', err.message);
|
||||
});
|
||||
|
||||
ws.on('close', (code, reason) => {
|
||||
console.log(`⚠️ Connection Closed (Code: ${code}, Reason: ${reason})`);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('--- Test Finished ---');
|
||||
console.log(`Summary:`);
|
||||
console.log(`Text Pings: ${textPings}, Acks: ${textAcks} (${Math.round(textAcks / textPings * 100)}%)`);
|
||||
console.log(`Binary Pings: ${binaryPings}, Acks: ${binaryAcks} (${Math.round(binaryAcks / binaryPings * 100)}%)`);
|
||||
process.exit(0);
|
||||
}, 20000);
|
||||
Loading…
Add table
Add a link
Reference in a new issue