選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

P2PDominantSpeakerDetection.js 1.8KB

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