瀏覽代碼

Merge pull request #137 from jitsi/cs-refactor

Refactor callstats removing improve static calls to Statistics.
master
hristoterezov 9 年之前
父節點
當前提交
7b797d9a2e
共有 4 個檔案被更改,包括 44 行新增89 行删除
  1. 0
    17
      JitsiConference.js
  2. 1
    9
      JitsiConnection.js
  3. 14
    32
      JitsiMeetJS.js
  4. 29
    31
      modules/statistics/statistics.js

+ 0
- 17
JitsiConference.js 查看文件

@@ -55,12 +55,6 @@ function JitsiConference(options) {
55 55
         roomName: this.options.name
56 56
     });
57 57
     setupListeners(this);
58
-    var JitsiMeetJS = this.connection.JitsiMeetJS;
59
-    JitsiMeetJS._gumFailedHandler.push(function(error) {
60
-        this.statistics.sendGetUserMediaFailed(error);
61
-    }.bind(this));
62
-    JitsiMeetJS._globalOnErrorHandler.push(
63
-        Statistics.reportGlobalError.bind(this.statistics));
64 58
     this.participants = {};
65 59
     this.lastDominantSpeaker = null;
66 60
     this.dtmfManager = null;
@@ -75,17 +69,6 @@ function JitsiConference(options) {
75 69
         video: undefined
76 70
     };
77 71
     this.isMutedByFocus = false;
