Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PiP pollyfill #1902

Merged
merged 11 commits into from
May 3, 2019
Prev Previous commit
Next Next commit
Move polyfillPictureInPictureElement to local variable
Alvaro Velad committed May 1, 2019

Verified

This commit was signed with the committer’s verified signature. The key has expired.
commit c228b2f277d30fdae672657196b40d721a4526c1
4 changes: 0 additions & 4 deletions externs/pictureinpicture.js
Original file line number Diff line number Diff line change
@@ -34,10 +34,6 @@ HTMLDocument.prototype.pictureInPictureElement;
HTMLDocument.prototype.pictureInPictureEnabled;


/** @type {Element} */
HTMLDocument.prototype.polyfillPictureInPictureElement;


/**
* @return {!Promise}
*/
19 changes: 11 additions & 8 deletions lib/polyfill/pip.js
Original file line number Diff line number Diff line change
@@ -47,28 +47,31 @@ shaka.polyfill.PiP.install = function() {
if (proto.webkitSupportsPresentationMode) {
avelad marked this conversation as resolved.
Show resolved Hide resolved
shaka.log.debug('PiP.install');

/** @type {HTMLMediaElement} */
let polyfillPictureInPictureElement = null;

/**
* polyfill document.pictureInPictureElement
*/
Object.defineProperty(document, 'pictureInPictureElement', {
avelad marked this conversation as resolved.
Show resolved Hide resolved
get() {
return document.polyfillPictureInPictureElement;
return polyfillPictureInPictureElement;
},

set(value) {
if (value === document.polyfillPictureInPictureElement) return;
if (value === polyfillPictureInPictureElement) return;

if (document.polyfillPictureInPictureElement) {
document.polyfillPictureInPictureElement.removeEventListener(
if (polyfillPictureInPictureElement) {
polyfillPictureInPictureElement.removeEventListener(
'webkitpresentationmodechanged',
shaka.polyfill.PiP.updatePictureInPictureElementInDocument_,
);
}

document.polyfillPictureInPictureElement =
/** @type {!HTMLMediaElement} */ (value);
if (document.polyfillPictureInPictureElement) {
document.polyfillPictureInPictureElement.addEventListener(
polyfillPictureInPictureElement =
/** @type {HTMLMediaElement} */ (value);
if (polyfillPictureInPictureElement) {
polyfillPictureInPictureElement.addEventListener(
'webkitpresentationmodechanged',
shaka.polyfill.PiP.updatePictureInPictureElementInDocument_,
);