Sfoglia il codice sorgente

Adds talk muted detection.

Fires event only once when the user is muted, if he unmutes and then mutes back again a new event will be fired if local talking is detected.
dev1
damencho 8 anni fa
parent
commit
7dc40c9d25
1 ha cambiato i file con 58 aggiunte e 0 eliminazioni
  1. 58
    0
      modules/talkmuted/TalkMutedDetection.js

+ 58
- 0
modules/talkmuted/TalkMutedDetection.js Vedi File

@@ -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;

Loading…
Annulla
Salva