瀏覽代碼

Do not subscribe each JitsiTrack to RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED, instead subscribe once in RTC

master
tsareg 9 年之前
父節點
當前提交
6500f9e1f4
共有 4 個檔案被更改,包括 22 行新增13 行删除
  1. 2
    1
      modules/RTC/JitsiLocalTrack.js
  2. 2
    0
      modules/RTC/JitsiRemoteTrack.js
  3. 1
    12
      modules/RTC/JitsiTrack.js
  4. 17
    0
      modules/RTC/RTC.js

+ 2
- 1
modules/RTC/JitsiLocalTrack.js 查看文件

@@ -36,6 +36,7 @@ function JitsiLocalTrack(stream, track, mediaType, videoType, resolution,
36 36
     this.resolution = resolution;
37 37
     this.deviceId = deviceId;
38 38
     this.startMuted = false;
39
+    this.disposed = false;
39 40
     //FIXME: This dependacy is not necessary.
40 41
     this.conference = null;
41 42
     this.initialMSID = this.getMSID();
@@ -282,7 +283,7 @@ JitsiLocalTrack.prototype.dispose = function () {
282 283
         this.detach();
283 284
     }
284 285
 
285
-    JitsiTrack.prototype.dispose.call(this);
286
+    this.disposed = true;
286 287
 
287 288
     RTCUtils.removeListener(RTCEvents.DEVICE_LIST_CHANGED,
288 289
         this._onDeviceListChanged);

+ 2
- 0
modules/RTC/JitsiRemoteTrack.js 查看文件

@@ -84,4 +84,6 @@ JitsiRemoteTrack.prototype._setVideoType = function (type) {
84 84
     this.eventEmitter.emit(JitsiTrackEvents.TRACK_VIDEOTYPE_CHANGED, type);
85 85
 };
86 86
 
87
+delete JitsiRemoteTrack.prototype.dispose;
88
+
87 89
 module.exports = JitsiRemoteTrack;

+ 1
- 12
modules/RTC/JitsiTrack.js 查看文件

@@ -70,7 +70,6 @@ function JitsiTrack(rtc, stream, track, streamInactiveHandler, trackMediaType,
70 70
     this.type = trackMediaType;
71 71
     this.track = track;
72 72
     this.videoType = videoType;
73
-    this.disposed = false;
74 73
 
75 74
     if(stream) {
76 75
         if (RTCBrowserType.isFirefox()) {
@@ -78,13 +77,6 @@ function JitsiTrack(rtc, stream, track, streamInactiveHandler, trackMediaType,
78 77
         }
79 78
         addMediaStreamInactiveHandler(stream, streamInactiveHandler);
80 79
     }
81
-
82
-    this._onAudioOutputDeviceChanged = this.setAudioOutput.bind(this);
83
-
84
-    if (this.isAudioTrack()) {
85
-        RTCUtils.addListener(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
86
-            this._onAudioOutputDeviceChanged);
87
-    }
88 80
 }
89 81
 
90 82
 /**
@@ -225,12 +217,9 @@ JitsiTrack.prototype.detach = function (container) {
225 217
 
226 218
 /**
227 219
  * Dispose sending the media track. And removes it from the HTML.
220
+ * NOTE: Works for local tracks only.
228 221
  */
229 222
 JitsiTrack.prototype.dispose = function () {
230
-    RTCUtils.removeListener(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
231
-        this._onAudioOutputDeviceChanged);
232
-
233
-    this.disposed = true;
234 223
 };
235 224
 
236 225
 /**

+ 17
- 0
modules/RTC/RTC.js 查看文件

@@ -59,6 +59,23 @@ function RTC(room, options) {
59 59
             videoTrack._setVideoType(data.value);
60 60
         }
61 61
     });
62
+
63
+    // switch audio output device on all local and remote audio tracks
64
+    RTCUtils.addListener(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,
65
+        function (deviceId) {
66
+            if (RTCUtils.isDeviceChangeAvailable('output')) {
67
+                if (self.localAudio) {
68
+                    self.localAudio.setAudioOutput(deviceId);
69
+                }
70
+
71
+                for (var key in self.remoteTracks) {
72
+                    if (self.remoteTracks.hasOwnProperty(key)
73
+                        && self.remoteTracks[key].audio) {
74
+                        self.remoteTracks[key].audio.setAudioOutput(deviceId);
75
+                    }
76
+                }
77
+            }
78
+        });
62 79
 }
63 80
 
64 81
 /**

Loading…
取消
儲存