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

Listen to messages before iframe append #8981

Merged
merged 14 commits into from Apr 27, 2017
Merged

Conversation

aghassemi
Copy link
Contributor

Plus a few unrelated cleanups for video players.

this.element.appendChild(this.iframe_);
this.playerReadyPromise_ = this.loadPromise(this.iframe_).then(() => {
this.element.dispatchCustomEvent(VideoEvents.LOAD);
});
Copy link
Contributor

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;
Copy link
Contributor

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(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm?

@aghassemi
Copy link
Contributor Author

sorry for the spammy commits :) PTAL. I added back all the playerReadyPromise stuff, realized we need the playerReadyPromise in buildCallback so we can queue up actions calls until layout is done. (e.g. we want <button on=tap:myVideo.mute> to work even if myVideo has not gone through layoutCallback yet`)

Copy link
Contributor

@jridgewell jridgewell left a 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
}));

@aghassemi
Copy link
Contributor Author

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?

@aghassemi
Copy link
Contributor Author

@jridgewell Would a rejected promise drop references to all of its handlers? (wondering if load().then(...).catch( ()=> { this.playerReadyPromise = new Promise... } ) would be any better for memory footprint)

@aghassemi
Copy link
Contributor Author

@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 sendCommands won't run). But I think that's what we want anyway.

@jridgewell
Copy link
Contributor

Would a rejected promise drop references to all of its handlers?

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 promise if otherPromise rejects.

wondering if load().then(...).catch( ()=> { this.playerReadyPromise = new Promise... } ) would be any better for memory footprint

This creates another promise instance, and takes an extra tick.

@jridgewell
Copy link
Contributor

Also I think neither the current code nor your proposal will actually send the messages to iframe if load fails

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.

@aghassemi
Copy link
Contributor Author

Got it. PTAL.


return this.loadPromise(iframe)
this.element.appendChild(this.iframe_);
const loadPromise = this.loadPromise(this.iframe_)
.then(() => this.listenToFrame_())
.then(() => {
Copy link
Contributor

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?

@rsimha
Copy link
Contributor

rsimha commented Apr 27, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants