瀏覽代碼

accumulate erorrs unitl connected to callstats

master
isymchych 10 年之前
父節點
當前提交
72c39a0162

+ 56
- 47
modules/statistics/CallStats.js 查看文件

@@ -5,20 +5,35 @@ var jsSHA = require('jssha');
5 5
 var io = require('socket.io-client');
6 6
 var callStats = null;
7 7
 
8
-// getUserMedia calls happen before CallStats init
9
-// so if there are any getUserMedia errors, we store them in this array
8
+/**
9
+ * @const
10
+ * @see http://www.callstats.io/api/#enumeration-of-wrtcfuncnames
11
+ */
12
+var wrtcFuncNames = {
13
+    createOffer:          "createOffer",
14
+    createAnswer:         "createAnswer",
15
+    setLocalDescription:  "setLocalDescription",
16
+    setRemoteDescription: "setRemoteDescription",
17
+    addIceCandidate:      "addIceCandidate",
18
+    getUserMedia:         "getUserMedia"
19
+};
20
+
21
+// some errors may happen before CallStats init
22
+// in this case we accumulate them in this array
10 23
 // and send them to callstats on init
11
-var pendingUserMediaErrors = [];
24
+var pendingErrors = [];
12 25
 
13 26
 function initCallback (err, msg) {
14
-    console.log("Initializing Status: err="+err+" msg="+msg);
27
+    console.log("CallStats Status: err=" + err + " msg=" + msg);
15 28
 }
16 29
 
30
+var callStatsIntegrationEnabled = config.callStatsID && config.callStatsSecret;
31
+
17 32
 var CallStats = {
18 33
     init: function (jingleSession) {
19
-
20
-        if(!config.callStatsID || !config.callStatsSecret || callStats !== null)
34
+        if(!callStatsIntegrationEnabled || callStats !== null) {
21 35
             return;
36
+        }
22 37
 
23 38
         callStats = new callstats($, io, jsSHA);
24 39
 
@@ -44,10 +59,12 @@ var CallStats = {
44 59
             this.confID,
45 60
             this.pcCallback.bind(this));
46 61
 
47
-        // notify callstats about getUserMedia failures if there were any
48
-        if (pendingUserMediaErrors.length) {
49
-            pendingUserMediaErrors.forEach(this.sendGetUserMediaFailed, this);
50
-            pendingUserMediaErrors.length = 0;
62
+        // notify callstats about failures if there were any
63
+        if (pendingErrors.length) {
64
+            pendingErrors.forEach(function (error) {
65
+                this._reportError(error.type, error.error, error.pc);
66
+            }, this);
67
+            pendingErrors.length = 0;
51 68
         }
52 69
     },
53 70
     pcCallback: function (err, msg) {
@@ -109,84 +126,76 @@ var CallStats = {
109 126
             this.confID, feedbackJSON);
110 127
     },
111 128
 
129
+    _reportError: function (type, e, pc) {
130
+        if (callStats) {
131
+            callStats.reportError(pc, this.confID, type, e);
132
+        } else if (callStatsIntegrationEnabled) {
133
+            pendingErrors.push({
134
+                type: type,
135
+                error: e,
136
+                pc: pc
137
+            });
138
+        }
139
+        // else just ignore it
140
+    },
141
+
112 142
     /**
113 143
      * Notifies CallStats that getUserMedia failed.
114 144
      *
115 145
      * @param {Error} e error to send
116 146
      */
117 147
     sendGetUserMediaFailed: function (e) {
118
-        if(!callStats) {
119
-            pendingUserMediaErrors.push(e);
120
-            return;
121
-        }
122
-        callStats.reportError(this.peerconnection, this.confID,
123
-                              callStats.webRTCFunctions.getUserMedia, e);
148
+        this._reportError(wrtcFuncNames.getUserMedia, e, null);
124 149
     },
125 150
 
126 151
     /**
127 152
      * Notifies CallStats that peer connection failed to create offer.
128 153
      *
129 154
      * @param {Error} e error to send
155
+     * @param {RTCPeerConnection} pc connection on which failure occured.
130 156
      */
131
-    sendCreateOfferFailed: function (e) {
132
-        if(!callStats) {
133
-            return;
134
-        }
135
-        callStats.reportError(this.peerconnection, this.confID,
136
-                              callStats.webRTCFunctions.createOffer, e);
157
+    sendCreateOfferFailed: function (e, pc) {
158
+        this._reportError(wrtcFuncNames.createOffer, e, pc);
137 159
     },
138 160
 
139 161
     /**
140 162
      * Notifies CallStats that peer connection failed to create answer.
141 163
      *
142 164
      * @param {Error} e error to send
165
+     * @param {RTCPeerConnection} pc connection on which failure occured.
143 166
      */
144
-    sendCreateAnswerFailed: function (e) {
145
-        if(!callStats) {
146
-            return;
147
-        }
148
-        callStats.reportError(this.peerconnection, this.confID,
149
-                              callStats.webRTCFunctions.createAnswer, e);
167
+    sendCreateAnswerFailed: function (e, pc) {
168
+        this._reportError(wrtcFuncNames.createAnswer, e, pc);
150 169
     },
151 170
 
152 171
     /**
153 172
      * Notifies CallStats that peer connection failed to set local description.
154 173
      *
155 174
      * @param {Error} e error to send
175
+     * @param {RTCPeerConnection} pc connection on which failure occured.
156 176
      */
157
-    sendSetLocalDescFailed: function (e) {
158
-        if(!callStats) {
159
-            return;
160
-        }
161
-        callStats.reportError(this.peerconnection, this.confID,
162
-                              callStats.webRTCFunctions.setLocalDescription, e);
177
+    sendSetLocalDescFailed: function (e, pc) {
178
+        this._reportError(wrtcFuncNames.setLocalDescription, e, pc);
163 179
     },
164 180
 
165 181
     /**
166 182
      * Notifies CallStats that peer connection failed to set remote description.
167 183
      *
168 184
      * @param {Error} e error to send
185
+     * @param {RTCPeerConnection} pc connection on which failure occured.
169 186
      */
170
-    sendSetRemoteDescFailed: function (e) {
171
-        if(!callStats) {
172
-            return;
173
-        }
174
-        callStats.reportError(
175
-            this.peerconnection, this.confID,
176
-            callStats.webRTCFunctions.setRemoteDescription, e);
187
+    sendSetRemoteDescFailed: function (e, pc) {
188
+        this._reportError(wrtcFuncNames.setRemoteDescription, e, pc);
177 189
     },
178 190
 
179 191
     /**
180 192
      * Notifies CallStats that peer connection failed to add ICE candidate.
181 193
      *
182 194
      * @param {Error} e error to send
195
+     * @param {RTCPeerConnection} pc connection on which failure occured.
183 196
      */
184
-    sendAddIceCandidateFailed: function (e) {
185
-        if(!callStats) {
186
-            return;
187
-        }
188
-        callStats.reportError(this.peerconnection, this.confID,
189
-                              callStats.webRTCFunctions.addIceCandidate, e);
197
+    sendAddIceCandidateFailed: function (e, pc) {
198
+        this._reportError(wrtcFuncNames.addIceCandidate, e, pc);
190 199
     }
191 200
 };
192 201
 module.exports = CallStats;

+ 18
- 13
modules/statistics/statistics.js 查看文件

@@ -113,25 +113,30 @@ var statistics = {
113 113
         APP.RTC.addListener(RTCEvents.GET_USER_MEDIA_FAILED, function (e) {
114 114
             CallStats.sendGetUserMediaFailed(e);
115 115
         });
116
-        APP.xmpp.addListener(RTCEvents.CREATE_OFFER_FAILED, function (e) {
117
-            CallStats.sendCreateOfferFailed(e);
116
+        APP.xmpp.addListener(RTCEvents.CREATE_OFFER_FAILED, function (e, pc) {
117
+            CallStats.sendCreateOfferFailed(e, pc);
118 118
         });
119
-        APP.xmpp.addListener(RTCEvents.CREATE_ANSWER_FAILED, function (e) {
120
-            CallStats.sendCreateAnswerFailed(e);
119
+        APP.xmpp.addListener(RTCEvents.CREATE_ANSWER_FAILED, function (e, pc) {
120
+            CallStats.sendCreateAnswerFailed(e, pc);
121 121
         });
122 122
         APP.xmpp.addListener(
123 123
             RTCEvents.SET_LOCAL_DESCRIPTION_FAILED,
124
-            function (e) {
125
-                CallStats.sendSetLocalDescFailed(e);
126
-        });
124
+            function (e, pc) {
125
+                CallStats.sendSetLocalDescFailed(e, pc);
126
+            }
127
+        );
127 128
         APP.xmpp.addListener(
128 129
             RTCEvents.SET_REMOTE_DESCRIPTION_FAILED,
129
-            function (e) {
130
-                CallStats.sendSetRemoteDescFailed(e);
131
-        });
132
-        APP.xmpp.addListener(RTCEvents.ADD_ICE_CANDIDATE_FAILED, function (e) {
133
-            CallStats.sendAddIceCandidateFailed(e);
134
-        });
130
+            function (e, pc) {
131
+                CallStats.sendSetRemoteDescFailed(e, pc);
132
+            }
133
+        );
134
+        APP.xmpp.addListener(
135
+            RTCEvents.ADD_ICE_CANDIDATE_FAILED,
136
+            function (e, pc) {
137
+                CallStats.sendAddIceCandidateFailed(e, pc);
138
+            }
139
+        );
135 140
     }
136 141
 };
137 142
 

+ 1
- 1
modules/xmpp/JingleSessionPC.js 查看文件

@@ -720,7 +720,7 @@ JingleSessionPC.prototype.addIceCandidate = function (elem) {
720 720
                 self.peerconnection.addIceCandidate(candidate);
721 721
             } catch (e) {
722 722
                 console.error('addIceCandidate failed', e.toString(), line);
723
-                self.eventEmitter.emit(RTCEvents.ADD_ICE_CANDIDATE_FAILED, err);
723
+                self.eventEmitter.emit(RTCEvents.ADD_ICE_CANDIDATE_FAILED, err, self.peerconnection);
724 724
             }
725 725
         });
726 726
     });

+ 4
- 4
modules/xmpp/TraceablePeerConnection.js 查看文件

@@ -295,7 +295,7 @@ TraceablePeerConnection.prototype.setLocalDescription
295 295
         },
296 296
         function (err) {
297 297
             self.trace('setLocalDescriptionOnFailure', err);
298
-            self.eventEmitter.emit(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED, err);
298
+            self.eventEmitter.emit(RTCEvents.SET_LOCAL_DESCRIPTION_FAILED, err, self.peerconnection);
299 299
             failureCallback(err);
300 300
         }
301 301
     );
@@ -331,7 +331,7 @@ TraceablePeerConnection.prototype.setRemoteDescription
331 331
         },
