mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(packages/api): ready event triggering even when not ready
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
|||||||
uncapitalize,
|
uncapitalize,
|
||||||
} from '@revanced/bot-shared'
|
} from '@revanced/bot-shared'
|
||||||
import type TypedEmitter from 'typed-emitter'
|
import type TypedEmitter from 'typed-emitter'
|
||||||
import { type RawData, WebSocket } from 'ws'
|
import { RawData, WebSocket } from 'ws'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class that handles the WebSocket connection to the server.
|
* The class that handles the WebSocket connection to the server.
|
||||||
@@ -41,14 +41,16 @@ export default class ClientGateway {
|
|||||||
|
|
||||||
this.#socket.on('open', () => {
|
this.#socket.on('open', () => {
|
||||||
this.disconnected = false
|
this.disconnected = false
|
||||||
|
this.#listen()
|
||||||
|
this.ready = true
|
||||||
|
this.#emitter.emit('ready')
|
||||||
rs()
|
rs()
|
||||||
})
|
})
|
||||||
|
|
||||||
this.#socket.on('close', () => this.#handleDisconnect(DisconnectReason.Generic))
|
const errorHandler = () => this.#handleDisconnect(DisconnectReason.Generic)
|
||||||
|
|
||||||
this.#listen()
|
this.#socket.on('close', errorHandler)
|
||||||
this.ready = true
|
this.#socket.on('error', errorHandler)
|
||||||
this.#emitter.emit('ready')
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rj(e)
|
rj(e)
|
||||||
}
|
}
|
||||||
@@ -112,7 +114,6 @@ export default class ClientGateway {
|
|||||||
*/
|
*/
|
||||||
disconnect() {
|
disconnect() {
|
||||||
this.#throwIfDisconnected('Cannot disconnect when already disconnected from the server')
|
this.#throwIfDisconnected('Cannot disconnect when already disconnected from the server')
|
||||||
|
|
||||||
this.#handleDisconnect(DisconnectReason.Generic)
|
this.#handleDisconnect(DisconnectReason.Generic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user