Browse Source

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 years ago
parent
commit
a82d4b7c3c
2 changed files with 39 additions and 11 deletions
  1. 19
    6
      modules/statistics/CallStats.js
  2. 20
    5
      modules/statistics/statistics.js

+ 19
- 6
modules/statistics/CallStats.js View File

61
     MST_WITH_USERID: 'mstWithUserID'
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
  * An instance of this class is a wrapper for the CallStats API fabric. A fabric
71
  * An instance of this class is a wrapper for the CallStats API fabric. A fabric
66
  * reports one peer connection the the CallStats backend and is allocated with
72
  * reports one peer connection the the CallStats backend and is allocated with
300
         /* eslint-enable max-params */
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
      * Initializes the CallStats backend. Should be called only if
323
      * Initializes the CallStats backend. Should be called only if
305
      * {@link CallStats.isBackendInitialized} returns <tt>false</tt>.
324
      * {@link CallStats.isBackendInitialized} returns <tt>false</tt>.
703
  * @type {object}
722
  * @type {object}
704
  */
723
  */
705
 CallStats.userID = null;
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 View File

10
 const logger = require('jitsi-meet-logger').getLogger(__filename);
10
 const logger = require('jitsi-meet-logger').getLogger(__filename);
11
 const ScriptUtil = require('../util/ScriptUtil');
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
  * True if callstats API is loaded
20
  * True if callstats API is loaded
15
  */
21
  */
124
 Statistics.disableThirdPartyRequests = false;
130
 Statistics.disableThirdPartyRequests = false;
125
 Statistics.analytics = analytics;
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
 Statistics.prototype.startRemoteStats = function(peerconnection) {
148
 Statistics.prototype.startRemoteStats = function(peerconnection) {
134
     this.stopRemoteStats();
149
     this.stopRemoteStats();

Loading…
Cancel
Save