Skip to content
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

Updates to InlineAudio to support tts autoplay #39159

Merged
merged 1 commit into from Feb 24, 2021

Conversation

maureensturgeon
Copy link
Contributor

@maureensturgeon maureensturgeon commented Feb 19, 2021

Adds a new prop, ttsAutoplayEnabled to the InlineAudio component. When true, the audio will automatically play when the component mounts. If the audio autoplay fails to play because of a DOMException, listeners will be added to the specified element if it exists (props. autoplayTriggerElementId) or document to play audio after user interaction.

These changes are broken out from the larger group of changes needed to enable automatic TTS autoplay instructions. The full set of changes can be found here.

Links

Testing story

These changes were tested in the larger PR #38956. I turned on autoplay for a teacher's section, logged in as a student on Chrome, went to a lesson, checked that instructions were autoplaying. On reload there is a DOMException, I checked that interactions on the workspace trigger the instructions to play once.

I additionally verified on this branch that the InlineAudio still works with the new prop.

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@maureensturgeon maureensturgeon force-pushed the LP-1561/inline-audio-changes branch 2 times, most recently from a0437d9 to 349c4ad Compare February 23, 2021 22:16
@@ -90,6 +104,11 @@ class InlineAudio extends React.Component {
src: PropTypes.string,
message: PropTypes.string,
style: PropTypes.object,
ttsAutoplayEnabled: PropTypes.bool,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added, but not being set to true anywhere in the code yet

await component.instance().playAudio();
expect(component.state().playing).to.be.true;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted for 2 days to figure out how to stub the DOMException and check that playing audio starts up after the first user interaction but was getting a lot of trouble with the promises involved in that code path and tests not waiting on promises. I involved other engineers and ultimately decided it was not worth the time it was taking. Please forgive this slight lack of coverage.

@maureensturgeon maureensturgeon marked this pull request as ready for review February 23, 2021 22:34
@maureensturgeon maureensturgeon requested review from jamescodeorg and a team February 23, 2021 22:34
Copy link
Contributor

@cforkish cforkish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! a couple minor comments but nothing blocking.

apps/src/templates/instructions/InlineAudio.jsx Outdated Show resolved Hide resolved
apps/src/templates/instructions/InlineAudio.jsx Outdated Show resolved Hide resolved
apps/src/templates/instructions/InlineAudio.jsx Outdated Show resolved Hide resolved
apps/src/templates/instructions/InlineAudio.jsx Outdated Show resolved Hide resolved
apps/test/unit/templates/instructions/InlineAudioTest.js Outdated Show resolved Hide resolved
componentDidMount() {
this.getAudioElement();
if (this.props.ttsAutoplayEnabled && !this.state.autoplayed) {
const {autoplayTriggerElementId} = this.props;
this.autoplayTriggerElement = autoplayTriggerElementId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: i'm personally of the opinion that we should declare all instance properties in or under the constructor (depending on whether or not they need access to this) even when they start out as null as a sort of "directory" for future devs, so i'd recommend adding autoplayTriggerElement = null around line 33

@maureensturgeon maureensturgeon merged commit ab49d65 into staging Feb 24, 2021
@maureensturgeon maureensturgeon deleted the LP-1561/inline-audio-changes branch February 24, 2021 19:57
});
}

playAudio() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if playAudio() is called more than once? (I think there are some potential race conditions where this might happen?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants