✨ [Story player] Re-emit captions state to host page#3
Closed
michaeldegori wants to merge 1 commit into
Closed
Conversation
Mirrors the existing amp-story-muted-state re-emit so host pages
embedding an amp-story can observe when the user toggles captions
inside the story.
* Adds CAPTIONS_STATE to STORY_MESSAGE_STATE_TYPE_ENUM.
* Subscribes to captions-state updates on handshake, alongside
muted-state.
* Routes inbound documentStateUpdate messages for CAPTIONS_STATE to
a new onCaptionsStateUpdate_ handler that dispatches an
'amp-story-captions-state' custom event with a {captions} detail
payload, matching the muted-state detail-key convention.
* Documents the new event in docs/spec/amp-story-player.md and
covers the on/off dispatch with two unit tests.
Owner
Author
|
Superseded by upstream PR ampproject#40506. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ [Story player] Re-emit captions state to host page
Summary
Adds
<amp-story-player>re-emit of caption-state changes so host pages embedding an amp-story can listen for caption toggles, mirroring the existingamp-story-muted-stateevent.Why
The player already bridges muted-state from the embedded story to the host element:
Caption-state is a parallel user-toggleable media state in the story (now also analytics-traced as of the captions-analytics PR), but the player does not re-emit it. Host pages embedding an amp-story can't observe caption toggles. This PR adds that bridge.
Changes
src/amp-story-player/amp-story-player-impl.js— four small additions mirroring the muted-state plumbing:CAPTIONS_STATE: 'CAPTIONS_STATE'inSTORY_MESSAGE_STATE_TYPE_ENUM.messaging.sendRequest('onDocumentState', ...)subscription on handshake, next to the muted-state one.casein theonDocumentStateUpdate_switch, routing inboundCAPTIONS_STATEmessages.onCaptionsStateUpdate_(captions)that dispatches anamp-story-captions-stateCustomEventon the player element with{captions}detail.docs/spec/amp-story-player.md— documents the new event in the same voice asamp-story-muted-state.test/unit/test-amp-story-player.js— two new tests covering the on/off dispatch, mirroring the existing muted-state tests verbatim.Public API shape
Naming notes
amp-story-captions-statematches theamp-story-muted-stateprecedent.captions(notcaptionsState) matches the muted-state external API which drops the_STATEsuffix (MUTED_STATE→event.detail.muted). The internal store key inamp-storyiscaptionsState, but the external event surface keeps parity with muted.CAPTIONS_STATEmatchesMUTED_STATEstyle.Out of scope (intentional follow-up)
This PR is story → host re-emit only. It does not add a host → story push direction analogous to
updateMutedState_/player.mute()/player.unmute()(lines 1472-1478 + 279-280 inamp-story-player-impl.js). The receiving side already exists in amp-story (the store acceptssetDocumentStateforCAPTIONS_STATE), so anupdateCaptionsState_+player.toggleCaptions()follow-up is mechanical if reviewers want it; my use case is host-side observation only, so I kept the diff minimal. Happy to add the push side in a separate PR.Test plan
npx eslintclean on touched filesamp unit --files=test/unit/test-amp-story-player.js— 2 new tests pass; 84 of 85 tests green (the one failure,revert navigation animation after transition ends, is a pre-existing flake on cleanupstream/mainunrelated to this diff — verified by stashing the changes and rerunning)amp-story-captions-statelistener