diff --git a/src/renderer/api/websocket-api.ts b/src/renderer/api/websocket-api.ts index c6ca43405829..398e02c3e2f7 100644 --- a/src/renderer/api/websocket-api.ts +++ b/src/renderer/api/websocket-api.ts @@ -65,7 +65,7 @@ export interface WebSocketEvents { type Defaulted = Required> & Omit; export class WebSocketApi extends (EventEmitter as { new(): TypedEventEmitter }) { - protected socket: WebSocket; + protected socket?: WebSocket | null; protected pendingCommands: (string | ArrayBufferLike | Blob | ArrayBufferView)[] = []; protected reconnectTimer?: any; protected pingTimer?: any; @@ -181,7 +181,7 @@ export class WebSocketApi extends (EventEmitter if (error) { const { reconnectDelay } = this.params; - if (reconnectDelay) { + if (reconnectDelay && this.socket) { const url = this.socket.url; this.writeLog("will reconnect in", `${reconnectDelay}s`);