Fix terminal WebSocket ready state checks

This commit is contained in:
Nathan Flurry 2026-03-07 17:44:24 -08:00
parent 9cca6e3e87
commit 8bf8319042

View file

@ -681,7 +681,7 @@ export class ProcessTerminalSession {
} }
close(): void { close(): void {
if (this.socket.readyState === WebSocket.CONNECTING) { if (this.socket.readyState === WS_READY_STATE_CONNECTING) {
this.socket.addEventListener( this.socket.addEventListener(
"open", "open",
() => { () => {
@ -692,7 +692,7 @@ export class ProcessTerminalSession {
return; return;
} }
if (this.socket.readyState === WebSocket.OPEN) { if (this.socket.readyState === WS_READY_STATE_OPEN) {
if (!this.closeSignalSent) { if (!this.closeSignalSent) {
this.closeSignalSent = true; this.closeSignalSent = true;
this.sendFrame({ type: "close" }); this.sendFrame({ type: "close" });
@ -701,7 +701,7 @@ export class ProcessTerminalSession {
return; return;
} }
if (this.socket.readyState !== WebSocket.CLOSED) { if (this.socket.readyState !== WS_READY_STATE_CLOSED) {
this.socket.close(); this.socket.close();
} }
} }
@ -743,7 +743,7 @@ export class ProcessTerminalSession {
} }
private sendFrame(frame: ProcessTerminalClientFrame): void { private sendFrame(frame: ProcessTerminalClientFrame): void {
if (this.socket.readyState !== WebSocket.OPEN) { if (this.socket.readyState !== WS_READY_STATE_OPEN) {
return; return;
} }
@ -757,6 +757,10 @@ export class ProcessTerminalSession {
} }
} }
const WS_READY_STATE_CONNECTING = 0;
const WS_READY_STATE_OPEN = 1;
const WS_READY_STATE_CLOSED = 3;
export class SandboxAgent { export class SandboxAgent {
private readonly baseUrl: string; private readonly baseUrl: string;
private readonly token?: string; private readonly token?: string;