forked from 8thwall/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8e71db
commit 1929251
Showing
3 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* globals XR8 */ | ||
|
||
// This pauses XR8 when the tab is hidden and calls resumes XR8 once the tab is visible again. | ||
// Useful for when you want your camera feed and MediaRecorder audio to continue even if your | ||
// desktop browser tab isn't focused. It has nearly identical functionality to PauseOnBlur for | ||
// mobile. | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event | ||
let pauseOnHidden = null | ||
|
||
function create() { | ||
const onVisChange = () => { | ||
if (document.visibilityState === 'visible') { | ||
XR8.resume() | ||
} else { | ||
XR8.pause() | ||
} | ||
} | ||
|
||
const pipelineModule = () => ({ | ||
name: 'pauseonhidden', | ||
onAttach: () => { | ||
document.addEventListener('visibilitychange', onVisChange) | ||
}, | ||
onDetach: () => { | ||
document.removeEventListener('visibilitychange', onVisChange) | ||
}, | ||
}) | ||
|
||
return { | ||
// Creates a camera pipeline module that, when installed, pauses the camera feed and processing | ||
// when the tab is hidden and restarts again when it's visible | ||
pipelineModule, | ||
} | ||
} | ||
|
||
const PauseOnHiddenFactory = () => { | ||
if (pauseOnHidden == null) { | ||
pauseOnHidden = create() | ||
} | ||
|
||
return pauseOnHidden | ||
} | ||
|
||
module.exports = { | ||
PauseOnHiddenFactory, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters