Skip to content

Commit

Permalink
Enhance RTCPeerconnection SDP error handling. Thanks @ibc for reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan committed Dec 28, 2012
1 parent d4e079b commit a8a7627
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
38 changes: 20 additions & 18 deletions src/MediaSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ JsSIP.MediaSession.prototype = {
}

/** @private */
function onGetUserMediaFailure() {
onFailure();
function onGetUserMediaFailure(e) {
onFailure(e);
}

this.getUserMedia(mediaType, onGetUserMediaSuccess, onGetUserMediaFailure);
Expand Down Expand Up @@ -82,16 +82,22 @@ JsSIP.MediaSession.prototype = {
// add stream to peerConnection
self.peerConnection.addStream(stream);

self.peerConnection.setRemoteDescription(new window.RTCSessionDescription({type:'offer', sdp:sdp}));

// Set local description and start Ice.
self.peerConnection.createAnswer(function(sessionDescription){
self.peerConnection.setLocalDescription(sessionDescription);
});
self.peerConnection.setRemoteDescription(
new window.RTCSessionDescription({type:'offer', sdp:sdp}),
function() {
self.peerConnection.createAnswer(
function(sessionDescription){
self.peerConnection.setLocalDescription(sessionDescription);
},
onSdpFailure
);
},
onSdpFailure
);
}

function onGetUserMediaFailure() {
onMediaFailure();
function onGetUserMediaFailure(e) {
onMediaFailure(e);
}

self.getUserMedia({'audio':true, 'video':true}, onGetUserMediaSuccess, onGetUserMediaFailure);
Expand Down Expand Up @@ -185,8 +191,8 @@ JsSIP.MediaSession.prototype = {
onSuccess(stream);
}

function getFailure() {
onFailure();
function getFailure(e) {
onFailure(e);
}

// Get User Media
Expand All @@ -206,12 +212,8 @@ JsSIP.MediaSession.prototype = {
if (type === 'offer') {
console.log(JsSIP.c.LOG_MEDIA_SESSION +'re-Invite received');
} else if (type === 'answer') {
try {
this.peerConnection.setRemoteDescription(new window.RTCSessionDescription({type:'answer', sdp:sdp}));
onSuccess();
} catch (e) {
onFailure(e);
}
this.peerConnection.setRemoteDescription(
new window.RTCSessionDescription({type:'answer', sdp:sdp}), onSuccess, onFailure);
}
}
};
12 changes: 6 additions & 6 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ JsSIP.Session.prototype.receiveInitialRequest = function(ua, request) {
* @param {HTMLVideoElement} remoteView
*/
this.answer = function(selfView, remoteView) {
var offer, onMediaSuccess, onMediaFailure, onSdpFailure;
var offer, onSuccess, onMediaFailure, onSdpFailure;

// Check UA Status
JsSIP.utils.checkUAStatus(this.ua);
Expand All @@ -385,7 +385,7 @@ JsSIP.Session.prototype.receiveInitialRequest = function(ua, request) {

offer = request.body;

onMediaSuccess = function() {
onSuccess = function() {
var sdp = session.mediaSession.peerConnection.localDescription.sdp;

if(!session.createConfirmedDialog(request, 'UAS')) {
Expand Down Expand Up @@ -435,7 +435,7 @@ JsSIP.Session.prototype.receiveInitialRequest = function(ua, request) {

//Initialize Media Session
session.mediaSession = new JsSIP.MediaSession(session, selfView, remoteView);
session.mediaSession.startCallee(onMediaSuccess, onMediaFailure, onSdpFailure, offer);
session.mediaSession.startCallee(onSuccess, onMediaFailure, onSdpFailure, offer);
};

// Fire 'call' event callback
Expand Down Expand Up @@ -526,7 +526,7 @@ JsSIP.Session.prototype.receiveResponse = function(response) {
return;
}

this.acceptAndTerminate(response,'SIP ;cause= 400 ;text= "Missing session description"');
this.acceptAndTerminate(response,'SIP ;cause=400 ;text= "Missing session description"');
this.failed('remote', response, JsSIP.c.causes.BAD_MEDIA_DESCRIPTION);

break;
Expand Down Expand Up @@ -561,7 +561,7 @@ JsSIP.Session.prototype.receiveResponse = function(response) {
*/
function(e) {
console.warn(e);
session.acceptAndTerminate(response, 'SIP ;cause= 488 ;text= "Not Acceptable Here"');
session.acceptAndTerminate(response, 'SIP ;cause=488 ;text="Not Acceptable Here"');
session.failed('remote', response, JsSIP.c.causes.BAD_MEDIA_DESCRIPTION);
}
);
Expand Down Expand Up @@ -947,7 +947,7 @@ JsSIP.Session.prototype.sendInitialRequest = function(mediaType) {
request_sender.send();
}

function onMediaFailure(fail,e) {
function onMediaFailure(e) {
if (self.status !== JsSIP.c.SESSION_TERMINATED) {
console.log(JsSIP.c.LOG_CLIENT_INVITE_SESSION +'Media Access denied');
self.failed('local', null, JsSIP.c.causes.USER_DENIED_MEDIA_ACCESS);
Expand Down

0 comments on commit a8a7627

Please sign in to comment.