Skip to content

Commit

Permalink
fix: flicker on visibility change
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed Aug 1, 2024
1 parent fea3737 commit 8411771
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
await this.replaceSenderTrack(this.processedTrack || this.nativeTrack);
};

// eslint-disable-next-line complexity
private handleVisibilityChange = async () => {
if (document.visibilityState === 'hidden') {
if (isMobile()) {
Expand All @@ -531,20 +532,22 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
);
}
} else {
const newEnabledState = isMobile() ? this.enabledStateBeforeBackground : this.enabled;
if (this.nativeTrack.muted || this.nativeTrack.readyState === 'ended') {
HMSLogger.d(this.TAG, 'visibility visible, restarting track', `${this}`);
const track = await this.replaceTrackWith(this.settings);
this.nativeTrack?.stop();
this.nativeTrack = track;
}
if (isMobile()) {
if (newEnabledState) {
await this.processPlugins();
await this.pluginsManager.waitForRestart();
}
await this.replaceSender(this.nativeTrack, newEnabledState);
this.videoHandler.updateSinks();
} else if (isMobile()) {
this.nativeTrack.enabled = this.enabledStateBeforeBackground;
await this.replaceSender(this.nativeTrack, this.enabledStateBeforeBackground);
} else {
await this.replaceSender(this.nativeTrack, this.enabled);
}
await this.processPlugins();
this.videoHandler.updateSinks();
}
this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this });
};
Expand Down

0 comments on commit 8411771

Please sign in to comment.