Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dont send preview failed after join on disconnect #3155

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<void> {
if (!this.localPeer || this.transportState !== TransportState.Joined) {
throw ErrorFactory.GenericErrors.NotConnected(HMSAction.VALIDATION, 'Not connected - midCallPreview');
Expand Down Expand Up @@ -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;

Expand Down
Loading