mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
feat(packages/api): allow setting new options for ClientWebsocketManager
This commit is contained in:
@@ -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<ClientWebSocketManagerOptions>, 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
|
||||
|
||||
Reference in New Issue
Block a user