fix: ot terminal
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
export let connected = false;
|
export let connected = false;
|
||||||
export let connecting = false;
|
export let connecting = false;
|
||||||
let resizeObserver: ResizeObserver | null = null;
|
let resizeObserver: ResizeObserver | null = null;
|
||||||
|
let pingInterval: ReturnType<typeof setInterval> | null = null;
|
||||||
|
|
||||||
// Resolve the active terminal server's info for the WebSocket URL
|
// Resolve the active terminal server's info for the WebSocket URL
|
||||||
const getTerminalInfo = (): { serverId: string; baseUrl: string } | null => {
|
const getTerminalInfo = (): { serverId: string; baseUrl: string } | null => {
|
||||||
@@ -108,6 +109,13 @@
|
|||||||
if (term && ws) {
|
if (term && ws) {
|
||||||
ws.send(JSON.stringify({ type: 'resize', cols: term.cols, rows: term.rows }));
|
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) => {
|
ws.onmessage = (event) => {
|
||||||
@@ -141,6 +149,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const disconnect = () => {
|
const disconnect = () => {
|
||||||
|
if (pingInterval) {
|
||||||
|
clearInterval(pingInterval);
|
||||||
|
pingInterval = null;
|
||||||
|
}
|
||||||
if (ws) {
|
if (ws) {
|
||||||
ws.close();
|
ws.close();
|
||||||
ws = null;
|
ws = null;
|
||||||
@@ -229,8 +241,10 @@
|
|||||||
});
|
});
|
||||||
resizeObserver.observe(terminalEl);
|
resizeObserver.observe(terminalEl);
|
||||||
|
|
||||||
// Auto-connect
|
// Connection is handled by the reactive block below (which fires
|
||||||
connect();
|
// 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
|
// Reconnect when the selected terminal changes
|
||||||
|
|||||||
Reference in New Issue
Block a user