Ver código fonte

Adds global error handler function and option to auto enable it. Reports unhandled exceptions catched by error handler through callstats.

dev1
damencho 9 anos atrás
pai
commit
b7e1654670

+ 3
- 0
JitsiConference.js Ver arquivo

@@ -51,6 +51,9 @@ function JitsiConference(options) {
51 51
     JitsiMeetJS._gumFailedHandler.push(function(error) {
52 52
         this.statistics.sendGetUserMediaFailed(error);
53 53
     }.bind(this));
54
+    JitsiMeetJS._globalOnErrorHandler.push(function(error) {
55
+        this.statistics.sendUnhandledError(error);
56
+    }.bind(this));
54 57
     this.participants = {};
55 58
     this.lastDominantSpeaker = null;
56 59
     this.dtmfManager = null;

+ 29
- 0
JitsiMeetJS.js Ver arquivo

@@ -54,6 +54,10 @@ var LibJitsiMeet = {
54 54
     _gumFailedHandler: [],
55 55
     init: function (options) {
56 56
         Statistics.audioLevelsEnabled = !options.disableAudioLevels || true;
57
+
58
+        if (options.enableWindowOnErrorHandler)
59
+            window.onerror = JitsiMeetJS.getGlobalOnErrorHandler;
60
+
57 61
         return RTC.init(options || {});
58 62
     },
59 63
     /**
@@ -136,6 +140,31 @@ var LibJitsiMeet = {
136 140
     enumerateDevices: function (callback) {
137 141
         RTC.enumerateDevices(callback);
138 142
     },
143
+    /**
144
+     * Array of functions that will receive the unhandled errors.
145
+     */
146
+    _globalOnErrorHandler: [],
147
+    /**
148
+     * @returns function that can be used to be attached to window.onerror and
149
+     * if options.enableWindowOnErrorHandler is enabled returns
150
+     * the function used by the lib.
151
+     * (function(message, source, lineno, colno, error)).
152
+     */
153
+    getGlobalOnErrorHandler: function (message, source, lineno, colno, error) {
154
+        console.error(
155
+            'UnhandledError: ' + message,
156
+            'Script: ' + source,
157
+            'Line: ' + lineno,
158
+            'Column: ' + colno,
159
+            'StackTrace: ', error);
160
+
161
+        JitsiMeetJS._globalOnErrorHandler.forEach(function (handler) {
162
+            handler(error);
163
+        });
164
+        if(!JitsiMeetJS._globalOnErrorHandler.length){
165
+            Statistics.sendUnhandledError(error);
166
+        }
167
+    },
139 168
 
140 169
     /**
141 170
      * Represents a hub/namespace for utility functionality which may be of

+ 2
- 0
doc/API.md Ver arquivo

@@ -47,6 +47,7 @@ The ```options``` parameter is JS object with the following properties:
47 47
     8. desktopSharingFirefoxExtensionURL - The URL to the Firefox extension for desktop sharing. "null" if no extension is required.
48 48
     9. disableAudioLevels - boolean property. Enables/disables audio levels.
49 49
     10. disableSimulcast - boolean property. Enables/disables simulcast.
50
+    11. enableWindowOnErrorHandler - boolean property (default false). Enables/disables attaching global onerror handler (window.onerror).
50 51
 
51 52
 * ```JitsiMeetJS.JitsiConnection``` - the ```JitsiConnection``` constructor. You can use that to create new server connection.
52 53
 
@@ -70,6 +71,7 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
70 71
 * ```JitsiMeetJS.isDeviceListAvailable()```- returns true if retrieving the device list is support and false - otherwise.
71 72
 
72 73
 * ```JitsiMeetJS.isDesktopSharingEnabled()``` - returns true if desktop sharing is supported and false otherwise. NOTE: that method can be used after ```JitsiMeetJS.init(options)``` is completed otherwise the result will be always null.
74
+* ```JitsiMeetJS.getGlobalOnErrorHandler()``` - returns function that can be used to be attached to window.onerror and if options.enableWindowOnErrorHandler is enabled returns the function used by the lib. (function(message, source, lineno, colno, error)).
73 75
 
74 76
 * ```JitsiMeetJS.events``` - JS object that contains all events used by the API. You will need that JS object when you try to subscribe for connection or conference events.
75 77
     We have two event types - connection and conference. You can access the events with the following code ```JitsiMeetJS.events.<event_type>.<event_name>```.

+ 13
- 1
modules/statistics/CallStats.js Ver arquivo

@@ -14,7 +14,8 @@ var wrtcFuncNames = {
14 14
     setLocalDescription:  "setLocalDescription",
15 15
     setRemoteDescription: "setRemoteDescription",
16 16
     addIceCandidate:      "addIceCandidate",
17
-    getUserMedia:         "getUserMedia"
17
+    getUserMedia:         "getUserMedia",
18
+    signallingError:      "signallingError"
18 19
 };
19 20
 
20 21
 /**
@@ -355,4 +356,15 @@ CallStats.sendAddIceCandidateFailed = _try_catch(function (e, pc, cs) {
355 356
     CallStats._reportError.call(cs, wrtcFuncNames.addIceCandidate, e, pc);
356 357
 });
357 358
 
359
+/**
360
+ * Notifies CallStats that there is an unhandled error on the page.
361
+ *
362
+ * @param {Error} e error to send
363
+ * @param {RTCPeerConnection} pc connection on which failure occured.
364
+ * @param {CallStats} cs callstats instance related to the error (optional)
365
+ */
366
+CallStats.sendUnhandledError = _try_catch(function (e, cs) {
367
+    CallStats._reportError.call(cs, wrtcFuncNames.signallingError, e, null);
368
+});
369
+
358 370
 module.exports = CallStats;

+ 20
- 0
modules/statistics/statistics.js Ver arquivo

@@ -292,6 +292,26 @@ Statistics.prototype.sendAddIceCandidateFailed = function (e, pc) {
292 292
         CallStats.sendAddIceCandidateFailed(e, pc, this.callstats);
293 293
 };
294 294
 
295
+/**
296
+ * Notifies CallStats that there is an unhandled error on the page.
297
+ *
298
+ * @param {Error} e error to send
299
+ * @param {RTCPeerConnection} pc connection on which failure occured.
300
+ */
301
+Statistics.prototype.sendUnhandledError = function (e) {
302
+    if(this.callStatsIntegrationEnabled)
303
+        CallStats.sendUnhandledError(e, this.callstats);
304
+};
305
+
306
+/**
307
+ * Notifies CallStats that there is unhandled exception.
308
+ *
309
+ * @param {Error} e error to send
310
+ */
311
+Statistics.sendUnhandledError = function (e) {
312
+    CallStats.sendUnhandledError(e, null);
313
+};
314
+
295 315
 /**
296 316
  * Sends the given feedback through CallStats.
297 317
  *

Carregando…
Cancelar
Salvar