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