Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Reacquire wakeLock after switching tabs (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblaszkow06 authored Jun 23, 2022
1 parent 9b939bc commit 9019e8e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions assets/src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export class Room {
});
this.updateParticipantsList();
if ("wakeLock" in navigator) {
// Acquire wakeLock on join
navigator.wakeLock.request('screen').then((wakeLock) => { this.wakeLock = wakeLock; });

// Reacquire wakeLock when after the document is visible again (e.g. user went back to the tab)
document.addEventListener('visibilitychange', this.onVisibilityChange);
}
},
onJoinError: (_metadata) => {
Expand Down Expand Up @@ -251,7 +255,14 @@ export class Room {
this.webrtc.join({ displayName: this.displayName });
};

private onVisibilityChange = async () => {
if (this.wakeLock !== null && document.visibilityState === 'visible') {
this.wakeLock = await navigator.wakeLock.request('screen');
}
}

private leave = () => {
document.removeEventListener('visibilitychange', this.onVisibilityChange);
this.wakeLock && this.wakeLock.release();
this.wakeLock = null;
this.webrtc.leave();
Expand Down

0 comments on commit 9019e8e

Please sign in to comment.