Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions extensions/amp-brid-player/0.1/amp-brid-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '#core/dom/fullscreen';
import {applyFillContent, isLayoutSizeDefined} from '#core/dom/layout';
import {propagateAttributes} from '#core/dom/propagate-attributes';
import {childElementsByTag} from '#core/dom/query';
import {htmlFor} from '#core/dom/static-template';
import {PauseHelper} from '#core/dom/video/pause-helper';

Expand Down Expand Up @@ -143,10 +144,15 @@ class AmpBridPlayer extends AMP.BaseElement {
'/?amp=1';

// Append child JSON config if supplied
try {
const customConfig = getChildJsonConfig(this.element);
src += '&cust_config=' + JSON.stringify(customConfig);
} catch (e) {}
if (childElementsByTag(this.element, 'script').length) {
try {
const customConfig = getChildJsonConfig(this.element);
src +=
'&cust_config=' + encodeURIComponent(JSON.stringify(customConfig));
} catch (e) {
this.user().warn(TAG, 'Ignoring the <script> config:', e.message);
}
}

this.videoIframeSrc_ = assertAbsoluteHttpOrHttpsUrl(src);

Expand Down
90 changes: 84 additions & 6 deletions extensions/amp-brid-player/0.1/test/test-amp-brid-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '../amp-brid-player';
import {Services} from '#service';

import {listenOncePromise} from '#utils/event-helper';
import {user} from '#utils/log';

import {VideoEvents_Enum} from '../../../../src/video-interface';

Expand Down Expand Up @@ -36,14 +37,15 @@ describes.realWin(
bc.setAttribute('layout', 'responsive');
}

// create config element if provided
if (config) {
// create config element(s) if provided
const configs = config ? [].concat(config) : [];
for (const c of configs) {
const configElement = doc.createElement('script');
configElement.setAttribute('type', 'application/json');
if (typeof config == 'string') {
configElement.textContent = config;
if (typeof c == 'string') {
configElement.textContent = c;
} else {
configElement.textContent = JSON.stringify(config);
configElement.textContent = JSON.stringify(c);
}
bc.appendChild(configElement);
}
Expand Down Expand Up @@ -202,11 +204,87 @@ describes.realWin(
expect(iframe).to.not.be.null;
expect(iframe.tagName).to.equal('IFRAME');
expect(iframe.src).to.equal(
'https://services.brid.tv/services/iframe/video/13663/264/4144/0/1/?amp=1&cust_config={%22debug%22:1}'
'https://services.brid.tv/services/iframe/video/13663/264/4144/0/1/?amp=1&cust_config=%7B%22debug%22%3A1%7D'
);
});
});

it('config is passed for alias', () => {
return getBridPlayer(
{
'data-partner': '264',
'data-player': '4144',
'data-video': '13663',
},
null,
{
'debug': 1,
},
true
).then((bc) => {
const iframe = bc.querySelector('iframe');
expect(iframe.src).to.equal(
'https://services.brid.tv/services/iframe/video/13663/264/4144/0/1/?amp=1&cust_config=%7B%22debug%22%3A1%7D'
);
});
});

it('URL-encodes reserved characters in the config', () => {
const config = {'title': 'a&b=c#d+e%f'};
return getBridPlayer(
{
'data-partner': '264',
'data-player': '4144',
'data-video': '13663',
},
null,
config
).then((bc) => {
const url = new URL(bc.querySelector('iframe').src);
expect(url.hash).to.equal('');
expect(Array.from(url.searchParams.keys())).to.deep.equal([
'amp',
'cust_config',
]);
expect(url.searchParams.get('cust_config')).to.equal(
JSON.stringify(config)
);
});
});

it('ignores the config and warns with multiple <script> children', () => {
const warn = env.sandbox.stub(user(doc.body), 'warn');
return getBridPlayer(
{
'data-partner': '264',
'data-player': '4144',
'data-video': '13663',
},
null,
[{'debug': 1}, {'debug': 2}]
).then((bc) => {
expect(bc.querySelector('iframe').src).to.equal(
'https://services.brid.tv/services/iframe/video/13663/264/4144/0/1/?amp=1'
);
expect(warn).to.have.been.calledOnceWith(
'amp-brid-player',
'Ignoring the <script> config:',
'Found 2 <script> children. Expected 1.'
);
});
});