332 332
         function (err) {
333 333
             self.trace('setRemoteDescriptionOnFailure', err);
334
-            self.eventEmitter.emit(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED, err);
334
+            self.eventEmitter.emit(RTCEvents.SET_REMOTE_DESCRIPTION_FAILED, err, self.peerconnection);
335 335
             failureCallback(err);
336 336
         }
337 337
     );
@@ -377,7 +377,7 @@ TraceablePeerConnection.prototype.createOffer
377 377
         },
378 378
         function(err) {
379 379
             self.trace('createOfferOnFailure', err);
380
-            self.eventEmitter.emit(RTCEvents.CREATE_OFFER_FAILED, err);
380
+            self.eventEmitter.emit(RTCEvents.CREATE_OFFER_FAILED, err, self.peerconnection);
381 381
             failureCallback(err);
382 382
         },
383 383
         constraints
@@ -408,7 +408,7 @@ TraceablePeerConnection.prototype.createAnswer
408 408
         },
409 409
         function(err) {
410 410
             self.trace('createAnswerOnFailure', err);
411
-            self.eventEmitter.emit(RTCEvents.CREATE_ANSWER_FAILED, err);
411
+            self.eventEmitter.emit(RTCEvents.CREATE_ANSWER_FAILED, err, self.peerconnection);
412 412
             failureCallback(err);
413 413
         },
414 414
         constraints

Loading…
取消
儲存