Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* @flow */
  2. import Sound from 'react-native-sound';
  3. import AbstractAudio from '../AbstractAudio';
  4. const logger = require('jitsi-meet-logger').getLogger(__filename);
  5. /**
  6. * The React Native/mobile {@link Component} which is similar to Web's
  7. * {@code HTMLAudioElement} and wraps around react-native-webrtc's
  8. * {@link RTCView}.
  9. */
  10. export default class Audio extends AbstractAudio {
  11. /**
  12. * Reference to 'react-native-sound} {@link Sound} instance.
  13. */
  14. _sound: Sound
  15. /**
  16. * A callback passed to the 'react-native-sound''s {@link Sound} instance,
  17. * called when loading sound is finished.
  18. *
  19. * @param {Object} error - The error object passed by
  20. * the 'react-native-sound' library.
  21. * @returns {void}
  22. * @private
  23. */
  24. _soundLoadedCallback(error) {
  25. if (error) {
  26. logger.error('Failed to load sound', error);
  27. } else {
  28. this.setAudioElementImpl(this._sound);
  29. }
  30. }
  31. /**
  32. * Will load the sound, after the component did mount.
  33. *
  34. * @returns {void}
  35. */
  36. componentDidMount() {
  37. this._sound
  38. = this.props.src
  39. ? new Sound(
  40. this.props.src,
  41. this._soundLoadedCallback.bind(this))
  42. : null;
  43. }
  44. /**
  45. * Will dispose sound resources (if any) when component is about to unmount.
  46. *
  47. * @returns {void}
  48. */
  49. componentWillUnmount() {
  50. if (this._sound) {
  51. this.setAudioElementImpl(null);
  52. this._sound.release();
  53. this._sound = null;
  54. }
  55. }
  56. /**
  57. * Implements React's {@link Component#render()}.
  58. *
  59. * @inheritdoc
  60. * @returns {null}
  61. */
  62. render() {
  63. // TODO react-native-webrtc's RTCView doesn't do anything with the audio
  64. // MediaStream specified to it so it's easier at the time of this
  65. // writing to not render anything.
  66. return null;
  67. }
  68. }