-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add PiP pollyfill #1902
Conversation
Currently the PR has errors, but I need some guidance for resolve it.
|
There seems to be no license information in the repository you're pulling from, and much of the code looks verbatim. So I'm not sure that I can accept this without a clear license from the author. But it should be fairly easy to implement from scratch with a link to the Apple docs on this functionality. The compiler issue is caused by the lack of annotations on the methods you're patching over. For example, |
Ok, tomorrow I'll rewrite the polyfill from scratch. I hope it can be introduced in version 2.5 |
I have updated the implementation. But I have 4 error that i can not fix...
Can you help me to correct it? |
Absolutely! I'd be happy to help. I'll leave specific comments on the changes. Thank you for working on this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the code, but i have 6 errors...
[WARNING] No changes detected, skipping. Use --force to override.
[INFO] Generating Closure dependencies...
[INFO] Linting JavaScript...
[WARNING] No changes detected, skipping. Use --force to override.
[INFO] Linting HTML...
[WARNING] No changes detected, skipping. Use --force to override.
[INFO] Checking that the build files are complete...
[INFO] Checking the tests for type errors...
[WARNING] No changes detected, skipping. Use --force to override.
/home/avelad/workspace/pull-request/shaka-player/lib/polyfill/pip.js:109: ERROR - actual parameter 1 of shaka.polyfill.PiP.getProxyEnterPiPEvent_ does not match formal parameter
found : (EventListener|function(Event): (boolean|undefined)|null)
required: (EventListener|null)
shaka.polyfill.PiP.getProxyEnterPiPEvent_(listener);
^^^^^^^^
/home/avelad/workspace/pull-request/shaka-player/lib/polyfill/pip.js:114: ERROR - actual parameter 1 of shaka.polyfill.PiP.getProxyLeavePiPEvent_ does not match formal parameter
found : (EventListener|function(Event): (boolean|undefined)|null)
required: (EventListener|null)
shaka.polyfill.PiP.getProxyLeavePiPEvent_(listener);
^^^^^^^^
/home/avelad/workspace/pull-request/shaka-player/lib/polyfill/pip.js:130: ERROR - actual parameter 1 of shaka.polyfill.PiP.getProxyEnterPiPEvent_ does not match formal parameter
found : (EventListener|function(Event): (boolean|undefined)|null)
required: (EventListener|null)
shaka.polyfill.PiP.getProxyEnterPiPEvent_(listener);
^^^^^^^^
/home/avelad/workspace/pull-request/shaka-player/lib/polyfill/pip.js:135: ERROR - actual parameter 1 of shaka.polyfill.PiP.getProxyLeavePiPEvent_ does not match formal parameter
found : (EventListener|function(Event): (boolean|undefined)|null)
required: (EventListener|null)
shaka.polyfill.PiP.getProxyLeavePiPEvent_(listener);
^^^^^^^^
/home/avelad/workspace/pull-request/shaka-player/lib/polyfill/pip.js:209: ERROR - EventListener expressions are not callable
listener();
^^^^^^^^^^
/home/avelad/workspace/pull-request/shaka-player/lib/polyfill/pip.js:225: ERROR - EventListener expressions are not callable
listener();
^^^^^^^^^^
6 error(s), 0 warning(s), 91.4% typed
[ERROR] Build failed
@joeyparrish , Do you have any idea how to solve it? I have tried many things but none has worked
The functionality works without problem in Safari.
lib/polyfill/pip.js
Outdated
/** | ||
* polyfill document.pictureInPictureEnabled | ||
*/ | ||
document.pictureInPictureEnabled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried and the API it in both MSE and src = so I have not seen any reason for this to not be true.
lib/polyfill/pip.js
Outdated
/** | ||
* polyfill document.pictureInPictureEnabled | ||
*/ | ||
document.pictureInPictureEnabled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sounds good.
lib/polyfill/pip.js
Outdated
/** | ||
* Get the proxy webkitpresentationmodechanged event. | ||
* | ||
* @param {EventListener} listener |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the compiler error is because addEventListener has a more complex signature that you would think. It accepts more than just EventListener, so the argument passed here could have other types, as well.
Could you listen to the webkit events all the time and dispatch equivalent standard events when they are seen? Like we do in the fullscreen polyfill?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not the same case than fullscreen. In fullscreen polyfill the event is trigger over the document. In this case, the event is trigger over the video element. I'll try to find another solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the only remaining issue is the compiler error on the parameter type here, you could just extend it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this:
@param {EventListener|function(Event): (boolean|undefined)} listener
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR - actual parameter 1 of shaka.polyfill.PiP.getProxyLeavePiPEvent_ does not match formal parameter
found : (EventListener|function(Event): (boolean|undefined)|null)
required: (EventListener|function((Event|null)): (boolean|undefined)|null)
lib/polyfill/pip.js
Outdated
if (videoElement.webkitPresentationMode === 'picture-in-picture') { | ||
// keep track of the pipElement | ||
document.pictureInPictureElement = videoElement; | ||
listener(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you'll need to call listener(event) with the event, since the compiler expects an argument. But if the listener is looking at event.type for some reason, it might get confused by seeing a type it didn't listen for.
I think this is another good argument for redispatching events.
I updated the implementacion without compiler issues and working in safari. |
/** @type {HTMLMediaElement} */ | ||
let polyfillPictureInPictureElement = null; | ||
|
||
let polyfillEnterpictureinpicture = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may be avoiding compiler errors by leaving out types. I appreciate all the work you've done on this, though, and I know the compiler can be a pain sometimes. I think perhaps we should merge this PR as-is and I will work on some follow-up changes. Would that be alright?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it's ok!
Thanks for your revision, I really appreciate it and it help to another PR in coming.
All tests passed! |
@joeyparrish , any news about this merge? |
Sorry, we've been busy wrapping up other things. I'm merging now, and I'll work on a that little bit of cleanup after that. Thanks for your contribution! |
I've experimented a bit and found a much simpler way to manage the events. It turns out that you can listen on document in the capturing phase to avoid having to shim the listeners on the video elements. |
Follow-up to #1902 Change-Id: I760d0006c4cbd7c3aad2ce96801259b578269195
By listening to events on document in the capturing phase, we can avoid complex event shims on HTMLVideoElement. By monitoring global PiP state on the document, we can get rid of the getter and setter for the document's PiP element, as well. Follow-up on PR #1902 Change-Id: Ib5f5d0c7c735124a438901c5bb15e034ab10b996
@avelad, I've just merged the last of my changes to your polyfill. Thanks again for working on this! It's great to see Safari and iOS getting so many useful features beyond merely "src= playback". |
Add PiP pollyfill for Safari
Based in https://github.com/gbentaieb/pip-polyfill