You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Audio.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React, { Component } from 'react';
  2. /**
  3. * The React equivalent of Web's audio element.
  4. *
  5. * @extends Component
  6. */
  7. export class Audio extends Component {
  8. /**
  9. * Implements React's {@link Component#render()}.
  10. *
  11. * @inheritdoc
  12. * @returns {ReactElement}
  13. */
  14. render() {
  15. // TODO URL.releaseObjectURL on componentDid/WillUnmount
  16. const src = this.props.stream
  17. ? URL.createObjectURL(this.props.stream)
  18. : '';
  19. return (
  20. <audio
  21. autoPlay = { true }
  22. muted = { this.props.muted }
  23. src = { src } />
  24. );
  25. }
  26. /**
  27. * Implements shouldComponentUpdate of React Component. We don't update
  28. * component if stream has not changed.
  29. *
  30. * @inheritdoc
  31. * @param {Object} nextProps - Props that component is going to receive.
  32. * @returns {boolean}
  33. */
  34. shouldComponentUpdate(nextProps) {
  35. return (nextProps.stream || {}).id !== (this.props.stream || {}).id;
  36. }
  37. }
  38. /**
  39. * Audio component's property types.
  40. *
  41. * @static
  42. */
  43. Audio.propTypes = {
  44. muted: React.PropTypes.bool,
  45. stream: React.PropTypes.object
  46. };