const url = 'wss://client-terminal-0f1fe89209a8.hosted.ghaymah.systems/ws'; async function run() { console.log('Connecting to ttyd WebSocket at', url); const ws = new WebSocket(url, ['tty']); let output = ''; ws.onopen = () => { console.log('WebSocket connected!'); // 1. Send auth token ws.send(JSON.stringify({ AuthToken: '' })); // 2. Send resize ws.send('1' + JSON.stringify({ columns: 120, rows: 40 })); // 3. Send command after brief delay setTimeout(() => { console.log('Sending command: id && ip addr && cat /etc/resolv.conf'); ws.send('0' + 'id && ip addr && cat /etc/resolv.conf\n'); }, 500); // 4. Close after collecting output setTimeout(() => { console.log('=== COLLECTED TERMINAL OUTPUT ==='); console.log(output); ws.close(); process.exit(0); }, 3500); }; ws.onmessage = async (event) => { let data; if (event.data instanceof Blob) { data = await event.data.text(); } else if (typeof event.data === 'string') { data = event.data; } else { data = Buffer.from(event.data).toString('utf8'); } // Remove ttyd command byte if present if (data.startsWith('0')) data = data.substring(1); output += data; }; ws.onerror = (err) => console.error('WS error:', err); ws.onclose = (e) => console.log('WS closed:', e.code, e.reason); } run().catch(console.error);