|
|
|
@ -6,6 +6,8 @@ function TraceablePeerConnection(ice_config, constraints) { |
|
|
|
|
this.stats = {}; |
|
|
|
|
this.statsinterval = null; |
|
|
|
|
this.maxstats = 0; // limit to 300 values, i.e. 5 minutes; set to 0 to disable
|
|
|
|
|
var Interop = require('sdp-interop').Interop; |
|
|
|
|
this.interop = new Interop(); |
|
|
|
|
|
|
|
|
|
// override as desired
|
|
|
|
|
this.trace = function (what, info) { |
|
|
|
@ -98,19 +100,39 @@ function TraceablePeerConnection(ice_config, constraints) { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
dumpSDP = function(description) { |
|
|
|
|
if (typeof description === 'undefined' || description == null) { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 'type: ' + description.type + '\r\n' + description.sdp; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) { |
|
|
|
|
TraceablePeerConnection.prototype.__defineGetter__('signalingState', function() { return this.peerconnection.signalingState; }); |
|
|
|
|
TraceablePeerConnection.prototype.__defineGetter__('iceConnectionState', function() { return this.peerconnection.iceConnectionState; }); |
|
|
|
|
TraceablePeerConnection.prototype.__defineGetter__('localDescription', function() { |
|
|
|
|
var publicLocalDescription = APP.simulcast.reverseTransformLocalDescription(this.peerconnection.localDescription); |
|
|
|
|
return publicLocalDescription; |
|
|
|
|
this.trace('getLocalDescription::preTransform (Plan A)', dumpSDP(this.peerconnection.localDescription)); |
|
|
|
|
// if we're running on FF, transform to Plan B first.
|
|
|
|
|
var desc = this.peerconnection.localDescription; |
|
|
|
|
if (navigator.mozGetUserMedia) { |
|
|
|
|
desc = this.interop.toPlanB(desc); |
|
|
|
|
} else { |
|
|
|
|
desc = APP.simulcast.reverseTransformLocalDescription(this.peerconnection.localDescription); |
|
|
|
|
} |
|
|
|
|
this.trace('getLocalDescription::postTransform (Plan B)', dumpSDP(desc)); |
|
|
|
|
return desc; |
|
|
|
|
}); |
|
|
|
|
TraceablePeerConnection.prototype.__defineGetter__('remoteDescription', function() { |
|
|
|
|
var publicRemoteDescription = APP.simulcast.reverseTransformRemoteDescription(this.peerconnection.remoteDescription); |
|
|
|
|
return publicRemoteDescription; |
|
|
|
|
this.trace('getRemoteDescription::preTransform (Plan A)', dumpSDP(this.peerconnection.remoteDescription)); |
|
|
|
|
// if we're running on FF, transform to Plan B first.
|
|
|
|
|
var desc = this.peerconnection.remoteDescription; |
|
|
|
|
if (navigator.mozGetUserMedia) { |
|
|
|
|
desc = this.interop.toPlanB(desc); |
|
|
|
|
} else { |
|
|
|
|
desc = APP.simulcast.reverseTransformRemoteDescription(this.peerconnection.remoteDescription); |
|
|
|
|
} |
|
|
|
|
this.trace('getRemoteDescription::postTransform (Plan B)', dumpSDP(desc)); |
|
|
|
|
return desc; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -148,9 +170,15 @@ TraceablePeerConnection.prototype.createDataChannel = function (label, opts) { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.setLocalDescription = function (description, successCallback, failureCallback) { |
|
|
|
|
this.trace('setLocalDescription::preTransform (Plan B)', dumpSDP(description)); |
|
|
|
|
// if we're running on FF, transform to Plan A first.
|
|
|
|
|
if (navigator.mozGetUserMedia) { |
|
|
|
|
description = this.interop.toPlanA(description); |
|
|
|
|
} else { |
|
|
|
|
description = APP.simulcast.transformLocalDescription(description); |
|
|
|
|
} |
|
|
|
|
this.trace('setLocalDescription::postTransform (Plan A)', dumpSDP(description)); |
|
|
|
|
var self = this; |
|
|
|
|
description = APP.simulcast.transformLocalDescription(description); |
|
|
|
|
this.trace('setLocalDescription', dumpSDP(description)); |
|
|
|
|
this.peerconnection.setLocalDescription(description, |
|
|
|
|
function () { |
|
|
|
|
self.trace('setLocalDescriptionOnSuccess'); |
|
|
|
@ -169,9 +197,16 @@ TraceablePeerConnection.prototype.setLocalDescription = function (description, s |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
TraceablePeerConnection.prototype.setRemoteDescription = function (description, successCallback, failureCallback) { |
|
|
|
|
this.trace('setRemoteDescription::preTransform (Plan B)', dumpSDP(description)); |
|
|
|
|
// if we're running on FF, transform to Plan A first.
|
|
|
|
|
if (navigator.mozGetUserMedia) { |
|
|
|
|
description = this.interop.toPlanA(description); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
description = APP.simulcast.transformRemoteDescription(description); |
|
|
|
|
} |
|
|
|
|
this.trace('setRemoteDescription::postTransform (Plan A)', dumpSDP(description)); |
|
|
|
|
var self = this; |
|
|
|
|
description = APP.simulcast.transformRemoteDescription(description); |
|
|
|
|
this.trace('setRemoteDescription', dumpSDP(description)); |
|
|
|
|
this.peerconnection.setRemoteDescription(description, |
|
|
|
|
function () { |
|
|
|
|
self.trace('setRemoteDescriptionOnSuccess'); |
|
|
|
@ -203,7 +238,12 @@ TraceablePeerConnection.prototype.createOffer = function (successCallback, failu |
|
|
|
|
this.trace('createOffer', JSON.stringify(constraints, null, ' ')); |
|
|
|
|
this.peerconnection.createOffer( |
|
|
|
|
function (offer) { |
|
|
|
|
self.trace('createOfferOnSuccess', dumpSDP(offer)); |
|
|
|
|
self.trace('createOfferOnSuccess::preTransform (Plan A)', dumpSDP(offer)); |
|
|
|
|
// if we're running on FF, transform to Plan B first.
|
|
|
|
|
if (navigator.mozGetUserMedia) { |
|
|
|
|
offer = self.interop.toPlanB(offer); |
|
|
|
|
} |
|
|
|
|
self.trace('createOfferOnSuccess::postTransform (Plan B)', dumpSDP(offer)); |
|
|
|
|
successCallback(offer); |
|
|
|
|
}, |
|
|
|
|
function(err) { |
|
|
|
@ -219,8 +259,14 @@ TraceablePeerConnection.prototype.createAnswer = function (successCallback, fail |
|
|
|
|
this.trace('createAnswer', JSON.stringify(constraints, null, ' ')); |
|
|
|
|
this.peerconnection.createAnswer( |
|
|
|
|
function (answer) { |
|
|
|
|
answer = APP.simulcast.transformAnswer(answer); |
|
|
|
|
self.trace('createAnswerOnSuccess', dumpSDP(answer)); |
|
|
|
|
self.trace('createAnswerOnSuccess::preTransfom (Plan A)', dumpSDP(answer)); |
|
|
|
|
// if we're running on FF, transform to Plan A first.
|
|
|
|
|
if (navigator.mozGetUserMedia) { |
|
|
|
|
answer = self.interop.toPlanB(answer); |
|
|
|
|
} else { |
|
|
|
|
answer = APP.simulcast.transformAnswer(answer); |
|
|
|
|
} |
|
|
|
|
self.trace('createAnswerOnSuccess::postTransfom (Plan B)', dumpSDP(answer)); |
|
|
|
|
successCallback(answer); |
|
|
|
|
}, |
|
|
|
|
function(err) { |
|
|
|
|