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
Listen to messages before iframe append #8981
Conversation
this.element.appendChild(this.iframe_); | ||
this.playerReadyPromise_ = this.loadPromise(this.iframe_).then(() => { | ||
this.element.dispatchCustomEvent(VideoEvents.LOAD); | ||
}); |
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.
👏
@@ -42,7 +42,7 @@ class AmpOoyalaPlayer extends AMP.BaseElement { | |||
this.playerReadyPromise_ = null; | |||
|
|||
/** @private {?Function} */ | |||
this.unlistenMessage_ = null; | |||
this.playerReadyResolver_ = 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.
This can be dropped.
@@ -191,12 +198,13 @@ class AmpYoutube extends AMP.BaseElement { | |||
); | |||
|
|||
this.element.appendChild(this.iframe_); | |||
this.playerReadyPromise_ = this.loadPromise(this.iframe_).then(() => { |
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.
Hm?
sorry for the spammy commits :) PTAL. I added back all the playerReadyPromise stuff, realized we need the playerReadyPromise in |
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 we go down this road, we need to resolve the #playerReadyPromise
with the loadPromise
. This will drop all queued messages to the iframe if loading fails.
// bad
let resolve;
const promise = new Promise(r => resolve = r);
otherPromise.then(() => {
// do some stuff
resolve();
});
// good
let resolve;
const promise = new Promise(r => resolve = r);
resolve(otherPromise.then(() => {
// do some stuff
}));
oh man Travis is running for every one of my back-to-back commits. @erwinmombay @rsimha-amp Can Travis become smart to cancel previous in-progress runs when a new commit comes in? |
@jridgewell Would a rejected promise drop references to all of its handlers? (wondering if |
@jridgewell Also I think neither the current code nor your proposal will actually send the messages to iframe if load fails (resolving with a rejected promise still results in a rejected promise meaning all the queued up |
Yes, that's why I want you to resolve with a promise and not the promise's fulfilled value. Doing the good example above rejects the original
This creates another promise instance, and takes an extra tick. |
Yes. But the difference is the current code keeps all those messages in memory because the promise is never resolved (neither fulfilled or rejected) and could be fulfilled at some point in the future. Rejecting (by resolving with a rejected promise) will drop all those from memory. |
Got it. PTAL. |
|
||
return this.loadPromise(iframe) | ||
this.element.appendChild(this.iframe_); | ||
const loadPromise = this.loadPromise(this.iframe_) | ||
.then(() => this.listenToFrame_()) | ||
.then(() => { |
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.
Nit: Can we join this with the previous block?
@aghassemi, re: preventing Travis from running against every one of your commits, there seems to be hope: travis-ci/travis-ci#964 I'll investigate this tomorrow and see if it's something we can institute within amphtml. |
Plus a few unrelated cleanups for video players.