Skip to content

Commit

Permalink
Force playback after app visibility changes back to visible (#1106)
Browse files Browse the repository at this point in the history
* Force playback after app visibility changes back to visible

* Create lemon-horses-cover.md

* remove debug logs
  • Loading branch information
lukasIO authored Apr 15, 2024
1 parent 9a59311 commit 7f0c1af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-horses-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": minor
---

Force playback after app visibility changes back to visible
11 changes: 11 additions & 0 deletions src/room/track/Track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@ export abstract class Track<

protected async handleAppVisibilityChanged() {
this.isInBackground = document.visibilityState === 'hidden';
if (!this.isInBackground && this.kind === Track.Kind.Video) {
setTimeout(
() =>
this.attachedElements.forEach((el) =>
el.play().catch(() => {
/** catch clause necessary for Safari */
}),
),
0,
);
}
}

protected addAppVisibilityListener() {
Expand Down

0 comments on commit 7f0c1af

Please sign in to comment.