|
@@ -4,15 +4,15 @@ var XMPPEvents = require("../../service/xmpp/XMPPEvents");
|
4
|
4
|
|
5
|
5
|
function TraceablePeerConnection(ice_config, constraints, session) {
|
6
|
6
|
var self = this;
|
7
|
|
- var RTCPeerconnectionType = null;
|
|
7
|
+ var RTCPeerConnectionType = null;
|
8
|
8
|
if (RTCBrowserType.isFirefox()) {
|
9
|
|
- RTCPeerconnectionType = mozRTCPeerConnection;
|
|
9
|
+ RTCPeerConnectionType = mozRTCPeerConnection;
|
10
|
10
|
} else if (RTCBrowserType.isTemasysPluginUsed()) {
|
11
|
|
- RTCPeerconnectionType = RTCPeerConnection;
|
|
11
|
+ RTCPeerConnectionType = RTCPeerConnection;
|
12
|
12
|
} else {
|
13
|
|
- RTCPeerconnectionType = webkitRTCPeerConnection;
|
|
13
|
+ RTCPeerConnectionType = webkitRTCPeerConnection;
|
14
|
14
|
}
|
15
|
|
- this.peerconnection = new RTCPeerconnectionType(ice_config, constraints);
|
|
15
|
+ this.peerconnection = new RTCPeerConnectionType(ice_config, constraints);
|
16
|
16
|
this.updateLog = [];
|
17
|
17
|
this.stats = {};
|
18
|
18
|
this.statsinterval = null;
|
|
@@ -95,9 +95,8 @@ function TraceablePeerConnection(ice_config, constraints, session) {
|
95
|
95
|
this.statsinterval = window.setInterval(function() {
|
96
|
96
|
self.peerconnection.getStats(function(stats) {
|
97
|
97
|
var results = stats.result();
|
|
98
|
+ var now = new Date();
|
98
|
99
|
for (var i = 0; i < results.length; ++i) {
|
99
|
|
- //console.log(results[i].type, results[i].id, results[i].names())
|
100
|
|
- var now = new Date();
|
101
|
100
|
results[i].names().forEach(function (name) {
|
102
|
101
|
var id = results[i].id + '-' + name;
|
103
|
102
|
if (!self.stats[id]) {
|
|
@@ -121,9 +120,12 @@ function TraceablePeerConnection(ice_config, constraints, session) {
|
121
|
120
|
|
122
|
121
|
}, 1000);
|
123
|
122
|
}
|
124
|
|
-};
|
|
123
|
+}
|
125
|
124
|
|
126
|
|
-dumpSDP = function(description) {
|
|
125
|
+/**
|
|
126
|
+ * Returns a string representation of a SessionDescription object.
|
|
127
|
+ */
|
|
128
|
+var dumpSDP = function(description) {
|
127
|
129
|
if (typeof description === 'undefined' || description == null) {
|
128
|
130
|
return '';
|
129
|
131
|
}
|
|
@@ -135,7 +137,7 @@ dumpSDP = function(description) {
|
135
|
137
|
* Takes a SessionDescription object and returns a "normalized" version.
|
136
|
138
|
* Currently it only takes care of ordering the a=ssrc lines.
|
137
|
139
|
*/
|
138
|
|
-normalizePlanB = function(desc) {
|
|
140
|
+var normalizePlanB = function(desc) {
|
139
|
141
|
if (typeof desc !== 'object' || desc === null ||
|
140
|
142
|
typeof desc.sdp !== 'string') {
|
141
|
143
|
console.warn('An empty description was passed as an argument.');
|
|
@@ -199,30 +201,38 @@ normalizePlanB = function(desc) {
|
199
|
201
|
};
|
200
|
202
|
|
201
|
203
|
if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) {
|
202
|
|
- TraceablePeerConnection.prototype.__defineGetter__('signalingState', function() { return this.peerconnection.signalingState; });
|
203
|
|
- TraceablePeerConnection.prototype.__defineGetter__('iceConnectionState', function() { return this.peerconnection.iceConnectionState; });
|
204
|
|
- TraceablePeerConnection.prototype.__defineGetter__('localDescription', function() {
|
205
|
|
- var desc = this.peerconnection.localDescription;
|
206
|
|
- this.trace('getLocalDescription::preTransform', dumpSDP(desc));
|
207
|
|
-
|
208
|
|
- // if we're running on FF, transform to Plan B first.
|
209
|
|
- if (RTCBrowserType.usesUnifiedPlan()) {
|
210
|
|
- desc = this.interop.toPlanB(desc);
|
211
|
|
- this.trace('getLocalDescription::postTransform (Plan B)', dumpSDP(desc));
|
212
|
|
- }
|
213
|
|
- return desc;
|
214
|
|
- });
|
215
|
|
- TraceablePeerConnection.prototype.__defineGetter__('remoteDescription', function() {
|
216
|
|
- var desc = this.peerconnection.remoteDescription;
|
217
|
|
- this.trace('getRemoteDescription::preTransform', dumpSDP(desc));
|
218
|
|
-
|
219
|
|
- // if we're running on FF, transform to Plan B first.
|
220
|
|
- if (RTCBrowserType.usesUnifiedPlan()) {
|
221
|
|
- desc = this.interop.toPlanB(desc);
|
222
|
|
- this.trace('getRemoteDescription::postTransform (Plan B)', dumpSDP(desc));
|
223
|
|
- }
|
224
|
|
- return desc;
|
225
|
|
- });
|
|
204
|
+ TraceablePeerConnection.prototype.__defineGetter__(
|
|
205
|
+ 'signalingState',
|
|
206
|
+ function() { return this.peerconnection.signalingState; });
|
|
207
|
+ TraceablePeerConnection.prototype.__defineGetter__(
|
|
208
|
+ 'iceConnectionState',
|
|
209
|
+ function() { return this.peerconnection.iceConnectionState; });
|
|
210
|
+ TraceablePeerConnection.prototype.__defineGetter__(
|
|
211
|
+ 'localDescription',
|
|
212
|
+ function() {
|
|
213
|
+ var desc = this.peerconnection.localDescription;
|
|
214
|
+ this.trace('getLocalDescription::preTransform', dumpSDP(desc));
|
|
215
|
+
|
|
216
|
+ // if we're running on FF, transform to Plan B first.
|
|
217
|
+ if (RTCBrowserType.usesUnifiedPlan()) {
|
|
218
|
+ desc = this.interop.toPlanB(desc);
|
|
219
|
+ this.trace('getLocalDescription::postTransform (Plan B)', dumpSDP(desc));
|
|
220
|
+ }
|
|
221
|
+ return desc;
|
|
222
|
+ });
|
|
223
|
+ TraceablePeerConnection.prototype.__defineGetter__(
|
|
224
|
+ 'remoteDescription',
|
|
225
|
+ function() {
|
|
226
|
+ var desc = this.peerconnection.remoteDescription;
|
|
227
|
+ this.trace('getRemoteDescription::preTransform', dumpSDP(desc));
|
|
228
|
+
|
|
229
|
+ // if we're running on FF, transform to Plan B first.
|
|
230
|
+ if (RTCBrowserType.usesUnifiedPlan()) {
|
|
231
|
+ desc = this.interop.toPlanB(desc);
|
|
232
|
+ this.trace('getRemoteDescription::postTransform (Plan B)', dumpSDP(desc));
|
|
233
|
+ }
|
|
234
|
+ return desc;
|
|
235
|
+ });
|
226
|
236
|
}
|
227
|
237
|
|
228
|
238
|
TraceablePeerConnection.prototype.addStream = function (stream) {
|
|
@@ -234,7 +244,6 @@ TraceablePeerConnection.prototype.addStream = function (stream) {
|
234
|
244
|
catch (e)
|
235
|
245
|
{
|
236
|
246
|
console.error(e);
|
237
|
|
- return;
|
238
|
247
|
}
|
239
|
248
|
};
|
240
|
249
|
|
|
@@ -272,7 +281,8 @@ TraceablePeerConnection.prototype.createDataChannel = function (label, opts) {
|
272
|
281
|
return this.peerconnection.createDataChannel(label, opts);
|
273
|
282
|
};
|
274
|
283
|
|
275
|
|
-TraceablePeerConnection.prototype.setLocalDescription = function (description, successCallback, failureCallback) {
|
|
284
|
+TraceablePeerConnection.prototype.setLocalDescription
|
|
285
|
+ = function (description, successCallback, failureCallback) {
|
276
|
286
|
this.trace('setLocalDescription::preTransform', dumpSDP(description));
|
277
|
287
|
// if we're running on FF, transform to Plan A first.
|
278
|
288
|
if (RTCBrowserType.usesUnifiedPlan()) {
|
|
@@ -298,7 +308,8 @@ TraceablePeerConnection.prototype.setLocalDescription = function (description, s
|
298
|
308
|
*/
|
299
|
309
|
};
|
300
|
310
|
|
301
|
|
-TraceablePeerConnection.prototype.setRemoteDescription = function (description, successCallback, failureCallback) {
|
|
311
|
+TraceablePeerConnection.prototype.setRemoteDescription
|
|
312
|
+ = function (description, successCallback, failureCallback) {
|
302
|
313
|
this.trace('setRemoteDescription::preTransform', dumpSDP(description));
|
303
|
314
|
// TODO the focus should squeze or explode the remote simulcast
|
304
|
315
|
description = this.simulcast.mungeRemoteDescription(description);
|
|
@@ -341,7 +352,8 @@ TraceablePeerConnection.prototype.close = function () {
|
341
|
352
|
this.peerconnection.close();
|
342
|
353
|
};
|
343
|
354
|
|
344
|
|
-TraceablePeerConnection.prototype.createOffer = function (successCallback, failureCallback, constraints) {
|
|
355
|
+TraceablePeerConnection.prototype.createOffer
|
|
356
|
+ = function (successCallback, failureCallback, constraints) {
|
345
|
357
|
var self = this;
|
346
|
358
|
this.trace('createOffer', JSON.stringify(constraints, null, ' '));
|
347
|
359
|
this.peerconnection.createOffer(
|
|
@@ -369,20 +381,21 @@ TraceablePeerConnection.prototype.createOffer = function (successCallback, failu
|
369
|
381
|
);
|
370
|
382
|
};
|
371
|
383
|
|
372
|
|
-TraceablePeerConnection.prototype.createAnswer = function (successCallback, failureCallback, constraints) {
|
|
384
|
+TraceablePeerConnection.prototype.createAnswer
|
|
385
|
+ = function (successCallback, failureCallback, constraints) {
|
373
|
386
|
var self = this;
|
374
|
387
|
this.trace('createAnswer', JSON.stringify(constraints, null, ' '));
|
375
|
388
|
this.peerconnection.createAnswer(
|
376
|
389
|
function (answer) {
|
377
|
|
- self.trace('createAnswerOnSuccess::preTransfom', dumpSDP(answer));
|
|
390
|
+ self.trace('createAnswerOnSuccess::preTransform', dumpSDP(answer));
|
378
|
391
|
// if we're running on FF, transform to Plan A first.
|
379
|
392
|
if (RTCBrowserType.usesUnifiedPlan()) {
|
380
|
393
|
answer = self.interop.toPlanB(answer);
|
381
|
|
- self.trace('createAnswerOnSuccess::postTransfom (Plan B)', dumpSDP(answer));
|
|
394
|
+ self.trace('createAnswerOnSuccess::postTransform (Plan B)', dumpSDP(answer));
|
382
|
395
|
}
|
383
|
396
|
if (config.enableSimulcast && self.simulcast.isSupported()) {
|
384
|
397
|
answer = self.simulcast.mungeLocalDescription(answer);
|
385
|
|
- self.trace('createAnswerOnSuccess::postTransfom (simulcast)', dumpSDP(answer));
|
|
398
|
+ self.trace('createAnswerOnSuccess::postTransform (simulcast)', dumpSDP(answer));
|
386
|
399
|
}
|
387
|
400
|
successCallback(answer);
|
388
|
401
|
},
|
|
@@ -394,8 +407,9 @@ TraceablePeerConnection.prototype.createAnswer = function (successCallback, fail
|
394
|
407
|
);
|
395
|
408
|
};
|
396
|
409
|
|
397
|
|
-TraceablePeerConnection.prototype.addIceCandidate = function (candidate, successCallback, failureCallback) {
|
398
|
|
- var self = this;
|
|
410
|
+TraceablePeerConnection.prototype.addIceCandidate
|
|
411
|
+ = function (candidate, successCallback, failureCallback) {
|
|
412
|
+ //var self = this;
|
399
|
413
|
this.trace('addIceCandidate', JSON.stringify(candidate, null, ' '));
|
400
|
414
|
this.peerconnection.addIceCandidate(candidate);
|
401
|
415
|
/* maybe later
|
|
@@ -418,7 +432,7 @@ TraceablePeerConnection.prototype.getStats = function(callback, errback) {
|
418
|
432
|
// ignore for now...
|
419
|
433
|
if(!errback)
|
420
|
434
|
errback = function () {};
|
421
|
|
- this.peerconnection.getStats(null,callback,errback);
|
|
435
|
+ this.peerconnection.getStats(null, callback, errback);
|
422
|
436
|
} else {
|
423
|
437
|
this.peerconnection.getStats(callback);
|
424
|
438
|
}
|