Преглед изворни кода

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

Global error handler and reporting those errors.
dev1
hristoterezov пре 9 година
родитељ
комит
9ac6462171
5 измењених фајлова са 77 додато и 1 уклоњено
  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 Прегледај датотеку

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

+ 39
- 0
JitsiMeetJS.js Прегледај датотеку

54
     _gumFailedHandler: [],
54
     _gumFailedHandler: [],
55
     init: function (options) {
55
     init: function (options) {
56
         Statistics.audioLevelsEnabled = !options.disableAudioLevels || true;
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
         return RTC.init(options || {});
71
         return RTC.init(options || {});
58
     },
72
     },
59
     /**
73
     /**
136
     enumerateDevices: function (callback) {
150
     enumerateDevices: function (callback) {
137
         RTC.enumerateDevices(callback);
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
      * Represents a hub/namespace for utility functionality which may be of
180
      * Represents a hub/namespace for utility functionality which may be of

+ 2
- 0
doc/API.md Прегледај датотеку

47
     8. desktopSharingFirefoxExtensionURL - The URL to the Firefox extension for desktop sharing. "null" if no extension is required.
47
     8. desktopSharingFirefoxExtensionURL - The URL to the Firefox extension for desktop sharing. "null" if no extension is required.
48
     9. disableAudioLevels - boolean property. Enables/disables audio levels.
48
     9. disableAudioLevels - boolean property. Enables/disables audio levels.
49
     10. disableSimulcast - boolean property. Enables/disables simulcast.
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
 * ```JitsiMeetJS.JitsiConnection``` - the ```JitsiConnection``` constructor. You can use that to create new server connection.
52
 * ```JitsiMeetJS.JitsiConnection``` - the ```JitsiConnection``` constructor. You can use that to create new server connection.
52
 
53
 
70
 * ```JitsiMeetJS.isDeviceListAvailable()```- returns true if retrieving the device list is support and false - otherwise.
71
 * ```JitsiMeetJS.isDeviceListAvailable()```- returns true if retrieving the device list is support and false - otherwise.
71
 
72
 
72
 * ```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.
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
 * ```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.
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
     We have two event types - connection and conference. You can access the events with the following code ```JitsiMeetJS.events.<event_type>.<event_name>```.
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 Прегледај датотеку

14
     setLocalDescription:  "setLocalDescription",
14
     setLocalDescription:  "setLocalDescription",
15
     setRemoteDescription: "setRemoteDescription",
15
     setRemoteDescription: "setRemoteDescription",
16
     addIceCandidate:      "addIceCandidate",
16
     addIceCandidate:      "addIceCandidate",
17
-    getUserMedia:         "getUserMedia"
17
+    getUserMedia:         "getUserMedia",
18
+    signallingError:      "signallingError"
18
 };
19
 };
19
 
20
 
20
 /**
21
 /**
355
     CallStats._reportError.call(cs, wrtcFuncNames.addIceCandidate, e, pc);
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
 module.exports = CallStats;
370
 module.exports = CallStats;

+ 20
- 0
modules/statistics/statistics.js Прегледај датотеку

292
         CallStats.sendAddIceCandidateFailed(e, pc, this.callstats);
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
  * Sends the given feedback through CallStats.
316
  * Sends the given feedback through CallStats.
297
  *
317
  *

Loading…
Откажи
Сачувај