浏览代码

Fixes comments.

dev1
damencho 7 年前
父节点
当前提交
67e30ea301
共有 2 个文件被更改,包括 25 次插入16 次删除
  1. 10
    8
      modules/RTC/TraceablePeerConnection.js
  2. 15
    8
      modules/statistics/RTPStatsCollector.js

+ 10
- 8
modules/RTC/TraceablePeerConnection.js 查看文件

@@ -539,15 +539,17 @@ TraceablePeerConnection.prototype.getTrackBySSRC = function(ssrc) {
539 539
  */
540 540
 TraceablePeerConnection.prototype.getSsrcByTrackId = function(id) {
541 541
 
542
-    for (const localTrack of this.localTracks.values()) {
543
-        if (localTrack.getTrack().id === id) {
544
-            return this.getLocalSSRC(localTrack);
545
-        }
542
+    const findTrackById = track => track.getTrack().id === id;
543
+    const localTrack = this.getLocalTracks().find(findTrackById);
544
+
545
+    if (localTrack) {
546
+        return this.getLocalSSRC(localTrack);
546 547
     }
547
-    for (const remoteTrack of this.getRemoteTracks()) {
548
-        if (remoteTrack.getTrack().id === id) {
549
-            return remoteTrack.getSSRC();
550
-        }
548
+
549
+    const remoteTrack = this.getRemoteTracks().find(findTrackById);
550
+
551
+    if (remoteTrack) {
552
+        return remoteTrack.getSSRC();
551 553
     }
552 554
 
553 555
     return null;

+ 15
- 8
modules/statistics/RTPStatsCollector.js 查看文件

@@ -241,6 +241,13 @@ export default function StatsCollector(
241 241
         throw `The browser type '${this._browserType}' isn't supported!`;
242 242
     }
243 243
 
244
+    /**
245
+     * Whether to use the Promise-based getStats API or not.
246
+     * @type {boolean}
247
+     */
248
+    this._usesPromiseGetStats
249
+        = browser.isSafariWithWebrtc() || browser.isFirefox();
250
+
244 251
     /**
245 252
      * The function which is to be used to retrieve the value associated in a
246 253
      * report returned by RTCPeerConnection#getStats with a lib-jitsi-meet
@@ -249,8 +256,10 @@ export default function StatsCollector(
249 256
      * @function
250 257
      * @private
251 258
      */
252
-    this._getStatValue = this._defineGetStatValueMethod(keys);
253
-    this._getNewStatValue = this._defineNewGetStatValueMethod(keys);
259
+    this._getStatValue
260
+        = this._usesPromiseGetStats
261
+            ? this._defineNewGetStatValueMethod(keys)
262
+            : this._defineGetStatValueMethod(keys);
254 263
 
255 264
     this.peerconnection = peerconnection;
256 265
     this.baselineAudioLevelsReport = null;
@@ -322,8 +331,7 @@ StatsCollector.prototype.start = function(startAudioLevelStats) {
322 331
                             results = report.result();
323 332
                         }
324 333
                         self.currentAudioLevelsReport = results;
325
-                        if (browser.isSafariWithWebrtc()
326
-                            || browser.isFirefox()) {
334
+                        if (this._usesPromiseGetStats) {
327 335
                             self.processNewAudioLevelReport();
328 336
                         } else {
329 337
                             self.processAudioLevelReport();
@@ -358,8 +366,7 @@ StatsCollector.prototype.start = function(startAudioLevelStats) {
358 366
 
359 367
                         self.currentStatsReport = results;
360 368
                         try {
361
-                            if (browser.isSafariWithWebrtc()
362
-                                || browser.isFirefox()) {
369
+                            if (this._usesPromiseGetStats) {
363 370
                                 self.processNewStatsReport();
364 371
                             } else {
365 372
                                 self.processStatsReport();
@@ -970,7 +977,7 @@ StatsCollector.prototype.processAudioLevelReport = function() {
970 977
 
971 978
 /**
972 979
  * New promised based getStats report processing.
973
- * Tested with chrome, firefox and safari. Not switching it on for for chrome as
980
+ * Tested with chrome, firefox and safari. Not switching it on for chrome as
974 981
  * frameRate stat is missing and calculating it using framesSent,
975 982
  * gives values double the values seen in webrtc-internals.
976 983
  * https://w3c.github.io/webrtc-stats/
@@ -1061,7 +1068,7 @@ StatsCollector.prototype.processNewStatsReport = function() {
1061 1068
         return;
1062 1069
     }
1063 1070
 
1064
-    const getStatValue = this._getNewStatValue;
1071
+    const getStatValue = this._getStatValue;
1065 1072
     const byteSentStats = {};
1066 1073
 
1067 1074
     this.currentStatsReport.forEach(now => {

正在加载...
取消
保存