|
@@ -17,56 +17,94 @@ export default class TalkMutedDetection {
|
17
|
17
|
*/
|
18
|
18
|
this._callback = callback;
|
19
|
19
|
|
|
20
|
+ /**
|
|
21
|
+ * The indicator which determines whether <tt>callback</tt> has been
|
|
22
|
+ * invoked for the current local audio track of <tt>conference</tt> so
|
|
23
|
+ * that it is invoked once only.
|
|
24
|
+ *
|
|
25
|
+ * @private
|
|
26
|
+ */
|
|
27
|
+ this._eventFired = false;
|
|
28
|
+
|
|
29
|
+ // XXX I went back and forth on the subject of where to put the access
|
|
30
|
+ // to statistics. On the one had, (1) statistics is likely intended to
|
|
31
|
+ // be private to conference and (2) there is a desire to keep the
|
|
32
|
+ // dependencies of modules to the minimum (i.e. not have
|
|
33
|
+ // TalkMutedDetection depend on statistics). On the other hand, (1)
|
|
34
|
+ // statistics is technically not private because
|
|
35
|
+ // JitsiConferenceEventManager accesses it and (2) TalkMutedDetection
|
|
36
|
+ // works exactly because it knows that there are no audio levels for
|
|
37
|
+ // JitsiLocalTrack but there are audio levels for the local participant
|
|
38
|
+ // through statistics.
|
20
|
39
|
conference.statistics.addAudioLevelListener(
|
21
|
|
- this.audioLevelListener.bind(this));
|
|
40
|
+ this._audioLevel.bind(this));
|
|
41
|
+
|
22
|
42
|
conference.on(
|
23
|
43
|
JitsiConferenceEvents.TRACK_MUTE_CHANGED,
|
24
|
44
|
this._trackMuteChanged.bind(this));
|
25
|
45
|
conference.on(
|
26
|
46
|
JitsiConferenceEvents.TRACK_ADDED,
|
27
|
47
|
this._trackAdded.bind(this));
|
28
|
|
-
|
29
|
|
- // we track firing the event, in order to avoid sending too many events
|
30
|
|
- this.eventFired = false;
|
31
|
48
|
}
|
32
|
49
|
|
33
|
50
|
/**
|
34
|
|
- * Receives audio level events for all send/receive streams.
|
35
|
|
- * @param ssrc the ssrc of the stream
|
36
|
|
- * @param level the current audio level
|
37
|
|
- * @param isLocal whether this is local or remote stream (sent or received)
|
|
51
|
+ * Receives audio level events for all send and receive streams.
|
|
52
|
+ *
|
|
53
|
+ * @param ssrc - The synchronization source identifier (SSRC) of the
|
|
54
|
+ * endpoint/participant/stream being reported.
|
|
55
|
+ * @param {number} audioLevel - The audio level of <tt>ssrc</tt>.
|
|
56
|
+ * @param {boolean} isLocal - <tt>true</tt> if <tt>ssrc</tt> represents a
|
|
57
|
+ * local/send stream or <tt>false</tt> for a remote/receive stream.
|
38
|
58
|
*/
|
39
|
|
- audioLevelListener(ssrc, level, isLocal) {
|
40
|
|
- // we are interested only in local audio stream
|
41
|
|
- // and if event is not already sent
|
42
|
|
- if (!isLocal || !this.audioTrack || this.eventFired)
|
|
59
|
+ _audioLevel(ssrc, audioLevel, isLocal) {
|
|
60
|
+ // We are interested in the local audio stream only and if event is not
|
|
61
|
+ // sent yet.
|
|
62
|
+ if (!isLocal || !this.audioTrack || this._eventFired)
|
43
|
63
|
return;
|
44
|
64
|
|
45
|
|
- if (this.audioTrack.isMuted() && level > 0.6) {
|
46
|
|
- this.eventFired = true;
|
|
65
|
+ if (this.audioTrack.isMuted() && audioLevel > 0.6) {
|
|
66
|
+ this._eventFired = true;
|
47
|
67
|
this._callback();
|
48
|
68
|
}
|
49
|
69
|
}
|
50
|
70
|
|
51
|
71
|
/**
|
52
|
|
- * Adds local tracks. We are interested only in the audio one.
|
53
|
|
- * @param track
|
|
72
|
+ * Determines whether a specific {@link JitsiTrack} represents a local audio
|
|
73
|
+ * track.
|
|
74
|
+ *
|
|
75
|
+ * @param {JitsiTrack} track - The <tt>JitsiTrack</tt> to be checked whether
|
|
76
|
+ * it represents a local audio track.
|
54
|
77
|
* @private
|
|
78
|
+ * @return {boolean} - <tt>true</tt> if the specified <tt>track</tt>
|
|
79
|
+ * represents a local audio track; otherwise, <tt>false</tt>.
|
55
|
80
|
*/
|
56
|
|
- _trackAdded(track) {
|
57
|
|
- if (!track.isAudioTrack() || !track.isLocal())
|
58
|
|
- return;
|
|
81
|
+ _isLocalAudioTrack(track) {
|
|
82
|
+ return track.isAudioTrack() && track.isLocal();
|
|
83
|
+ }
|
59
|
84
|
|
60
|
|
- this.audioTrack = track;
|
|
85
|
+ /**
|
|
86
|
+ * Notifies this <tt>TalkMutedDetection</tt> that a {@link JitsiTrack} was
|
|
87
|
+ * added to the associated {@link JitsiConference}. Looks for the local
|
|
88
|
+ * audio track only.
|
|
89
|
+ *
|
|
90
|
+ * @param {JitsiTrack} track - The added <tt>JitsiTrack</tt>.
|
|
91
|
+ * @private
|
|
92
|
+ */
|
|
93
|
+ _trackAdded(track) {
|
|
94
|
+ if (this._isLocalAudioTrack(track))
|
|
95
|
+ this.audioTrack = track;
|
61
|
96
|
}
|
62
|
97
|
|
63
|
98
|
/**
|
64
|
|
- * Mute changed for a track.
|
65
|
|
- * @param track the track which mute state has changed.
|
|
99
|
+ * Notifies this <tt>TalkMutedDetection</tt> that the mute state of a
|
|
100
|
+ * {@link JitsiTrack} has changed. Looks for the local audio track only.
|
|
101
|
+ *
|
|
102
|
+ * @param {JitsiTrack} track - The <tt>JitsiTrack</tt> whose mute state has
|
|
103
|
+ * changed.
|
66
|
104
|
* @private
|
67
|
105
|
*/
|
68
|
106
|
_trackMuteChanged(track) {
|
69
|
|
- if (track.isLocal() && track.isAudioTrack() && track.isMuted())
|
70
|
|
- this.eventFired = false;
|
|
107
|
+ if (this._isLocalAudioTrack(track) && track.isMuted())
|
|
108
|
+ this._eventFired = false;
|
71
|
109
|
}
|
72
|
110
|
}
|