|
@@ -0,0 +1,58 @@
|
|
1
|
+var JitsiTrackEvents = require('../../JitsiTrackEvents');
|
|
2
|
+
|
|
3
|
+/**
|
|
4
|
+ * Creates TalkMutedDetection
|
|
5
|
+ * @param callback the callback to call when detected local user is talking
|
|
6
|
+ * while its microphone is muted.
|
|
7
|
+ * @constructor
|
|
8
|
+ */
|
|
9
|
+function TalkMutedDetection(callback) {
|
|
10
|
+ this.callback = callback;
|
|
11
|
+
|
|
12
|
+ // we track firing the event, in order to avoid sending too many events
|
|
13
|
+ this.eventFired = false;
|
|
14
|
+}
|
|
15
|
+
|
|
16
|
+/**
|
|
17
|
+ * Receives audio level events for all send/receive streams.
|
|
18
|
+ * @param ssrc the ssrc of the stream
|
|
19
|
+ * @param level the current audio level
|
|
20
|
+ * @param isLocal whether this is local or remote stream (sent or received)
|
|
21
|
+ */
|
|
22
|
+TalkMutedDetection.prototype.audioLevelListener =
|
|
23
|
+ function (ssrc, level, isLocal) {
|
|
24
|
+ // we are interested only in local audio stream
|
|
25
|
+ // and if event is not already sent
|
|
26
|
+ if (!isLocal || !this.audioTrack || this.eventFired)
|
|
27
|
+ return;
|
|
28
|
+
|
|
29
|
+ if (this.audioTrack.isMuted() && level > 0.02) {
|
|
30
|
+ this.eventFired = true;
|
|
31
|
+ this.callback();
|
|
32
|
+ }
|
|
33
|
+ };
|
|
34
|
+
|
|
35
|
+/**
|
|
36
|
+ * Mute changed for a track.
|
|
37
|
+ * @param track the track which mute state has changed.
|
|
38
|
+ */
|
|
39
|
+TalkMutedDetection.prototype.muteChanged = function (track) {
|
|
40
|
+ if (!track.isLocal() || !track.isAudioTrack())
|
|
41
|
+ return;
|
|
42
|
+
|
|
43
|
+ if (track.isMuted())
|
|
44
|
+ this.eventFired = false;
|
|
45
|
+};
|
|
46
|
+
|
|
47
|
+/**
|
|
48
|
+ * Adds local tracks. We are interested only in the audio one.
|
|
49
|
+ * @param track
|
|
50
|
+ */
|
|
51
|
+TalkMutedDetection.prototype.addTrack = function(track){
|
|
52
|
+ if (!track.isAudioTrack())
|
|
53
|
+ return;
|
|
54
|
+
|
|
55
|
+ this.audioTrack = track;
|
|
56
|
+};
|
|
57
|
+
|
|
58
|
+module.exports = TalkMutedDetection;
|