Explorar el Código

Changes talk while muted to listen for track events.

JitsiConference passed in the constructor and adding all events happen inside the feature.
dev1
damencho hace 9 años
padre
commit
1f362466e9
Se han modificado 2 ficheros con 17 adiciones y 20 borrados
  1. 3
    13
      JitsiConference.js
  2. 14
    7
      modules/talkmuted/TalkMutedDetection.js

+ 3
- 13
JitsiConference.js Ver fichero

@@ -119,16 +119,9 @@ JitsiConference.prototype._init = function (options) {
119 119
     this.eventManager.setupStatisticsListeners();
120 120
 
121 121
     if (this.options.config.enableTalkWhileMuted) {
122
-        this.talkMutedDetection
123
-            = new TalkMutedDetection(() => {
124
-                this.eventEmitter.emit(JitsiConferenceEvents.TALK_WHILE_MUTED);
125
-            });
126
-        this.statistics.addAudioLevelListener(
127
-            this.talkMutedDetection.audioLevelListener
128
-                .bind(this.talkMutedDetection));
129
-        this.eventEmitter.on(
130
-            JitsiConferenceEvents.TRACK_MUTE_CHANGED,
131
-            this.talkMutedDetection.muteChanged.bind(this.talkMutedDetection));
122
+        new TalkMutedDetection(this, () => {
123
+            this.eventEmitter.emit(JitsiConferenceEvents.TALK_WHILE_MUTED);
124
+        });
132 125
     }
133 126
 }
134 127
 
@@ -472,9 +465,6 @@ JitsiConference.prototype.addTrack = function (track) {
472 465
                 this.room.setVideoMute(track.isMuted());
473 466
             }
474 467
 
475
-            if (this.talkMutedDetection && track.isAudioTrack())
476
-                this.talkMutedDetection.addTrack(track);
477
-
478 468
             track.muteHandler = this._fireMuteChangeEvent.bind(this, track);
479 469
             track.audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
480 470
             track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,

+ 14
- 7
modules/talkmuted/TalkMutedDetection.js Ver fichero

@@ -1,15 +1,25 @@
1
-import * as JitsiTrackEvents from '../../JitsiTrackEvents';
1
+import * as JitsiConferenceEvents from "../../JitsiConferenceEvents";
2 2
 
3 3
 export default class TalkMutedDetection {
4 4
     /**
5 5
      * Creates TalkMutedDetection
6
+     * @param conference the JitsiConference instance that created us.
6 7
      * @param callback the callback to call when detected local user is talking
7 8
      * while its microphone is muted.
8 9
      * @constructor
9 10
      */
10
-    constructor(callback) {
11
+    constructor(conference, callback) {
11 12
         this.callback = callback;
12 13
 
14
+        conference.statistics.addAudioLevelListener(
15
+            this.audioLevelListener.bind(this));
16
+        conference.eventEmitter.on(
17
+            JitsiConferenceEvents.TRACK_MUTE_CHANGED,
18
+            this.muteChanged.bind(this));
19
+        conference.eventEmitter.on(
20
+            JitsiConferenceEvents.TRACK_ADDED,
21
+            this.onTrackAdded.bind(this));
22
+
13 23
         // we track firing the event, in order to avoid sending too many events
14 24
         this.eventFired = false;
15 25
     }
@@ -18,7 +28,7 @@ export default class TalkMutedDetection {
18 28
      * Adds local tracks. We are interested only in the audio one.
19 29
      * @param track
20 30
      */
21
-    addTrack(track) {
31
+    onTrackAdded(track) {
22 32
         if (!track.isAudioTrack())
23 33
             return;
24 34
 
@@ -48,10 +58,7 @@ export default class TalkMutedDetection {
48 58
      * @param track the track which mute state has changed.
49 59
      */
50 60
     muteChanged(track) {
51
-        if (!track.isLocal() || !track.isAudioTrack())
52
-            return;
53
-
54
-        if (track.isMuted())
61
+        if (track.isLocal() && track.isAudioTrack() && track.isMuted())
55 62
             this.eventFired = false;
56 63
     }
57 64
 }

Loading…
Cancelar
Guardar