Browse Source

ref: Changes the config format of RttMonitor.

dev1
Boris Grozev 7 years ago
parent
commit
430551a5ab
1 changed files with 23 additions and 12 deletions
  1. 23
    12
      modules/rttmonitor/rttmonitor.js

+ 23
- 12
modules/rttmonitor/rttmonitor.js View File

@@ -28,17 +28,19 @@ const stunKeepAliveIntervalMs = 10000;
28 28
  * to the STUN server.
29 29
  */
30 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 36
      * @param {number} getStatsIntervalMs how often to call getStats.
36 37
      * @param {number} delay the delay after which the PeerConnection will be
37 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 44
         this.getStatsIntervalMs = getStatsIntervalMs;
43 45
         this.getStatsInterval = null;
44 46
 
@@ -48,7 +50,7 @@ class PCMonitor {
48 50
         // The RTT measurements we've made from the latest getStats() calls.
49 51
         this.rtts = [];
50 52
 
51
-        const iceServers = [ { 'url': `stun:${stunServer.address}` } ];
53
+        const iceServers = [ { 'url': `stun:${address}` } ];
52 54
 
53 55
         this.pc = new RTCUtils.RTCPeerConnectionType(
54 56
             {
@@ -265,7 +267,7 @@ export default class RttMonitor {
265 267
      * Starts the PCMonitors according to the configuration.
266 268
      */
267 269
     startPCMonitors(config) {
268
-        if (!Array.isArray(config.stunServers)) {
270
+        if (!config.stunServers) {
269 271
             logger.warn('No stun servers configured.');
270 272
 
271 273
             return;
@@ -279,16 +281,25 @@ export default class RttMonitor {
279 281
             = config.getStatsInterval || stunKeepAliveIntervalMs;
280 282
         const analyticsIntervalMs
281 283
             = config.analyticsInterval || getStatsIntervalMs;
282
-        const count = config.stunServers.length;
284
+        const count = Object.keys(config.stunServers).length;
283 285
         const offset = getStatsIntervalMs / count;
284 286
 
285 287
         // We delay the initialization of each PC so that they are uniformly
286 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 305
         window.setTimeout(

Loading…
Cancel
Save