From 091d1c710a01f5a71f8e60137fa3bf3e1ec540b8 Mon Sep 17 00:00:00 2001 From: eswarclynn Date: Mon, 5 Aug 2024 15:48:22 +0530 Subject: [PATCH] fix: remove terminal error handling from preview(dont send preview.failed after join on disconnect) --- packages/hms-video-store/src/sdk/index.ts | 25 ++++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index cb45ca5d57..76940879d7 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -429,16 +429,9 @@ export class HMSSdk implements HMSInterface { resolve(); }; - const errorHandler = (ex?: HMSException) => { - this.analyticsTimer.end(TimedEvent.PREVIEW); - ex && this.errorListener?.onError(ex); - this.sendPreviewAnalyticsEvent(ex); - this.sdkState.isPreviewInProgress = false; - reject(ex as HMSException); - }; - this.eventBus.policyChange.subscribeOnce(policyHandler); - this.eventBus.leave.subscribeOnce(errorHandler); + this.eventBus.leave.subscribeOnce(this.handlePreviewError); + this.eventBus.leave.subscribeOnce(ex => reject(ex as HMSException)); this.transport .preview( @@ -458,10 +451,20 @@ export class HMSSdk implements HMSInterface { }); } }) - .catch(errorHandler); + .catch(ex => { + this.handlePreviewError(ex); + reject(ex); + }); }); } + private handlePreviewError = (ex?: HMSException) => { + this.analyticsTimer.end(TimedEvent.PREVIEW); + ex && this.errorListener?.onError(ex); + this.sendPreviewAnalyticsEvent(ex); + this.sdkState.isPreviewInProgress = false; + }; + private async midCallPreview(asRole?: string, settings?: InitialSettings): Promise { if (!this.localPeer || this.transportState !== TransportState.Joined) { throw ErrorFactory.GenericErrors.NotConnected(HMSAction.VALIDATION, 'Not connected - midCallPreview'); @@ -539,6 +542,8 @@ export class HMSSdk implements HMSInterface { throw ErrorFactory.GenericErrors.NotReady(HMSAction.JOIN, "Preview is in progress, can't join"); } + // remove terminal error handling from preview(do not send preview.failed after join on disconnect) + this.eventBus.leave.unsubscribe(this.handlePreviewError); this.analyticsTimer.start(TimedEvent.JOIN); this.sdkState.isJoinInProgress = true;