Skip to content

Commit

Permalink
fix: try another fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed May 20, 2024
1 parent b2c0b0f commit 1071e63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
} else {
this.nativeTrack.enabled = this.enabledStateBeforeBackground;
this.replaceSenderTrack(this.nativeTrack);
if (this.nativeTrack.enabled) {
this.videoHandler.updateSinks();
}
}
this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this });
};
Expand Down
25 changes: 10 additions & 15 deletions packages/hms-video-store/src/media/tracks/VideoElementManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HMSLocalVideoTrack, HMSRemoteVideoTrack } from '../../internal';
import { HMSIntersectionObserver } from '../../utils/intersection-observer';
import HMSLogger from '../../utils/logger';
import { HMSResizeObserver } from '../../utils/resize-observer';
import { isBrowser } from '../../utils/support';
import { isBrowser, isMobile } from '../../utils/support';

/**
* This class is to manager video elements for video tracks.
Expand Down Expand Up @@ -83,20 +83,17 @@ export class VideoElementManager {
return Array.from(this.videoElements);
}

private resumeVideoPlayback = () => {
private resumeVideoPlayback = (e: Event) => {
console.trace('Resuming playback');
if (!document.hidden) {
if (!document.hidden && isMobile()) {
setTimeout(() => {
for (const element of this.videoElements) {
if (element.paused) {
console.log('element paused, try resuming');
element.play().catch(err => {
HMSLogger.w(
this.TAG,
`Error resuming video playback for ${this.track.trackId} ${(err as Error).message}`,
);
});
}
const element = e.target as HTMLVideoElement;
if (element.paused) {
console.log('element paused, try resuming');
this.track.addSink(element);
element.play().catch(err => {
HMSLogger.w(this.TAG, `Error resuming video playback for ${this.track.trackId} ${(err as Error).message}`);
});
}
}, 0);
}
Expand All @@ -106,7 +103,6 @@ export class VideoElementManager {
if (isBrowser) {
this.resizeObserver = HMSResizeObserver;
this.intersectionObserver = HMSIntersectionObserver;
document.addEventListener('visibilitychange', this.resumeVideoPlayback);
}
}

Expand Down Expand Up @@ -197,7 +193,6 @@ export class VideoElementManager {
this.intersectionObserver?.unobserve(videoElement);
});
this.videoElements.clear();
document.removeEventListener('visibilitychange', this.resumeVideoPlayback);
this.resizeObserver = undefined;
this.intersectionObserver = undefined;
};
Expand Down

0 comments on commit 1071e63

Please sign in to comment.