fix: throw an error when login() or logoff() is unexpected
This commit is contained in:
@@ -55,6 +55,10 @@ export class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login({ seed }) {
|
login({ seed }) {
|
||||||
|
if (this.#ws && this.#ws.readyState === WebSocket.OPEN) {
|
||||||
|
throw new Error('already connected')
|
||||||
|
}
|
||||||
|
|
||||||
const ws = new WebSocket(this.#gateway)
|
const ws = new WebSocket(this.#gateway)
|
||||||
this.#ws = ws
|
this.#ws = ws
|
||||||
|
|
||||||
@@ -81,6 +85,10 @@ export class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logoff() {
|
logoff() {
|
||||||
|
if (!this.#ws || this.#ws.readyState !== WebSocket.OPEN) {
|
||||||
|
throw new Error('not connected')
|
||||||
|
}
|
||||||
|
|
||||||
this.#ws.close()
|
this.#ws.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user