reconnecter do not throw errors.

This commit is contained in:
Miroslav Šedivý 2021-07-26 23:20:14 +02:00
parent 963929a7d1
commit 558b6d2c0b

View File

@ -114,14 +114,17 @@ export class Reconnecter extends EventEmitter<ReconnecterEvents> {
} }
public open(deferredConnection = false): void { public open(deferredConnection = false): void {
if (this._open) { if (this._timeout) {
throw new Error('connection is already open') window.clearTimeout(this._timeout)
this._timeout = undefined
} }
this._open = true if (!this._open) {
this.emit('open') this._open = true
this.emit('open')
}
if (!deferredConnection) { if (!deferredConnection && !this._conn.connected) {
this.connect() this.connect()
} }
} }
@ -132,14 +135,12 @@ export class Reconnecter extends EventEmitter<ReconnecterEvents> {
this._timeout = undefined this._timeout = undefined
} }
if (!this._open) { if (this._open) {
throw new Error('connection is already closed') 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) { if (this._conn.connected) {
this._conn.disconnect() this._conn.disconnect()
} }
@ -156,10 +157,6 @@ export class Reconnecter extends EventEmitter<ReconnecterEvents> {
} }
public reconnect(): void { public reconnect(): void {
if (this._conn.connected) {
throw new Error('connection is already connected')
}
if (this._timeout) { if (this._timeout) {
window.clearTimeout(this._timeout) window.clearTimeout(this._timeout)
this._timeout = undefined this._timeout = undefined