Skip to content

Commit

Permalink
✨ Brid player support for child JSON config (#38984)
Browse files Browse the repository at this point in the history
* Brid player support for child JSON config

* Brid player fix lint errors
  • Loading branch information
grajzer authored Aug 4, 2023
1 parent c6cf3c0 commit 3ecc395
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
16 changes: 13 additions & 3 deletions extensions/amp-brid-player/0.1/amp-brid-player.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {CONSENT_POLICY_STATE} from '#core/constants/consent-state';
import {Deferred} from '#core/data-structures/promise';
import {dispatchCustomEvent, removeElement} from '#core/dom';
import {
dispatchCustomEvent,
getChildJsonConfig,
removeElement,
} from '#core/dom';
import {
fullscreenEnter,
fullscreenExit,
Expand Down Expand Up @@ -124,8 +128,8 @@ class AmpBridPlayer extends AMP.BaseElement {
feedType = 'outstream';
}

//Create iframe
const src =
// Create iframe
let src =
'https://services.brid.tv/services/iframe/' +
encodeURIComponent(feedType) +
'/' +
Expand All @@ -138,6 +142,12 @@ class AmpBridPlayer extends AMP.BaseElement {
itemsNum +
'/?amp=1';

// Append child JSON config if supplied
try {
const customConfig = getChildJsonConfig(this.element);
src += '&cust_config=' + JSON.stringify(customConfig);
} catch (e) {}

this.videoIframeSrc_ = assertAbsoluteHttpOrHttpsUrl(src);

return this.videoIframeSrc_;
Expand Down
35 changes: 34 additions & 1 deletion extensions/amp-brid-player/0.1/test/test-amp-brid-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describes.realWin(
timer = Services.timerFor(win);
});

function getBridPlayer(attributes, opt_responsive) {
function getBridPlayer(attributes, opt_responsive, config) {
const bc = doc.createElement('amp-brid-player');

for (const key in attributes) {
Expand All @@ -34,6 +34,18 @@ describes.realWin(
bc.setAttribute('layout', 'responsive');
}

// create config element if provided
if (config) {
const configElement = doc.createElement('script');
configElement.setAttribute('type', 'application/json');
if (typeof config == 'string') {
configElement.textContent = config;
} else {
configElement.textContent = JSON.stringify(config);
}
bc.appendChild(configElement);
}

// see yt test implementation
timer
.promise(50)
Expand Down Expand Up @@ -152,6 +164,27 @@ describes.realWin(
});
});

it('config is passed', () => {
return getBridPlayer(
{
'data-partner': '264',
'data-player': '4144',
'data-video': '13663',
},
null,
{
'debug': 1,
}
).then((bc) => {
const iframe = bc.querySelector('iframe');
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}'
);
});
});

it('should forward events from brid-player to the amp element', async () => {
const bc = await getBridPlayer(
{
Expand Down

0 comments on commit 3ecc395

Please sign in to comment.