Просмотр исходного кода

Merge pull request #465 from virtuacoplenny/lenny/ie-set-array

fix(stats): lazy initialization for statistics Sets
tags/v0.0.2
Saúl Ibarra Corretgé 8 лет назад
Родитель
Сommit
f1e8134558
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();

Загрузка…
Отмена
Сохранить