Skip to content

Commit

Permalink
✨[amp-story-player] Install viewer integration script when inside the…
Browse files Browse the repository at this point in the history
… player (#26719)

* install viewer integration script when inside the player

* wip

* add private in jsdoc

* Revert "wip"

This reverts commit 3e9e741.

* provide a default handler to remove errors
  • Loading branch information
Enriqe authored Feb 11, 2020
1 parent 9ef9811 commit eb4c20b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 16 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ export class AmpStory extends AMP.BaseElement {
.then(() => {
this.markStoryAsLoaded_();
this.initializeLiveStory_();
this.initializeStoryPlayer_();
});

// Story is being prerendered: resolve the layoutCallback when the first
Expand Down Expand Up @@ -1287,6 +1288,21 @@ export class AmpStory extends AMP.BaseElement {
activePage.next(opt_isAutomaticAdvance);
}

/**
* Installs amp-viewer-integration script in case story is inside an
* amp-story-player.
* @private
*/
initializeStoryPlayer_() {
if (this.viewer_.getParam('storyPlayer') !== 'v0') {
return;
}
Services.extensionsFor(this.getAmpDoc().win).installExtensionForDoc(
this.getAmpDoc(),
'amp-viewer-integration'
);
}

/**
* Handles EventType.NO_NEXT_PAGE events.
* @private
Expand Down
12 changes: 6 additions & 6 deletions src/amp-story-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,15 @@ export class AmpStoryPlayer {
this.initializeLoadingListeners_(iframeEl);
this.rootEl_.appendChild(iframeEl);

// TODO(#26308): enable messaging when multiple documents are supported.
return;

this.initializeHandshake_(story, iframeEl).then(
messaging => {
const iframeIdx = findIndex(
this.iframes_,
iframe => iframe === iframeEl
);

messaging.setDefaultHandler(() => {});

this.messagingFor_[iframeIdx] = messaging;

// TODO(#26308): Appropiately set visibility to stories.
Expand Down Expand Up @@ -206,10 +205,9 @@ export class AmpStoryPlayer {
* @private
*/
layoutIframe_(story, iframe) {
// TODO(#26308): enable messaging when multiple documents are supported.
// const {href} = this.getEncodedLocation_(story.href);
const {href} = this.getEncodedLocation_(story.href);

iframe.setAttribute('src', story.href);
iframe.setAttribute('src', href);
}

/**
Expand All @@ -226,6 +224,8 @@ export class AmpStoryPlayer {
'amp_js_v': '0.1',
'visibilityState': 'inactive',
'origin': url.origin,
'showStoryUrlInfo': '0',
'storyPlayer': 'v0',
});

const fragmentParam = getFragment(href);
Expand Down

0 comments on commit eb4c20b

Please sign in to comment.