浏览代码

fix(stats): lazy initialization for statistics Sets

Internet Explorer is throwing an error when doing a for...of over
Sets. This is because IE needs a Set polyfill, which may be applied
after lib-jitsi-meet has loaded. However, lib-jitsi-meet on load
creates two Sets, one for CallStats.fabrics and another for
Statistics.instances. When the polyfill is then applied, the two
existing Sets do not get new methods. The fix is to lazily
initialize the Sets to allow for polyfills to be applied.
dev1
Leonard Kim 8 年前
父节点
当前提交
a82d4b7c3c
共有 2 个文件被更改,包括 39 次插入11 次删除
  1. 19
    6
      modules/statistics/CallStats.js
  2. 20
    5
      modules/statistics/statistics.js

+ 19
- 6
modules/statistics/CallStats.js 查看文件

@@ -61,6 +61,12 @@ const reportType = {
61 61
     MST_WITH_USERID: 'mstWithUserID'
62 62
 };
63 63
 
64
+/**
65
+ * Set of currently existing {@link CallStats} instances.
66
+ * @type {Set<CallStats>}
67
+ */
68
+let _fabrics;
69
+
64 70
 /**
65 71
  * An instance of this class is a wrapper for the CallStats API fabric. A fabric
66 72
  * reports one peer connection the the CallStats backend and is allocated with
@@ -300,6 +306,19 @@ export default class CallStats {
300 306
         /* eslint-enable max-params */
301 307
     }
302 308
 
309
+    /**
310
+     * Returns the Set with the currently existing {@link CallStats} instances.
311
+     * Lazily initializes the Set to allow any Set polyfills to be applied.
312
+     * @type {Set<CallStats>}
313
+     */
314
+    static get fabrics() {
315
+        if (!_fabrics) {
316
+            _fabrics = new Set();
317
+        }
318
+
319
+        return _fabrics;
320
+    }
321
+
303 322
     /**
304 323
      * Initializes the CallStats backend. Should be called only if
305 324
      * {@link CallStats.isBackendInitialized} returns <tt>false</tt>.
@@ -703,9 +722,3 @@ CallStats.callStatsSecret = null;
703 722
  * @type {object}
704 723
  */
705 724
 CallStats.userID = null;
706
-
707
-/**
708
- * Set of currently existing {@link CallStats} instances.
709
- * @type {Set<CallStats>}
710
- */
711
-CallStats.fabrics = new Set();

+ 20
- 5
modules/statistics/statistics.js 查看文件

@@ -10,6 +10,12 @@ const EventEmitter = require('events');
10 10
 const logger = require('jitsi-meet-logger').getLogger(__filename);
11 11
 const ScriptUtil = require('../util/ScriptUtil');
12 12
 
13
+/**
14
+ * Stores all active {@link Statistics} instances.
15
+ * @type {Set<Statistics>}
16
+ */
17
+let _instances;
18
+
13 19
 /**
14 20
  * True if callstats API is loaded
15 21
  */
@@ -124,11 +130,20 @@ Statistics.audioLevelsInterval = 200;
124 130
 Statistics.disableThirdPartyRequests = false;
125 131
 Statistics.analytics = analytics;
126 132
 
127
-/**
128
- * Stores all active {@link Statistics} instances.
129
- * @type {Set<Statistics>}
130
- */
131
-Statistics.instances = new Set();
133
+Object.defineProperty(Statistics, 'instances', {
134
+    /**
135
+     * Returns the Set holding all active {@link Statistics} instances. Lazily
136
+     * initializes the Set to allow any Set polyfills to be applied.
137
+     * @type {Set<Statistics>}
138
+     */
139
+    get() {
140
+        if (!_instances) {
141
+            _instances = new Set();
142
+        }
143
+
144
+        return _instances;
145
+    }
146
+});
132 147
 
133 148
 Statistics.prototype.startRemoteStats = function(peerconnection) {
134 149
     this.stopRemoteStats();

正在加载...
取消
保存