Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AudioMixerEffect.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // @flow
  2. import JitsiMeetJS from '../../base/lib-jitsi-meet';
  3. import { MEDIA_TYPE } from '../../base/media';
  4. /**
  5. * Class Implementing the effect interface expected by a JitsiLocalTrack.
  6. * The AudioMixerEffect, as the name implies, mixes two JitsiLocalTracks containing a audio track. First track is
  7. * provided at the moment of creation, second is provided through the effect interface.
  8. */
  9. export class AudioMixerEffect {
  10. /**
  11. * JitsiLocalTrack that is going to be mixed into the track that uses this effect.
  12. */
  13. _mixAudio: Object;
  14. /**
  15. * lib-jitsi-meet AudioMixer.
  16. */
  17. _audioMixer: Object;
  18. /**
  19. * Creates AudioMixerEffect.
  20. *
  21. * @param {JitsiLocalTrack} mixAudio - JitsiLocalTrack which will be mixed with the original track.
  22. */
  23. constructor(mixAudio: Object) {
  24. if (mixAudio.getType() !== MEDIA_TYPE.AUDIO) {
  25. throw new Error('AudioMixerEffect only supports audio JitsiLocalTracks; effect will not work!');
  26. }
  27. this._mixAudio = mixAudio;
  28. }
  29. /**
  30. * Checks if the JitsiLocalTrack supports this effect.
  31. *
  32. * @param {JitsiLocalTrack} sourceLocalTrack - Track to which the effect will be applied.
  33. * @returns {boolean} - Returns true if this effect can run on the specified track, false otherwise.
  34. */
  35. isEnabled(sourceLocalTrack: Object) {
  36. // Both JitsiLocalTracks need to be audio i.e. contain an audio MediaStreamTrack
  37. return sourceLocalTrack.isAudioTrack() && this._mixAudio.isAudioTrack();
  38. }
  39. /**
  40. * Effect interface called by source JitsiLocalTrack, At this point a WebAudio ChannelMergerNode is created
  41. * and and the two associated MediaStreams are connected to it; the resulting mixed MediaStream is returned.
  42. *
  43. * @param {MediaStream} audioStream - Audio stream which will be mixed with _mixAudio.
  44. * @returns {MediaStream} - MediaStream containing both audio tracks mixed together.
  45. */
  46. startEffect(audioStream: MediaStream) {
  47. this._audioMixer = JitsiMeetJS.createAudioMixer();
  48. this._audioMixer.addMediaStream(this._mixAudio.getOriginalStream());
  49. this._audioMixer.addMediaStream(audioStream);
  50. return this._audioMixer.start();
  51. }
  52. /**
  53. * Reset the AudioMixer stopping it in the process.
  54. *
  55. * @returns {void}
  56. */
  57. stopEffect() {
  58. this._audioMixer.reset();
  59. }
  60. }