-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
feat: always return a promise from play, if supported #5227
Conversation
@@ -1148,7 +1149,18 @@ QUnit.test('play promise should resolve to native value if returned', function(a | |||
player.tech_.play = () => 'foo'; | |||
const p = player.play(); | |||
|
|||
assert.equal(p, 'foo', 'play returns foo'); | |||
const finish = (v) => { |
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.
now that play will always return a promise, if it is supported, we have to use then
to check the resolved value.
}); | ||
} | ||
|
||
return this.play_(); |
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.
ie11 does not support promises, so that should be the only platform this happens on.
ea148de
to
9789bf4
Compare
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.
This is probably a good first step, we should make sure that this is set up to adding rejecting the promise properly as well. We might want to do that in a separate PR though.
src/js/player.js
Outdated
|
||
if (promise) { | ||
return new Promise((resolve) => { |
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 wonder if it's possible to have play_
return a promise itself or use a promise we give it. Maybe a bit tricky since our play_
method has some event listeners.
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.
whats really tricky is that IE 11 does not have promise support, so we can't technically return a promise all the time.
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.
yeah, IE11 aside, I mean.
We can require a polyfill for the best behavior here, as long as we don't fail if one doesn't provided.
Two questions for you @gkatsev.
|
I guess I never responded here.
|
So if we want to try and shim the play promise behavior on IE 11. Does that mean we want to:
|
Yeah, more or less. It gets a bit trickier because you'd want to reject the promise if you get a pause before play and stuff like that but essentially if a native play promise isn't provided we want to make our own promise. |
My main worry was that on IE11 if a Promise Polyfill was on the page, we'd end up returning a forever-pending promise, but I think that we'd get a promise that gets resolved once |
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 want to take this for a quick spin but otherwise, it's good to go. I'll work on making a full play promise shim afterwards.
awesome, also make sure in the next pr to add something here: https://github.com/videojs/video.js/pull/5227/files#diff-3b0266ff1c037b289ec624ab25b0272eR1928 that will check to see if there is a play promise and if not it will fallback to using |
If Promise is available or if Promise is polyfilled, then we'll return a new Promise from `play()` that will get fulfilled with the value returned from the `play()` method. This means that on IE11, this promise will get resolved when we call `play()` even if play doesn't succeed. We will have a follow-on PR to polyfill this behavior and resolve or reject the promise for browsers like IE11 that don't return a promise from `play()`.
If Promise is available or if Promise is polyfilled, then we'll return a new Promise from `play()` that will get fulfilled with the value returned from the `play()` method. This means that on IE11, this promise will get resolved when we call `play()` even if play doesn't succeed. We will have a follow-on PR to polyfill this behavior and resolve or reject the promise for browsers like IE11 that don't return a promise from `play()`.
If Promise is available or if Promise is polyfilled, then we'll return a new Promise from `play()` that will get fulfilled with the value returned from the `play()` method. This means that on IE11, this promise will get resolved when we call `play()` even if play doesn't succeed. We will have a follow-on PR to polyfill this behavior and resolve or reject the promise for browsers like IE11 that don't return a promise from `play()`.
Description
Always return a Promise from play when we have a Promise object.
Fixes #3927