|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+import * as JitsiConferenceEvents from '../JitsiConferenceEvents';
|
|
|
2
|
+
|
|
|
3
|
+/**
|
|
|
4
|
+ * The value which we use to say, every sound over this threshold
|
|
|
5
|
+ * is talking on the mic.
|
|
|
6
|
+ * @type {number}
|
|
|
7
|
+ */
|
|
|
8
|
+const SPEECH_DETECT_THRESHOLD = 0.6;
|
|
|
9
|
+
|
|
|
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
|
+ /**
|
|
|
20
|
+ * Creates P2PDominantSpeakerDetection
|
|
|
21
|
+ * @param conference the JitsiConference instance that created us.
|
|
|
22
|
+ * @constructor
|
|
|
23
|
+ */
|
|
|
24
|
+ constructor(conference) {
|
|
|
25
|
+ this.conference = conference;
|
|
|
26
|
+
|
|
|
27
|
+ conference.addEventListener(
|
|
|
28
|
+ JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
|
|
|
29
|
+ this._audioLevel.bind(this));
|
|
|
30
|
+
|
|
|
31
|
+ this.myUserID = this.conference.myUserId();
|
|
|
32
|
+ }
|
|
|
33
|
+
|
|
|
34
|
+ /**
|
|
|
35
|
+ * Receives audio level events for all streams in the conference.
|
|
|
36
|
+ *
|
|
|
37
|
+ * @param {String} id - The participant id
|
|
|
38
|
+ * @param {number} audioLevel - The audio level.
|
|
|
39
|
+ */
|
|
|
40
|
+ _audioLevel(id, audioLevel) {
|
|
|
41
|
+
|
|
|
42
|
+ // we do not process if p2p is not active
|
|
|
43
|
+ // or audio level is under certain threshold
|
|
|
44
|
+ // or if the audio level is for local audio track which is muted
|
|
|
45
|
+ if (!this.conference.isP2PActive()
|
|
|
46
|
+ || audioLevel <= SPEECH_DETECT_THRESHOLD
|
|
|
47
|
+ || (id === this.myUserID
|
|
|
48
|
+ && this.conference.getLocalAudioTrack().isMuted())) {
|
|
|
49
|
+ return;
|
|
|
50
|
+ }
|
|
|
51
|
+
|
|
|
52
|
+ this.conference.eventEmitter.emit(
|
|
|
53
|
+ JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
|
|
|
54
|
+ id);
|
|
|
55
|
+ }
|
|
|
56
|
+}
|