78
-
79
-    // Lets send some general stats useful for debugging problems
80
-    if (window.jitsiRegionInfo
81
-            && Object.keys(window.jitsiRegionInfo).length > 0) {
82
-        // remove quotes to make it prettier
83
-        Statistics.sendLog(
84
-            JSON.stringify(window.jitsiRegionInfo).replace(/\"/g, ""));
85
-    }
86
-
87
-    if(JitsiMeetJS.version)
88
-        Statistics.sendLog("LibJitsiMeet:" + JitsiMeetJS.version);
89 72
 }
90 73
 
91 74
 /**

+ 1
- 9
JitsiConnection.js 查看文件

@@ -4,20 +4,12 @@ var XMPP = require("./modules/xmpp/xmpp");
4 4
 /**
5 5
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
6 6
  * JitsiConference interface.
7
- * @param JitsiMeetJS the JitsiMeetJS instance which is initializing the new
8
- * JitsiConnection instance
9 7
  * @param appID identification for the provider of Jitsi Meet video conferencing services.
10 8
  * @param token the JWT token used to authenticate with the server(optional)
11 9
  * @param options Object with properties / settings related to connection with the server.
12 10
  * @constructor
13 11
  */
14
-function JitsiConnection(JitsiMeetJS, appID, token, options) {
15
-    /**
16
-     * The {JitsiMeetJS} instance which has initialized this {JitsiConnection}
17
-     * instance.
18
-     * @public
19
-     */
20
-    this.JitsiMeetJS = JitsiMeetJS;
12
+function JitsiConnection(appID, token, options) {
21 13
     this.appID = appID;
22 14
     this.token = token;
23 15
     this.options = options;

+ 14
- 32
JitsiMeetJS.js 查看文件

@@ -42,6 +42,7 @@ var LibJitsiMeet = {
42 42
 
43 43
     version: '{#COMMIT_HASH#}',
44 44
 
45
+    JitsiConnection: JitsiConnection,
45 46
     events: {
46 47
         conference: JitsiConferenceEvents,
47 48
         connection: JitsiConnectionEvents,
@@ -56,10 +57,6 @@ var LibJitsiMeet = {
56 57
     },
57 58
     logLevels: Logger.levels,
58 59
     mediaDevices: JitsiMediaDevices,
59
-    /**
60
-     * Array of functions that will receive the GUM error.
61
-     */
62
-    _gumFailedHandler: [],
63 60
     init: function (options) {
64 61
         Statistics.audioLevelsEnabled = !options.disableAudioLevels;
65 62
 
@@ -68,6 +65,17 @@ var LibJitsiMeet = {
68 65
                 this.getGlobalOnErrorHandler.bind(this));
69 66
         }
70 67
 
68
+        // Lets send some general stats useful for debugging problems
69
+        if (window.jitsiRegionInfo
70
+            && Object.keys(window.jitsiRegionInfo).length > 0) {
71
+            // remove quotes to make it prettier
72
+            Statistics.sendLog(
73
+                JSON.stringify(window.jitsiRegionInfo).replace(/\"/g, ""));
74
+        }
75
+
76
+        if(JitsiMeetJS.version)
77
+            Statistics.sendLog("LibJitsiMeet:" + JitsiMeetJS.version);
78
+
71 79
         return RTC.init(options || {});
72 80
     },
73 81
     /**
@@ -114,13 +122,7 @@ var LibJitsiMeet = {
114 122
                     }
115 123
                 return tracks;
116 124
             }).catch(function (error) {
117
-                this._gumFailedHandler.forEach(function (handler) {
118
-                    handler(error);
119
-                });
120
-
121
-                if(!this._gumFailedHandler.length) {
122
-                    Statistics.sendGetUserMediaFailed(error);
123
-                }
125
+                Statistics.sendGetUserMediaFailed(error);
124 126
 
125 127
                 if(error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {
126 128
                     var oldResolution = options.resolution || '360',
@@ -174,10 +176,6 @@ var LibJitsiMeet = {
174 176
             'JitsiMeetJS.mediaDevices.enumerateDevices instead');
175 177
         this.mediaDevices.enumerateDevices(callback);
176 178
     },
177
-    /**
178
-     * Array of functions that will receive the unhandled errors.
179
-     */
180
-    _globalOnErrorHandler: [],
181 179
     /**
182 180
      * @returns function that can be used to be attached to window.onerror and
183 181
      * if options.enableWindowOnErrorHandler is enabled returns
@@ -191,14 +189,7 @@ var LibJitsiMeet = {
191 189
             'Line: ' + lineno,
192 190
             'Column: ' + colno,
193 191
             'StackTrace: ', error);
194
-        var globalOnErrorHandler = this._globalOnErrorHandler;
195
-        if (globalOnErrorHandler.length) {
196
-          globalOnErrorHandler.forEach(function (handler) {
197
-              handler(error);
198
-          });
199
-        } else {
200
-            Statistics.reportGlobalError(error);
201
-        }
192
+        Statistics.reportGlobalError(error);
202 193
     },
203 194
 
204 195
     /**
@@ -211,15 +202,6 @@ var LibJitsiMeet = {
211 202
     }
212 203
 };
213 204
 
214
-// XXX JitsiConnection or the instances it initializes and is associated with
215
-// (e.g. JitsiConference) may need a reference to LibJitsiMeet (aka
216
-// JitsiMeetJS). An approach could be to declare LibJitsiMeet global (which is
217
-// what we do in Jitsi Meet) but that could be seen as not such a cool decision
218
-// certainly looks even worse within the lib-jitsi-meet library itself. That's
219
-// why the decision is to provide LibJitsiMeet as a parameter of
220
-// JitsiConnection.
221
-LibJitsiMeet.JitsiConnection = JitsiConnection.bind(null, LibJitsiMeet);
222
-
223 205
 // expose JitsiTrackError this way to give library consumers to do checks like
224 206
 // if (error instanceof JitsiMeetJS.JitsiTrackError) { }
225 207
 LibJitsiMeet.JitsiTrackError = JitsiTrackError;

+ 29
- 31
modules/statistics/statistics.js 查看文件

@@ -84,6 +84,12 @@ function Statistics(xmpp, options) {
84 84
 }
85 85
 Statistics.audioLevelsEnabled = false;
86 86
 
87
+/**
88
+ * Array of callstats instances. Used to call Statistics static methods and
89
+ * send stats to all cs instances.
90
+ */
91
+Statistics.callsStatsInstances = [];
92
+
87 93
 Statistics.prototype.startRemoteStats = function (peerconnection) {
88 94
     if(!Statistics.audioLevelsEnabled)
89 95
         return;
@@ -194,6 +200,7 @@ Statistics.prototype.stopRemoteStats = function () {
194 200
 Statistics.prototype.startCallStats = function (session, settings) {
195 201
     if(this.callStatsIntegrationEnabled && !this.callstats) {
196 202
         this.callstats = new CallStats(session, settings, this.options);
203
+        Statistics.callsStatsInstances.push(this.callstats);
197 204
     }
198 205
 };
199 206
 
@@ -270,29 +277,25 @@ function (ssrc, isLocal, usageLabel, containerId) {
270 277
  *
271 278
  * @param {Error} e error to send
272 279
  */
273
-Statistics.prototype.sendGetUserMediaFailed = function (e) {
274
-    if(this.callstats) {
280
+Statistics.sendGetUserMediaFailed = function (e) {
281
+
282
+    if (Statistics.callsStatsInstances.length) {
283
+        Statistics.callsStatsInstances.forEach(function (cs) {
284
+            CallStats.sendGetUserMediaFailed(
285
+                e instanceof JitsiTrackError
286
+                    ? formatJitsiTrackErrorForCallStats(e)
287
+                    : e,
288
+                cs);
289
+        });
290
+    } else {
275 291
         CallStats.sendGetUserMediaFailed(
276 292
             e instanceof JitsiTrackError
277 293
                 ? formatJitsiTrackErrorForCallStats(e)
278 294
                 : e,
279
-            this.callstats);
295
+            null);
280 296
     }
281 297
 };
282 298
 
283
-/**
284
- * Notifies CallStats that getUserMedia failed.
285
- *
286
- * @param {Error} e error to send
287
- */
288
-Statistics.sendGetUserMediaFailed = function (e) {
289
-    CallStats.sendGetUserMediaFailed(
290
-        e instanceof JitsiTrackError
291
-            ? formatJitsiTrackErrorForCallStats(e)
292
-            : e,
293
-        null);
294
-};
295
-
296 299
 /**
297 300
  * Notifies CallStats that peer connection failed to create offer.
298 301
  *
@@ -348,24 +351,19 @@ Statistics.prototype.sendAddIceCandidateFailed = function (e, pc) {
348 351
         CallStats.sendAddIceCandidateFailed(e, pc, this.callstats);
349 352
 };
350 353
 
351
-/**
352
- * Notifies CallStats that there is an unhandled error on the page.
353
- *
354
- * @param {Error} e error to send
355
- * @param {RTCPeerConnection} pc connection on which failure occured.
356
- */
357
-Statistics.prototype.sendUnhandledError = function (e) {
358
-    if(this.callstats)
359
-        CallStats.sendUnhandledError(e, this.callstats);
360
-};
361
-
362 354
 /**
363 355
  * Notifies CallStats that there is unhandled exception.
364 356
  *
365 357
  * @param {Error} e error to send
366 358
  */
367 359
 Statistics.sendUnhandledError = function (e) {
368
-    CallStats.sendUnhandledError(e, null);
360
+    if (Statistics.callsStatsInstances.length) {
361
+        Statistics.callsStatsInstances.forEach(function (cs) {
362
+            CallStats.sendUnhandledError(e, cs);
363
+        });
364
+    } else {
365
+        CallStats.sendUnhandledError(e, null);
366
+    }
369 367
 };
370 368
 
371 369
 /**
@@ -375,7 +373,7 @@ Statistics.sendUnhandledError = function (e) {
375 373
  */
376 374
 Statistics.sendLog = function (m) {
377 375
     // uses  the same field for cs stat as unhandled error
378
-    CallStats.sendUnhandledError(m, null);
376
+    Statistics.sendUnhandledError(m);
379 377
 };
380 378
 
381 379
 /**
@@ -408,9 +406,9 @@ Statistics.LOCAL_JID = require("../../service/statistics/constants").LOCAL_JID;
408 406
  */
409 407
 Statistics.reportGlobalError = function (error) {
410 408
     if (error instanceof JitsiTrackError && error.gum) {
411
-        this.sendGetUserMediaFailed(error);
409
+        Statistics.sendGetUserMediaFailed(error);
412 410
     } else {
413
-        this.sendUnhandledError(error);
411
+        Statistics.sendUnhandledError(error);
414 412
     }
415 413
 };
416 414
 

Loading…
取消
儲存