Skip to content

Commit

Permalink
feat(UI): Add config to preferDocumentPictureInPicture (#5690)
Browse files Browse the repository at this point in the history
Closes #5689
  • Loading branch information
avelad authored Sep 28, 2023
1 parent 12400b1 commit 025502a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions ui/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
* @export
*/
isPiPAllowed() {
if ('documentPictureInPicture' in window) {
if ('documentPictureInPicture' in window &&
this.config_.preferDocumentPictureInPicture) {
return true;
}
if (document.pictureInPictureEnabled) {
Expand All @@ -663,7 +664,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
* @export
*/
isPiPEnabled() {
if ('documentPictureInPicture' in window) {
if ('documentPictureInPicture' in window &&
this.config_.preferDocumentPictureInPicture) {
return !!window.documentPictureInPicture.window;
} else {
return !!document.pictureInPictureElement;
Expand All @@ -673,7 +675,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
/** @export */
async togglePiP() {
try {
if ('documentPictureInPicture' in window) {
if ('documentPictureInPicture' in window &&
this.config_.preferDocumentPictureInPicture) {
await this.toggleDocumentPictureInPicture_();
} else if (!document.pictureInPictureElement) {
// If you were fullscreen, leave fullscreen first.
Expand Down
9 changes: 8 additions & 1 deletion ui/externs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ shaka.extern.UIVolumeBarColors;
* enableTooltips: boolean,
* keyboardSeekDistance: number,
* keyboardLargeSeekDistance: number,
* fullScreenElement: HTMLElement
* fullScreenElement: HTMLElement,
* preferDocumentPictureInPicture: boolean
* }}
*
* @property {!Array.<string>} controlPanelElements
Expand Down Expand Up @@ -193,6 +194,12 @@ shaka.extern.UIVolumeBarColors;
* @property {HTMLElement} fullScreenElement
* DOM element on which fullscreen will be done.
* Defaults to Shaka Player Container.
* @property {boolean} preferDocumentPictureInPicture
* Indicates whether the Document Picture in Picture API is preferred or the
* Video Element Picture in Picture API is preferred.
* Changing this property in mid-playback may produce undesired behavior if
* you are already in PiP.
* Defaults to true.
* @exportDoc
*/
shaka.extern.UIConfiguration;
Expand Down
1 change: 1 addition & 0 deletions ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ shaka.ui.Overlay = class {
keyboardSeekDistance: 5,
keyboardLargeSeekDistance: 60,
fullScreenElement: this.videoContainer_,
preferDocumentPictureInPicture: true,
};

// eslint-disable-next-line no-restricted-syntax
Expand Down

0 comments on commit 025502a

Please sign in to comment.