From 558b6d2c0b2758485a6a51de570e15f538df4e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 26 Jul 2021 23:20:14 +0200 Subject: [PATCH] reconnecter do not throw errors. --- src/component/utils/reconnecter.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/component/utils/reconnecter.ts b/src/component/utils/reconnecter.ts index 035b2b2a..58f21eca 100644 --- a/src/component/utils/reconnecter.ts +++ b/src/component/utils/reconnecter.ts @@ -114,14 +114,17 @@ export class Reconnecter extends EventEmitter { } public open(deferredConnection = false): void { - if (this._open) { - throw new Error('connection is already open') + if (this._timeout) { + window.clearTimeout(this._timeout) + this._timeout = undefined } - this._open = true - this.emit('open') + if (!this._open) { + this._open = true + this.emit('open') + } - if (!deferredConnection) { + if (!deferredConnection && !this._conn.connected) { this.connect() } } @@ -132,14 +135,12 @@ export class Reconnecter extends EventEmitter { this._timeout = undefined } - if (!this._open) { - throw new Error('connection is already closed') + if (this._open) { + this._open = false + this._last_connected = undefined + this.emit('close', error) } - this._open = false - this._last_connected = undefined - this.emit('close', error) - if (this._conn.connected) { this._conn.disconnect() } @@ -156,10 +157,6 @@ export class Reconnecter extends EventEmitter { } public reconnect(): void { - if (this._conn.connected) { - throw new Error('connection is already connected') - } - if (this._timeout) { window.clearTimeout(this._timeout) this._timeout = undefined