Selaa lähdekoodia

Merge pull request #137 from jitsi/cs-refactor

Refactor callstats removing improve static calls to Statistics.
master
hristoterezov 9 vuotta sitten
vanhempi
commit
7b797d9a2e
4 muutettua tiedostoa jossa 44 lisäystä ja 89 poistoa
  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 Näytä tiedosto

55
         roomName: this.options.name
55
         roomName: this.options.name
56
     });
56
     });
57
     setupListeners(this);
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
     this.participants = {};
58
     this.participants = {};
65
     this.lastDominantSpeaker = null;
59
     this.lastDominantSpeaker = null;
66
     this.dtmfManager = null;
60
     this.dtmfManager = null;
75
         video: undefined
69
         video: undefined
76
     };
70
     };
77
     this.isMutedByFocus = false;
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 Näytä tiedosto

4
 /**
4
 /**
5
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
5
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
6
  * JitsiConference interface.
6
  * JitsiConference interface.
7
- * @param JitsiMeetJS the JitsiMeetJS instance which is initializing the new
8
- * JitsiConnection instance
9
  * @param appID identification for the provider of Jitsi Meet video conferencing services.
7
  * @param appID identification for the provider of Jitsi Meet video conferencing services.
10
  * @param token the JWT token used to authenticate with the server(optional)
8
  * @param token the JWT token used to authenticate with the server(optional)
11
  * @param options Object with properties / settings related to connection with the server.
9
  * @param options Object with properties / settings related to connection with the server.
12
  * @constructor
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
     this.appID = appID;
13
     this.appID = appID;
22
     this.token = token;
14
     this.token = token;
23
     this.options = options;
15
     this.options = options;

+ 14
- 32
JitsiMeetJS.js Näytä tiedosto

42
 
42
 
43
     version: '{#COMMIT_HASH#}',
43
     version: '{#COMMIT_HASH#}',
44
 
44
 
45
+    JitsiConnection: JitsiConnection,
45
     events: {
46
     events: {
46
         conference: JitsiConferenceEvents,
47
         conference: JitsiConferenceEvents,
47
         connection: JitsiConnectionEvents,
48
         connection: JitsiConnectionEvents,
56
     },
57
     },
57
     logLevels: Logger.levels,
58
     logLevels: Logger.levels,
58
     mediaDevices: JitsiMediaDevices,
59
     mediaDevices: JitsiMediaDevices,
59
-    /**
60
-     * Array of functions that will receive the GUM error.
61
-     */
62
-    _gumFailedHandler: [],
63
     init: function (options) {
60
     init: function (options) {
64
         Statistics.audioLevelsEnabled = !options.disableAudioLevels;
61
         Statistics.audioLevelsEnabled = !options.disableAudioLevels;
65
 
62
 
68
                 this.getGlobalOnErrorHandler.bind(this));
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
         return RTC.init(options || {});
79
         return RTC.init(options || {});
72
     },
80
     },
73
     /**
81
     /**
114
                     }
122
                     }
115
                 return tracks;
123
                 return tracks;
116
             }).catch(function (error) {
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
                 if(error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {
127
                 if(error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION) {
126
                     var oldResolution = options.resolution || '360',
128
                     var oldResolution = options.resolution || '360',
174
             'JitsiMeetJS.mediaDevices.enumerateDevices instead');
176
             'JitsiMeetJS.mediaDevices.enumerateDevices instead');
175
         this.mediaDevices.enumerateDevices(callback);
177
         this.mediaDevices.enumerateDevices(callback);
176
     },
178
     },
177
-    /**
178
-     * Array of functions that will receive the unhandled errors.
179
-     */
180
-    _globalOnErrorHandler: [],
181
     /**
179
     /**
182
      * @returns function that can be used to be attached to window.onerror and
180
      * @returns function that can be used to be attached to window.onerror and
183
      * if options.enableWindowOnErrorHandler is enabled returns
181
      * if options.enableWindowOnErrorHandler is enabled returns
191
             'Line: ' + lineno,
189
             'Line: ' + lineno,
192
             'Column: ' + colno,
190
             'Column: ' + colno,
193
             'StackTrace: ', error);
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
     }
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
 // expose JitsiTrackError this way to give library consumers to do checks like
205
 // expose JitsiTrackError this way to give library consumers to do checks like
224
 // if (error instanceof JitsiMeetJS.JitsiTrackError) { }
206
 // if (error instanceof JitsiMeetJS.JitsiTrackError) { }
225
 LibJitsiMeet.JitsiTrackError = JitsiTrackError;
207
 LibJitsiMeet.JitsiTrackError = JitsiTrackError;

+ 29
- 31
modules/statistics/statistics.js Näytä tiedosto

84
 }
84
 }
85
 Statistics.audioLevelsEnabled = false;
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
 Statistics.prototype.startRemoteStats = function (peerconnection) {
93
 Statistics.prototype.startRemoteStats = function (peerconnection) {
88
     if(!Statistics.audioLevelsEnabled)
94
     if(!Statistics.audioLevelsEnabled)
89
         return;
95
         return;
194
 Statistics.prototype.startCallStats = function (session, settings) {
200
 Statistics.prototype.startCallStats = function (session, settings) {
195
     if(this.callStatsIntegrationEnabled && !this.callstats) {
201
     if(this.callStatsIntegrationEnabled && !this.callstats) {
196
         this.callstats = new CallStats(session, settings, this.options);
202
         this.callstats = new CallStats(session, settings, this.options);
203
+        Statistics.callsStatsInstances.push(this.callstats);
197
     }
204
     }
198
 };
205
 };
199
 
206
 
270
  *
277
  *
271
  * @param {Error} e error to send
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
         CallStats.sendGetUserMediaFailed(
291
         CallStats.sendGetUserMediaFailed(
276
             e instanceof JitsiTrackError
292
             e instanceof JitsiTrackError
277
                 ? formatJitsiTrackErrorForCallStats(e)
293
                 ? formatJitsiTrackErrorForCallStats(e)
278
                 : e,
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
  * Notifies CallStats that peer connection failed to create offer.
300
  * Notifies CallStats that peer connection failed to create offer.
298
  *
301
  *
348
         CallStats.sendAddIceCandidateFailed(e, pc, this.callstats);
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
  * Notifies CallStats that there is unhandled exception.
355
  * Notifies CallStats that there is unhandled exception.
364
  *
356
  *
365
  * @param {Error} e error to send
357
  * @param {Error} e error to send
366
  */
358
  */
367
 Statistics.sendUnhandledError = function (e) {
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
  */
373
  */
376
 Statistics.sendLog = function (m) {
374
 Statistics.sendLog = function (m) {
377
     // uses  the same field for cs stat as unhandled error
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
  */
406
  */
409
 Statistics.reportGlobalError = function (error) {
407
 Statistics.reportGlobalError = function (error) {
410
     if (error instanceof JitsiTrackError && error.gum) {
408
     if (error instanceof JitsiTrackError && error.gum) {
411
-        this.sendGetUserMediaFailed(error);
409
+        Statistics.sendGetUserMediaFailed(error);
412
     } else {
410
     } else {
413
-        this.sendUnhandledError(error);
411
+        Statistics.sendUnhandledError(error);
414
     }
412
     }
415
 };
413
 };
416
 
414
 

Loading…
Peruuta
Tallenna