浏览代码

ref: Changes the config format of RttMonitor.

dev1
Boris Grozev 7 年前
父节点
当前提交
430551a5ab
共有 1 个文件被更改,包括 23 次插入12 次删除
  1. 23
    12
      modules/rttmonitor/rttmonitor.js

+ 23
- 12
modules/rttmonitor/rttmonitor.js 查看文件

28
  * to the STUN server.
28
  * to the STUN server.
29
  */
29
  */
30
 class PCMonitor {
30
 class PCMonitor {
31
+    /* eslint-disable max-params */
31
     /**
32
     /**
32
      *
33
      *
33
-     * @param {Object} stunServer the STUN server configuration (address and
34
-     * region).
34
+     * @param {String} region - The region of the STUN server.
35
+     * @param {String} address - The address of the STUN server.
35
      * @param {number} getStatsIntervalMs how often to call getStats.
36
      * @param {number} getStatsIntervalMs how often to call getStats.
36
      * @param {number} delay the delay after which the PeerConnection will be
37
      * @param {number} delay the delay after which the PeerConnection will be
37
      * started (that is, createOffer and setLocalDescription will be invoked).
38
      * started (that is, createOffer and setLocalDescription will be invoked).
38
      *
39
      *
39
      */
40
      */
40
-    constructor(stunServer, getStatsIntervalMs, delay) {
41
-        this.region = stunServer.region;
41
+    constructor(region, address, getStatsIntervalMs, delay) {
42
+        /* eslint-disable max-params */
43
+        this.region = region;
42
         this.getStatsIntervalMs = getStatsIntervalMs;
44
         this.getStatsIntervalMs = getStatsIntervalMs;
43
         this.getStatsInterval = null;
45
         this.getStatsInterval = null;
44
 
46
 
48
         // The RTT measurements we've made from the latest getStats() calls.
50
         // The RTT measurements we've made from the latest getStats() calls.
49
         this.rtts = [];
51
         this.rtts = [];
50
 
52
 
51
-        const iceServers = [ { 'url': `stun:${stunServer.address}` } ];
53
+        const iceServers = [ { 'url': `stun:${address}` } ];
52
 
54
 
53
         this.pc = new RTCUtils.RTCPeerConnectionType(
55
         this.pc = new RTCUtils.RTCPeerConnectionType(
54
             {
56
             {
265
      * Starts the PCMonitors according to the configuration.
267
      * Starts the PCMonitors according to the configuration.
266
      */
268
      */
267
     startPCMonitors(config) {
269
     startPCMonitors(config) {
268
-        if (!Array.isArray(config.stunServers)) {
270
+        if (!config.stunServers) {
269
             logger.warn('No stun servers configured.');
271
             logger.warn('No stun servers configured.');
270
 
272
 
271
             return;
273
             return;
279
             = config.getStatsInterval || stunKeepAliveIntervalMs;
281
             = config.getStatsInterval || stunKeepAliveIntervalMs;
280
         const analyticsIntervalMs
282
         const analyticsIntervalMs
281
             = config.analyticsInterval || getStatsIntervalMs;
283
             = config.analyticsInterval || getStatsIntervalMs;
282
-        const count = config.stunServers.length;
284
+        const count = Object.keys(config.stunServers).length;
283
         const offset = getStatsIntervalMs / count;
285
         const offset = getStatsIntervalMs / count;
284
 
286
 
285
         // We delay the initialization of each PC so that they are uniformly
287
         // We delay the initialization of each PC so that they are uniformly
286
         // distributed across the getStatsIntervalMs.
288
         // distributed across the getStatsIntervalMs.
287
-        for (let i = 0; i < count; i++) {
288
-            const stunServer = config.stunServers[i];
289
-
290
-            this.pcMonitors[stunServer.region]
291
-                = new PCMonitor(stunServer, getStatsIntervalMs, offset * i);
289
+        let i = 0;
290
+
291
+        for (const region in config.stunServers) {
292
+            if (config.stunServers.hasOwnProperty(region)) {
293
+                const address = config.stunServers[region];
294
+
295
+                this.pcMonitors[region]
296
+                    = new PCMonitor(
297
+                        region,
298
+                        address,
299
+                        getStatsIntervalMs,
300
+                        offset * i);
301
+                i++;
302
+            }
292
         }
303
         }
293
 
304
 
294
         window.setTimeout(
305
         window.setTimeout(

正在加载...
取消
保存