diff --git a/packages/api/src/classes/ClientWebSocket.ts b/packages/api/src/classes/ClientWebSocket.ts index fd6e9d0..87b75d2 100755 --- a/packages/api/src/classes/ClientWebSocket.ts +++ b/packages/api/src/classes/ClientWebSocket.ts @@ -17,7 +17,7 @@ import { type RawData, WebSocket } from 'ws' * This is the only relevant class for the time being. But in the future, there may be more classes to handle different protocols of the API. */ export class ClientWebSocketManager { - readonly url: string + url: string timeout: number connecting = false @@ -33,6 +33,21 @@ export class ClientWebSocketManager { this.timeout = options.timeout ?? 10000 } + /** + * Sets the URL to connect to + * + * **Requires a reconnect to take effect** + */ + async setOptions({ url, timeout }: Partial, autoReconnect = true) { + if (url) this.url = url + this.timeout = timeout ?? this.timeout + + if (autoReconnect) { + this.disconnect(true) + await this.connect() + } + } + /** * Connects to the WebSocket API * @returns A promise that resolves when the client is ready