fix: ot terminal

This commit is contained in:
Timothy Jaeryang Baek
2026-03-02 19:09:13 -06:00
parent 10daa64d5b
commit ca2aaf0321

View File

@@ -20,6 +20,7 @@
export let connected = false;
export let connecting = false;
let resizeObserver: ResizeObserver | null = null;
let pingInterval: ReturnType<typeof setInterval> | null = null;
// Resolve the active terminal server's info for the WebSocket URL
const getTerminalInfo = (): { serverId: string; baseUrl: string } | null => {
@@ -108,6 +109,13 @@
if (term && ws) {
ws.send(JSON.stringify({ type: 'resize', cols: term.cols, rows: term.rows }));
}
// Keepalive ping to prevent idle timeout from proxies/LBs
if (pingInterval) clearInterval(pingInterval);
pingInterval = setInterval(() => {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'ping' }));
}
}, 25000);
};
ws.onmessage = (event) => {
@@ -141,6 +149,10 @@
};
const disconnect = () => {
if (pingInterval) {
clearInterval(pingInterval);
pingInterval = null;
}
if (ws) {
ws.close();
ws = null;
@@ -229,8 +241,10 @@
});
resizeObserver.observe(terminalEl);
// Auto-connect
connect();
// Connection is handled by the reactive block below (which fires
// when `term` is set here), so we intentionally do NOT call
// connect() to avoid creating a duplicate WebSocket whose onclose
// handler would write a spurious "[Connection closed]" message.
};
// Reconnect when the selected terminal changes