|
|
@@ -54,23 +54,47 @@ function initCallback (err, msg) {
|
|
54
|
54
|
if (err !== 'success')
|
|
55
|
55
|
return;
|
|
56
|
56
|
|
|
|
57
|
+ CallStats.initialized = true;
|
|
|
58
|
+
|
|
|
59
|
+ var ret = callStats.addNewFabric(this.peerconnection,
|
|
|
60
|
+ Strophe.getResourceFromJid(this.session.peerjid),
|
|
|
61
|
+ callStats.fabricUsage.multiplex,
|
|
|
62
|
+ this.confID,
|
|
|
63
|
+ this.pcCallback.bind(this));
|
|
|
64
|
+
|
|
|
65
|
+ var fabricInitialized = (ret.status === 'success');
|
|
|
66
|
+
|
|
|
67
|
+ if(!fabricInitialized)
|
|
|
68
|
+ console.log("callstats fabric not initilized", ret.message);
|
|
|
69
|
+
|
|
57
|
70
|
// notify callstats about failures if there were any
|
|
58
|
71
|
if (CallStats.reportsQueue.length) {
|
|
59
|
72
|
CallStats.reportsQueue.forEach(function (report) {
|
|
60
|
|
- if (report.type === reportType.ERROR)
|
|
61
|
|
- {
|
|
|
73
|
+ if (report.type === reportType.ERROR) {
|
|
62
|
74
|
var error = report.data;
|
|
63
|
75
|
CallStats._reportError.call(this, error.type, error.error,
|
|
64
|
76
|
error.pc);
|
|
65
|
77
|
}
|
|
66
|
|
- else if (report.type === reportType.EVENT)
|
|
67
|
|
- {
|
|
68
|
|
- var data = report.data;
|
|
|
78
|
+ // if we have and event to report and we failed to add fabric
|
|
|
79
|
+ // this event will not be reported anyway, returning an error
|
|
|
80
|
+ else if (report.type === reportType.EVENT
|
|
|
81
|
+ && fabricInitialized) {
|
|
|
82
|
+ var eventData = report.data;
|
|
69
|
83
|
callStats.sendFabricEvent(
|
|
70
|
84
|
this.peerconnection,
|
|
71
|
|
- data.event,
|
|
|
85
|
+ eventData.event,
|
|
|
86
|
+ this.confID,
|
|
|
87
|
+ eventData.eventData);
|
|
|
88
|
+ } else if (report.type === reportType.MST_WITH_USERID) {
|
|
|
89
|
+ var data = report.data;
|
|
|
90
|
+ callStats.associateMstWithUserID(
|
|
|
91
|
+ this.peerconnection,
|
|
|
92
|
+ data.callStatsId,
|
|
72
|
93
|
this.confID,
|
|
73
|
|
- data.eventData);
|
|
|
94
|
+ data.ssrc,
|
|
|
95
|
+ data.usageLabel,
|
|
|
96
|
+ data.containerId
|
|
|
97
|
+ );
|
|
74
|
98
|
}
|
|
75
|
99
|
}, this);
|
|
76
|
100
|
CallStats.reportsQueue.length = 0;
|
|
|
@@ -127,11 +151,6 @@ var CallStats = _try_catch(function(jingleSession, Settings, options) {
|
|
127
|
151
|
this.userID,
|
|
128
|
152
|
initCallback.bind(this));
|
|
129
|
153
|
|
|
130
|
|
- callStats.addNewFabric(this.peerconnection,
|
|
131
|
|
- Strophe.getResourceFromJid(jingleSession.peerjid),
|
|
132
|
|
- callStats.fabricUsage.multiplex,
|
|
133
|
|
- this.confID,
|
|
134
|
|
- this.pcCallback.bind(this));
|
|
135
|
154
|
} catch (e) {
|
|
136
|
155
|
// The callstats.io API failed to initialize (e.g. because its
|
|
137
|
156
|
// download failed to succeed in general or on time). Further
|
|
|
@@ -147,13 +166,21 @@ var CallStats = _try_catch(function(jingleSession, Settings, options) {
|
|
147
|
166
|
// and send them to callstats on init
|
|
148
|
167
|
CallStats.reportsQueue = [];
|
|
149
|
168
|
|
|
|
169
|
+/**
|
|
|
170
|
+ * Whether the library was successfully initialized using its initialize method.
|
|
|
171
|
+ * And whether we had successfully called addNewFabric.
|
|
|
172
|
+ * @type {boolean}
|
|
|
173
|
+ */
|
|
|
174
|
+CallStats.initialized = false;
|
|
|
175
|
+
|
|
150
|
176
|
/**
|
|
151
|
177
|
* Type of pending reports, can be event or an error.
|
|
152
|
178
|
* @type {{ERROR: string, EVENT: string}}
|
|
153
|
179
|
*/
|
|
154
|
180
|
var reportType = {
|
|
155
|
181
|
ERROR: "error",
|
|
156
|
|
- EVENT: "event"
|
|
|
182
|
+ EVENT: "event",
|
|
|
183
|
+ MST_WITH_USERID: "mstWithUserID"
|
|
157
|
184
|
};
|
|
158
|
185
|
|
|
159
|
186
|
CallStats.prototype.pcCallback = _try_catch(function (err, msg) {
|
|
|
@@ -166,6 +193,7 @@ CallStats.prototype.pcCallback = _try_catch(function (err, msg) {
|
|
166
|
193
|
/**
|
|
167
|
194
|
* Lets CallStats module know where is given SSRC rendered by providing renderer
|
|
168
|
195
|
* tag ID.
|
|
|
196
|
+ * If the lib is not initialized yet queue the call for later, when its ready.
|
|
169
|
197
|
* @param ssrc {number} the SSRC of the stream
|
|
170
|
198
|
* @param isLocal {boolean} <tt>true<tt> if this stream is local or
|
|
171
|
199
|
* <tt>false</tt> otherwise.
|
|
|
@@ -195,14 +223,27 @@ function (ssrc, isLocal, usageLabel, containerId) {
|
|
195
|
223
|
usageLabel,
|
|
196
|
224
|
containerId
|
|
197
|
225
|
);
|
|
198
|
|
- callStats.associateMstWithUserID(
|
|
199
|
|
- this.peerconnection,
|
|
200
|
|
- callStatsId,
|
|
201
|
|
- this.confID,
|
|
202
|
|
- ssrc,
|
|
203
|
|
- usageLabel,
|
|
204
|
|
- containerId
|
|
205
|
|
- );
|
|
|
226
|
+ if(CallStats.initialized) {
|
|
|
227
|
+ callStats.associateMstWithUserID(
|
|
|
228
|
+ this.peerconnection,
|
|
|
229
|
+ callStatsId,
|
|
|
230
|
+ this.confID,
|
|
|
231
|
+ ssrc,
|
|
|
232
|
+ usageLabel,
|
|
|
233
|
+ containerId
|
|
|
234
|
+ );
|
|
|
235
|
+ }
|
|
|
236
|
+ else {
|
|
|
237
|
+ CallStats.reportsQueue.push({
|
|
|
238
|
+ type: reportType.MST_WITH_USERID,
|
|
|
239
|
+ data: {
|
|
|
240
|
+ callStatsId: callStatsId,
|
|
|
241
|
+ ssrc: ssrc,
|
|
|
242
|
+ usageLabel: usageLabel,
|
|
|
243
|
+ containerId: containerId
|
|
|
244
|
+ }
|
|
|
245
|
+ });
|
|
|
246
|
+ }
|
|
206
|
247
|
}).bind(this)();
|
|
207
|
248
|
};
|
|
208
|
249
|
|
|
|
@@ -267,7 +308,7 @@ CallStats.sendАctiveDeviceListEvent = _try_catch(function (devicesData, cs) {
|
|
267
|
308
|
* @private
|
|
268
|
309
|
*/
|
|
269
|
310
|
CallStats._reportEvent = function (event, eventData) {
|
|
270
|
|
- if (callStats) {
|
|
|
311
|
+ if (CallStats.initialized) {
|
|
271
|
312
|
callStats.sendFabricEvent(
|
|
272
|
313
|
this.peerconnection, event, this.confID, eventData);
|
|
273
|
314
|
} else {
|
|
|
@@ -282,7 +323,7 @@ CallStats._reportEvent = function (event, eventData) {
|
|
282
|
323
|
* Notifies CallStats for connection setup errors
|
|
283
|
324
|
*/
|
|
284
|
325
|
CallStats.prototype.sendTerminateEvent = _try_catch(function () {
|
|
285
|
|
- if(!callStats) {
|
|
|
326
|
+ if(!CallStats.initialized) {
|
|
286
|
327
|
return;
|
|
287
|
328
|
}
|
|
288
|
329
|
callStats.sendFabricEvent(this.peerconnection,
|
|
|
@@ -308,7 +349,7 @@ CallStats.prototype.sendIceConnectionFailedEvent = _try_catch(function (pc, cs){
|
|
308
|
349
|
*/
|
|
309
|
350
|
CallStats.prototype.sendFeedback = _try_catch(
|
|
310
|
351
|
function(overallFeedback, detailedFeedback) {
|
|
311
|
|
- if(!callStats) {
|
|
|
352
|
+ if(!CallStats.initialized) {
|
|
312
|
353
|
return;
|
|
313
|
354
|
}
|
|
314
|
355
|
var feedbackString = '{"userID":"' + this.userID + '"' +
|
|
|
@@ -333,7 +374,7 @@ CallStats._reportError = function (type, e, pc) {
|
|
333
|
374
|
logger.warn("No error is passed!");
|
|
334
|
375
|
e = new Error("Unknown error");
|
|
335
|
376
|
}
|
|
336
|
|
- if (callStats) {
|
|
|
377
|
+ if (CallStats.initialized) {
|
|
337
|
378
|
callStats.reportError(pc, this.confID, type, e);
|
|
338
|
379
|
} else {
|
|
339
|
380
|
CallStats.reportsQueue.push({
|