it('does not warn without a <script> child', () => {
const warn = env.sandbox.stub(user(doc.body), 'warn');
return getBridPlayer({
'data-partner': '264',
'data-player': '4144',
'data-video': '13663',
}).then(() => {
expect(warn).to.not.have.been.called;
});
});

it('should forward events from brid-player to the amp element', async () => {
const bc = await getBridPlayer(
{
Expand Down
56 changes: 56 additions & 0 deletions extensions/amp-brid-player/0.1/test/validator-amp-brid-player.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,61 @@
layout="responsive"
width="480" height="270">
</amp-brid-player>
<!-- Valid example with a JSON config child. -->
<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
<script type="application/json">{"debug": 1}</script>
</amp-brid-player>
<!-- Valid amp-target-video-player example with a JSON config child. -->
<amp-target-video-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
<script type="application/json">{"debug": 1}</script>
</amp-target-video-player>
<!-- Invalid: JSON config child with the wrong type. -->
<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
<script type="text/plain">{"debug": 1}</script>
</amp-brid-player>
<!-- Invalid: HTML comment in the JSON config child. -->
<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
<script type="application/json">{"title": "<!--"}</script>
</amp-brid-player>
<!-- Invalid: JSON config child nested inside a div. -->
<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
<div>
<script type="application/json">{"debug": 1}</script>
</div>
</amp-brid-player>
<!-- Invalid: JSON config child with a src attribute. -->
<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480" height="270">
<script type="application/json" src="https://example.com/config.json"></script>
</amp-brid-player>
</body>
</html>
64 changes: 64 additions & 0 deletions extensions/amp-brid-player/0.1/test/validator-amp-brid-player.out
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,69 @@ amp-brid-player/0.1/test/validator-amp-brid-player.html:72:2 The attribute 'dock
| layout="responsive"
| width="480" height="270">
| </amp-brid-player>
| <!-- Valid example with a JSON config child. -->
| <amp-brid-player
| data-partner="264"
| data-player="4144"
| data-video="13663"
| layout="responsive"
| width="480" height="270">
| <script type="application/json">{"debug": 1}</script>
| </amp-brid-player>
| <!-- Valid amp-target-video-player example with a JSON config child. -->
| <amp-target-video-player
| data-partner="264"
| data-player="4144"
| data-video="13663"
| layout="responsive"
| width="480" height="270">
| <script type="application/json">{"debug": 1}</script>
| </amp-target-video-player>
| <!-- Invalid: JSON config child with the wrong type. -->
| <amp-brid-player
| data-partner="264"
| data-player="4144"
| data-video="13663"
| layout="responsive"
| width="480" height="270">
| <script type="text/plain">{"debug": 1}</script>
>> ^~~~~~~~~
amp-brid-player/0.1/test/validator-amp-brid-player.html:105:4 The parent tag of tag 'amphtml engine script' is 'amp-brid-player', but it can only be 'head'. (see https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/#required-markup)
| </amp-brid-player>
| <!-- Invalid: HTML comment in the JSON config child. -->
| <amp-brid-player
| data-partner="264"
| data-player="4144"
| data-video="13663"
| layout="responsive"
| width="480" height="270">
| <script type="application/json">{"title": "<!--"}</script>
>> ^~~~~~~~~
amp-brid-player/0.1/test/validator-amp-brid-player.html:114:4 The text inside tag 'script' contains 'html comments', which is disallowed. (see https://amp.dev/documentation/components/amp-brid-player/)
| </amp-brid-player>
| <!-- Invalid: JSON config child nested inside a div. -->
| <amp-brid-player
| data-partner="264"
| data-player="4144"
| data-video="13663"
| layout="responsive"
| width="480" height="270">
| <div>
| <script type="application/json">{"debug": 1}</script>
>> ^~~~~~~~~
amp-brid-player/0.1/test/validator-amp-brid-player.html:124:6 The parent tag of tag 'amphtml engine script' is 'div', but it can only be 'head'. (see https://amp.dev/documentation/guides-and-tutorials/learn/spec/amphtml/#required-markup)
| </div>
| </amp-brid-player>
| <!-- Invalid: JSON config child with a src attribute. -->
| <amp-brid-player
| data-partner="264"
| data-player="4144"
| data-video="13663"
| layout="responsive"
| width="480" height="270">
| <script type="application/json" src="https://example.com/config.json"></script>
>> ^~~~~~~~~
amp-brid-player/0.1/test/validator-amp-brid-player.html:134:4 The attribute 'src' may not appear in tag 'script'. (see https://amp.dev/documentation/components/amp-brid-player/)
| </amp-brid-player>
| </body>
| </html>
50 changes: 41 additions & 9 deletions extensions/amp-brid-player/amp-brid-player.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ $category@: media
formats:
- websites
teaser:
text: Displays a Brid.tv player.
text: Displays a TargetVideo player.
---

# amp-brid-player

An `amp-brid-player` displays the Brid Player used in [Brid.tv](https://www.brid.tv/) Video Platform.
An `amp-brid-player` displays the TargetVideo player (formerly Brid Player) used in the [TargetVideo](https://target-video.com/) video platform.

It is also available as `amp-target-video-player`, which takes the same
attributes. Both tag names come from the `amp-brid-player` extension, so a page
that uses `amp-target-video-player` still needs the
`<script async custom-element="amp-brid-player" ...>` extension script.

The `width` and `height` attributes determine the aspect ratio of the player embedded in responsive layouts.

Expand Down Expand Up @@ -40,30 +45,30 @@ If this attribute is present, and the browser supports autoplay:

### `data-partner`

The Brid.tv partner ID.
The TargetVideo partner ID.

### `data-player`

The Brid.tv player ID. Specific to every partner.
The TargetVideo player ID. Specific to every partner.

### `data-video`

The Brid.tv video ID. Embed code must either have `video`, `playlist`, `carousel`
The TargetVideo video ID. Embed code must either have `video`, `playlist`, `carousel`
or `outstream` attribute.

### `data-playlist`

The Brid.tv playlist ID or custom string value for dynamic playlists. Embed code
The TargetVideo playlist ID or custom string value for dynamic playlists. Embed code
must either have `video`, `playlist`, `carousel` or `outstream` attribute.

### `data-carousel`

The Brid.tv carousel ID. Embed code must either have `video`, `playlist`, `carousel`
The TargetVideo carousel ID. Embed code must either have `video`, `playlist`, `carousel`
or `outstream` attribute.

### `data-outstream`

The Brid.tv outstream unit ID. Embed code must either have `video`, `playlist`, `carousel`
The TargetVideo outstream unit ID. Embed code must either have `video`, `playlist`, `carousel`
or `outstream` attribute.

### `data-dynamic`
Expand All @@ -83,6 +88,33 @@ For more details, see [documentation on the docking extension itself](https://am
This element includes [common attributes](https://amp.dev/documentation/guides-and-tutorials/learn/common_attributes)
extended to AMP components.

## Custom configuration

Additional player configuration can be supplied as a JSON object in a
`<script type="application/json">` child element. The component forwards it to
the player iframe. For the available options, see TargetVideo's
[embed options](https://docs.target-video.com/v1.0/docs/embed-options).

Use a single `<script>` child. If there is more than one, or its content is not
valid JSON, the configuration is ignored and a warning is logged to the console.

```html
<amp-brid-player
data-partner="264"
data-player="4144"
data-video="13663"
layout="responsive"
width="480"
height="270"
>
<script type="application/json">
{
"debug": 1
}
</script>
</amp-brid-player>
```

## Actions

### `play`
Expand All @@ -107,4 +139,4 @@ Takes the video to fullscreen.

## Validation

See [amp-brid-player rules](https://github.com/ampproject/amphtml/blob/main/extensions/amp-brid-player/validator-amp-brid-player.protoascii) in the AMP validator specification.
See [amp-brid-player rules](validator-amp-brid-player.protoascii) in the AMP validator specification.
Loading
Loading