From a13aabd39466ab3e31978af4ab8633db627c5936 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 4 Feb 2021 22:18:03 +0530 Subject: [PATCH] Prevent unexpected endConnection --- src/WAConnection/0.Base.ts | 2 +- src/WAConnection/1.Validation.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/WAConnection/0.Base.ts b/src/WAConnection/0.Base.ts index a3b0044..0f09986 100644 --- a/src/WAConnection/0.Base.ts +++ b/src/WAConnection/0.Base.ts @@ -96,7 +96,7 @@ export class WAConnection extends EventEmitter { protected mediaConn: MediaConnInfo protected connectionDebounceTimeout = Utils.debouncedTimeout( 1000, - () => this.endConnection(DisconnectReason.timedOut) + () => this.state === 'connecting' && this.endConnection(DisconnectReason.timedOut) ) protected messagesDebounceTimeout = Utils.debouncedTimeout(2000) /** diff --git a/src/WAConnection/1.Validation.ts b/src/WAConnection/1.Validation.ts index 9faa527..252ea58 100644 --- a/src/WAConnection/1.Validation.ts +++ b/src/WAConnection/1.Validation.ts @@ -225,7 +225,8 @@ export class WAConnection extends Base { ref = newRef } catch (error) { this.logger.warn ({ error }, `error in QR gen`) - if (error.status === 429) { // too many QR requests + // @ts-ignore + if (error.status === 429 && this.state !== 'open') { // too many QR requests this.endConnection(error.message) return }