From 6953d870ae9f1bd9fb9fb695dce2545c24a0f391 Mon Sep 17 00:00:00 2001 From: utf-4096 Date: Wed, 12 Jul 2023 13:34:52 +0200 Subject: [PATCH] fix: throw an error when login() or logoff() is unexpected --- src/Client.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Client.js b/src/Client.js index 9071703..ee73fef 100644 --- a/src/Client.js +++ b/src/Client.js @@ -55,6 +55,10 @@ export class Client extends EventEmitter { } login({ seed }) { + if (this.#ws && this.#ws.readyState === WebSocket.OPEN) { + throw new Error('already connected') + } + const ws = new WebSocket(this.#gateway) this.#ws = ws @@ -81,6 +85,10 @@ export class Client extends EventEmitter { } logoff() { + if (!this.#ws || this.#ws.readyState !== WebSocket.OPEN) { + throw new Error('not connected') + } + this.#ws.close() }