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 amp-hulu element for Hulu videos. #5993
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
CLAs look good, thanks! |
@unbug Out of curiosity: Are you working for Hulu? |
@cramforce I am :) |
@unbug, thanks for the PR. Couple of questions before the code review: 1- Is any publisher allowed to use 2- Does the Hulu's iframe embed have a postMessage API that would allow |
@aghassemi Thanks for your time.
|
@unbug Any reason |
@aghassemi Thanks for your time :)
|
iframe.setAttribute('allowfullscreen', 'true'); | ||
iframe.src = 'https://secure.hulu.com/dash/mobile_embed.html?eid=' + encodeURIComponent(eid); | ||
this.applyFillContent(iframe); | ||
iframe.width = width; |
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.
Setting the width and height on the iframe shouldn't be necessary as it's "fill-content".
That's fine but keep in mind that AMP pages can be served from caches such as
Good to hear, please implement the video-interface as soon as you have the necessary hooks. Implementing the video-interface will automatically enable features such as AMP-managed I will send out the code review soon. |
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.
Additional requests:
1- Validation file (validator-amp-hulu.protoascii
) is missing. Please take a look at <amp-youtube>
or other amp components for reference.
2- amp-hulu
needs to be added to gulpfile.js
to be built.
3- Please only submit when cdn.ampproject.org
as referrer works as per previous comment.
|
||
/** @override */ | ||
createdCallback() { | ||
this.preconnect.url('https://secure.hulu.com/dash/mobile_embed.html'); |
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.
move to preconnectCallback
override.
|
||
/** @override */ | ||
createdCallback() { | ||
this.preconnect.url('https://secure.hulu.com/dash/mobile_embed.html'); |
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.
just preconnect to https://secure.hulu.com
, the path segment is not useful.
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.
'https://secure.hulu.com` is refusing origins other than http://.hulu.com https://.hulu.com *.optimizely.com, but any request's referer is https://secure.hulu.com/dash/mobile_embed.html
will not.
Should we preconnect to https://secure.hulu.com/dash/mobile_embed.html
?
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.
that's fine then, I did not realize 'https://secure.hulu.com` and tps://secure.hulu.com/dash/mobile_embed.html
have different access policies.
import {user} from '../../../src/log'; | ||
|
||
class AmpHulu extends AMP.BaseElement { | ||
|
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.
add constructor where iframe_
is defined.
/** @param {!AmpElement} element */
constructor(element) {
super(element);
/** @private {?Element} */
this.iframe_ = null;
}
iframe.width = width; | ||
iframe.height = height; | ||
this.element.appendChild(iframe); | ||
/** @private {?Element} */ |
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.
remove this type annotation (since it will be annotated in the constructor per request above))
/** @override */ | ||
pauseCallback() { | ||
if (this.iframe_ && this.iframe_.contentWindow) { | ||
this.iframe_.contentWindow./*OK*/postMessage('pause', '*'); |
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.
does this actually work? I thought there is no postMessage API. If this does not work yet, please remove the pauseCallaback and set
/** @override */
unlayoutOnPause() {
return true;
}
until you have postMessage support.
<td class="col-fourty"><strong><a href="https://www.ampproject.org/docs/guides/responsive/control_layout.html">Supported Layouts</a></strong></td> | ||
<td>fill, fixed, fixed-height, flex-item, nodisplay, responsive</td> | ||
</tr> | ||
<tr> |
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.
remove it instead of a TODO, add back when example is there.
<td>(TODO) <a href="https://ampbyexample.com/components/amp-hulu/">Annotated code example for amp-hulu</a></td> | ||
</tr> | ||
</table> | ||
|
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.
Please mention the restrictions (in bold warning) and instructions on how publishers can signup for whitelisting.
## Example | ||
|
||
```html | ||
<amp-hulu width="400" height="400" |
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.
add layout="responsive"
to the example
|
||
/** @override */ | ||
layoutCallback() { | ||
const width = this.element.getAttribute('width'); |
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.
as per @jridgewell's comment, no need to read the width/height values.
## Example | ||
|
||
```html | ||
<amp-hulu width="400" height="400" |
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.
Please use correct aspect ratio for this video ( width="412" height="231" ?)
@aghassemi Thanks for your time :)
I just talked to my team about the Content-Security-Policy issue. Yes, 'https://secure.hulu.com` is refusing origins other than
|
I was under the impression that Hulu only allows certain origins to be able to embed Hulu videos, if that's not the case and any origin can embed Hulu videos, then it is not an issue at all. |
# limitations under the license. | ||
# | ||
|
||
tags: { # amp-hulu |
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.
@Gregable @powdercloud @honeybadgerdontcare can somebody review this? seems to be causing a failure on the validator tests
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.
Please rename the file to validator-amp-hulu.protoascii.
@unbug Please let me know when this is ready for review again. Thanks! |
attrs: { | ||
name: "src" | ||
mandatory: true | ||
value_regex: "https://cdn\\.ampproject\\.org/v0/amp-hulu-(latest|0\\.1).js" |
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.
Please escape the last "." e.g. \\.js
tags: { # <amp-hulu> | ||
html_format: AMP | ||
html_format: AMP4ADS | ||
tag_name: "AMP-VINE" |
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.
The tag_name should be AMP-HULU
not AMP-VINE
tag_name: "AMP-VINE" | ||
disallowed_ancestor: "AMP-SIDEBAR" | ||
also_requires_tag: "amp-hulu extension .js script" | ||
# data-* is generally allowed, but it's not generally mandatory. |
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.
No need for this comment here.
disallowed_ancestor: "AMP-SIDEBAR" | ||
also_requires_tag: "amp-hulu extension .js script" | ||
# data-* is generally allowed, but it's not generally mandatory. | ||
attrs: { name: "data-eid" mandatory: 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.
nit, please expand to multi-line.
attrs: {
name: "data-eid"
mandatory: true
}
supported_layouts: FIXED | ||
supported_layouts: FIXED_HEIGHT | ||
supported_layouts: FLEX_ITEM | ||
supported_layouts: NODISPLAY |
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.
Somewhat surprised to see nodisplay. Is that intentional? Wouldn't a video player want to be seen?
@@ -106,6 +106,7 @@ declareExtension('amp-viz-vega', '0.1', true); | |||
declareExtension('amp-google-vrview-image', '0.1', false, 'NO_TYPE_CHECK'); | |||
declareExtension('amp-viewer-integration', '0.1', false); | |||
declareExtension('amp-youtube', '0.1', false); | |||
declareExtension('amp-hulu', '0.1', false, 'NO_TYPE_CHECK'); |
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, please put this in alphabetical order (even though some are not, lets try to keep it consistent).
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.
👍
Thanks @honeybadgerdontcare , I was wordering why it can't pass the travis. I had no idea about the validator rules, so I just followed vine's file, and it failed, so I talked to @erwinmombay in slack, it's not ready to reviewed yet. You're very helping, I'll make it right and re-summit again :) |
@aghassemi It's ready, thanks 👍 |
@unbug validator rules look good. thanks! |
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.
Thanks @unbug. Two small requests and then we should be good to merge this.
iframe.src = 'https://secure.hulu.com/dash/mobile_embed.html?eid=' + encodeURIComponent(eid); | ||
this.applyFillContent(iframe); | ||
this.element.appendChild(iframe); | ||
/** @private {?Element} */ |
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.
remove the type annotation, it is redundant at this point.
@@ -72,6 +72,7 @@ declareExtension('amp-form', '0.1', true); | |||
declareExtension('amp-fresh', '0.1', true); | |||
declareExtension('amp-fx-flying-carpet', '0.1', true); | |||
declareExtension('amp-gfycat', '0.1', false); | |||
declareExtension('amp-hulu', '0.1', false, 'NO_TYPE_CHECK'); |
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.
Please remove NO_TYPE_CHECK
and allow the component to be type checked. Please run gulp check-types
locally to ensure it passes type checking.
|
||
/** @override */ | ||
preconnectCallback() { | ||
this.preconnect.url('https://secure.hulu.com/dash/mobile_embed.html'); |
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.
Should this be Preconnect#preload
? The path won't be useful for #url
.
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.
@unbug Signature of this method is preconnectCallback(onLayout)
and onLayout needs to be passed to this.preconnect.url
as the last arg.
@jridgewell I had the same question but apparently https://secure.hulu.com/dash/mobile_embed.html
and https://secure.hulu.com/
return different Content-Security-Policy
response headers. I don't know if preconnect logic still keeps the connections if Content-Security-Policy
is not met.
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.
Why not #preload
then? That'll get the right security headers and we won't have this question again. 😁
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.
@unbug let's do @jridgewell's suggestion for preload but you need to have the eid=
appended to the Url before preloading. I suggest the following:
1- introduce a new instance variable this.eid_
in the cosntrcutor.
2- in buildCallback
do the this.eid_ = user().assert(this.element.getAttribute('data-eid'), 'The data-eid attribute is required for <amp-hulu> %s', this.element);
instead of in the layoutCallback as it does now.
3- Create a new getVideoIframeSrc_()
which returns the Url with correct eid query string appended.
4- Use getVideoIframeSrc_()
in preconnectCallback
and layoutCallback
} | ||
|
||
/** @override */ | ||
unlayoutOnPause() { |
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.
We need an #unlayoutCallback
that removes the iframe! See https://github.com/ampproject/amphtml/blob/master/extensions/amp-brightcove/0.1/amp-brightcove.js#L122-L128.
@aghassemi @jridgewell Sorry for so much troubles, 👍 and thanks for your patience. I hope this time everything is ready :) |
use es6 syntax use const instead of let added validator file remove size expect code reviewed some updated added amp-hulu reviewd validator code reviewed, remove NO_TYPE_CHECK, added getVideoIframeSrc_ syntax fixed
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.
LGTM
/** @return {string} */ | ||
getVideoIframeSrc_() { | ||
dev().assert(this.eid_); | ||
return `https://secure.hulu.com/dash/mobile_embed.html?eid=${encodeURIComponent(this.eid_ || '')}`; |
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.
The || ''
will never occur, since we've asserted #eid
is truthy.
@unbug LGTM. |
@aghassemi Thanks, my team already created a ticket for |
Intent to use amp-hulu element in Hulu website.