feat(packages/api): add force disconnecting and disconnected getter in APIClient

This commit is contained in:
PalmDevs
2024-07-30 21:02:42 +07:00
parent 8168f79ac6
commit a848a9c896
2 changed files with 8 additions and 4 deletions

View File

@@ -163,13 +163,17 @@ export default class Client {
/**
* Disconnects the client from the API
*/
disconnect() {
this.ws.disconnect()
disconnect(force?: boolean) {
this.ws.disconnect(force)
}
#throwIfNotReady() {
if (!this.isReady()) throw new Error('Client is not ready')
}
get disconnected() {
return this.ws.disconnected
}
}
export class ClientWebSocketPacketAwaiter {

View File

@@ -137,8 +137,8 @@ export class ClientWebSocketManager {
/**
* Disconnects from the WebSocket API
*/
disconnect() {
this.#throwIfDisconnected('Cannot disconnect when already disconnected from the server')
disconnect(force?: boolean) {
if (!force) this.#throwIfDisconnected('Cannot disconnect when already disconnected from the server')
this._handleDisconnect(DisconnectReason.PlannedDisconnect)
}