Sfoglia il codice sorgente

Merge pull request #58 from damencho/global-error-handler

Global error handler and reporting those errors.
dev1
hristoterezov 9 anni fa
parent
commit
9ac6462171
5 ha cambiato i file con 77 aggiunte e 1 eliminazioni
  1. 3
    0
      JitsiConference.js
  2. 39
    0
      JitsiMeetJS.js
  3. 2
    0
      doc/API.md
  4. 13
    1
      modules/statistics/CallStats.js
  5. 20
    0
      modules/statistics/statistics.js

+ 3
- 0
JitsiConference.js Vedi File

@@ -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;

+ 39
- 0
JitsiMeetJS.js Vedi File

@@ -54,6 +54,20 @@ var LibJitsiMeet = {
54 54
     _gumFailedHandler: [],
55 55
     init: function (options) {
56 56
         Statistics.audioLevelsEnabled = !options.disableAudioLevels || true;
57
+
58
+        if (options.enableWindowOnErrorHandler) {
59
+            // if an old handler exists also fire its events
60
+            var oldOnErrorHandler = window.onerror;
61
+            window.onerror = function (message, source, lineno, colno, error) {
62
+
63
+                JitsiMeetJS.getGlobalOnErrorHandler(
64
+                    message, source, lineno, colno, error);
65
+
66
+                if(oldOnErrorHandler)
67
+                    oldOnErrorHandler(message, source, lineno, colno, error);
68
+            }
69
+        }
70
+
57 71
         return RTC.init(options || {});
58 72
     },
59 73
     /**
@@ -136,6 +150,31 @@ var LibJitsiMeet = {
136 150
     enumerateDevices: function (callback) {
137 151
         RTC.enumerateDevices(callback);
138 152
     },
153
+    /**
154
+     * Array of functions that will receive the unhandled errors.
155
+     */
156
+    _globalOnErrorHandler: [],
157
+    /**
158
+     * @returns function that can be used to be attached to window.onerror and
159
+     * if options.enableWindowOnErrorHandler is enabled returns
160
+     * the function used by the lib.
161
+     * (function(message, source, lineno, colno, error)).
162
+     */
163
+    getGlobalOnErrorHandler: function (message, source, lineno, colno, error) {
164
+        console.error(
165
+            'UnhandledError: ' + message,
166
+            'Script: ' + source,
167
+            'Line: ' + lineno,
168
+            'Column: ' + colno,
169
+            'StackTrace: ', error);
170
+
171
+        JitsiMeetJS._globalOnErrorHandler.forEach(function (handler) {
172
+            handler(error);
173
+        });
174
+        if(!JitsiMeetJS._globalOnErrorHandler.length){
175
+            Statistics.sendUnhandledError(error);
176
+        }
177
+    },
139 178
 
140 179
     /**
141 180
      * Represents a hub/namespace for utility functionality which may be of

+ 2
- 0
doc/API.md Vedi File

@@ -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 Vedi File

@@ -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 Vedi File

@@ -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
  *

Loading…
Annulla
Salva