Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

P2PDominantSpeakerDetection.ts 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import JitsiConference from '../../JitsiConference';
  2. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
  3. import RTCEvents from '../../service/RTC/RTCEvents';
  4. /**
  5. * The value which we use to say, every sound over this threshold
  6. * is talking on the mic.
  7. * @type {number}
  8. */
  9. const SPEECH_DETECT_THRESHOLD: number = 0.6;
  10. /**
  11. * The <tt>P2PDominantSpeakerDetection</tt> is activated only when p2p is
  12. * currently used.
  13. * Listens for changes in the audio level changes of the local p2p audio track
  14. * or remote p2p one and fires dominant speaker events to be able to use
  15. * features depending on those events (speaker stats), to make them work without
  16. * the video bridge.
  17. */
  18. export default class P2PDominantSpeakerDetection {
  19. private conference: JitsiConference;
  20. private myUserID: string;
  21. /**
  22. * Creates P2PDominantSpeakerDetection
  23. * @param conference the JitsiConference instance that created us.
  24. * @constructor
  25. */
  26. constructor(conference: JitsiConference) {
  27. this.conference = conference;
  28. conference.addEventListener(
  29. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  30. this._audioLevel.bind(this));
  31. this.myUserID = this.conference.myUserId();
  32. }
  33. /**
  34. * Receives audio level events for all streams in the conference.
  35. *
  36. * @param {String} id - The participant id
  37. * @param {number} audioLevel - The audio level.
  38. */
  39. private _audioLevel(id: string, audioLevel: number): void {
  40. // we do not process if p2p is not active
  41. // or audio level is under certain threshold
  42. // or if the audio level is for local audio track which is muted
  43. if (!this.conference.isP2PActive()
  44. || audioLevel <= SPEECH_DETECT_THRESHOLD
  45. || (id === this.myUserID
  46. && this.conference.getLocalAudioTrack().isMuted())) {
  47. return;
  48. }
  49. this.conference.rtc.eventEmitter.emit(
  50. RTCEvents.DOMINANT_SPEAKER_CHANGED,
  51. id);
  52. }
  53. }