Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
egreenmachine committed Sep 27, 2018
2 parents 4606ce0 + ad924c1 commit f1e8ea7
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 62 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module.exports = {
"globals": {
"Uint8Array": false
},
"parserOptions": {
"ecmaVersion": 6
},
"extends": "eslint:recommended",
"rules": {
"accessor-pairs": "error",
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sip.js",
"version": "0.11.3",
"version": "0.11.4",
"authors": [
"James Criscuolo <[email protected]>",
"Eric Green <[email protected]>",
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sip.js",
"title": "SIP.js",
"description": "A simple, intuitive, and powerful JavaScript signaling library",
"version": "0.11.3",
"version": "0.11.4",
"main": "dist/sip.js",
"browser": {
"./src/environment.js": "./src/environment_browser.js"
Expand All @@ -29,19 +29,18 @@
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"eslint": "^4.9.0",
"jasmine-core": "^3.1.0",
"karma": "^2.0.2",
"eslint": "^5.4.0",
"jasmine-core": "^3.2.1",
"karma": "^3.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-jasmine-html-reporter": "^1.2.0",
"karma-jasmine-html-reporter": "^1.3.1",
"karma-mocha-reporter": "^2.2.5",
"karma-webpack": "^3.0.0",
"pegjs": "^0.10.0",
"pegjs-loader": "^0.5.4",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "^4.16.0",
"webpack": "^4.19.0",
"webpack-cli": "^3.0.8"
},
"engines": {
Expand Down
13 changes: 13 additions & 0 deletions src/Exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
return exception;
}()),

// Deprecated
GetDescriptionError: (function(){
var exception = function(message) {
this.code = 4;
Expand Down Expand Up @@ -83,4 +84,16 @@ module.exports = {
exception.prototype = new Error();
return exception;
}()),

SessionDescriptionHandlerError: (function(){
var exception = function(method, error, message) {
this.code = 8;
this.name = 'SESSION_DESCRIPTION_HANDLER_ERROR';
this.method = method;
this.error = error;
this.message = message || 'Error with Session Description Handler';
};
exception.prototype = new Error();
return exception;
}()),
};
4 changes: 2 additions & 2 deletions src/Grammar/src/Grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ other_param = param: pname value: ( "=" pvalue )? {
else {
value = value[1];
}
options.data.uri_params[param.toLowerCase()] = value && value.toLowerCase();}
options.data.uri_params[param.toLowerCase()] = value;}

pname = $ paramchar +

Expand Down Expand Up @@ -813,7 +813,7 @@ via_ttl = "ttl"i EQUAL via_ttl_value: ttl {
via_maddr = "maddr"i EQUAL via_maddr: host {
options.data.maddr = via_maddr; }

via_received = "received"i EQUAL via_received: (IPv4address / IPv6address) {
via_received = "received"i EQUAL via_received: (IPv4address / IPv6address / IPv6reference) {
options.data.received = via_received; }

via_branch = "branch"i EQUAL via_branch: token {
Expand Down
21 changes: 15 additions & 6 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Session.prototype = {

promise.catch(function onFailure (e) {
var statusCode;
if (e instanceof SIP.Exceptions.GetDescriptionError) {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
statusCode = 500;
} else if (e instanceof SIP.Exceptions.RenegotiationError) {
self.emit('renegotiationError', e);
Expand All @@ -433,6 +433,8 @@ Session.prototype = {
}
request.reply(statusCode);
self.emit('reinviteFailed', self);
// TODO: This could be better
throw e;
})
.then(function(description) {
var extraHeaders = ['Contact: ' + self.contact];
Expand Down Expand Up @@ -565,6 +567,14 @@ Session.prototype = {
var self = this;

if (this.status === C.STATUS_TERMINATED) {
this.logger.error('Received reinvite response, but in STATUS_TERMINATED');
// TODO: Do we need to send a SIP response?
return;
}

if (!this.pendingReinvite) {
this.logger.error('Received reinvite response, but have no pending reinvite');
// TODO: Do we need to send a SIP response?
return;
}

Expand Down Expand Up @@ -1612,7 +1622,8 @@ InviteClientContext.prototype = Object.create({}, {
session.emit('progress', response);
})
.catch(function onFailure(e) {
if (e instanceof SIP.Exceptions.GetDescriptionError) {
// TODO: This is a bit wonky
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
earlyDialog.pracked.push(response.getHeader('rseq'));
if (session.status === C.STATUS_TERMINATED) {
return;
Expand Down Expand Up @@ -1700,12 +1711,10 @@ InviteClientContext.prototype = Object.create({}, {
session.accepted(response);
})
.catch(function onFailure(e) {
if (e instanceof SIP.Exceptions.GetDescriptionError) {
// TODO do something here
session.logger.warn("there was a problem");
} else {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
session.logger.warn('invalid description');
session.logger.warn(e);
// TODO: This message is inconsistent
session.acceptAndTerminate(response, 488, 'Invalid session description');
session.failed(response, SIP.C.causes.BAD_MEDIA_DESCRIPTION);
}
Expand Down
2 changes: 1 addition & 1 deletion src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ URI = function(scheme, user, host, port, parameters, headers) {
URI.prototype = {
setParam: function(key, value) {
if(key) {
this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null) ? null : value.toString().toLowerCase();
this.parameters[key.toLowerCase()] = (typeof value === 'undefined' || value === null) ? null : value.toString();
}
},

Expand Down
13 changes: 13 additions & 0 deletions src/Web/Modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ function stripPayload(sdp, payload) {
return lines.join('\r\n');
}

function stripMediaDescription(sdp, description) {
const descriptionRegExp = new RegExp("m=" + description + ".*$", "gm");
if (descriptionRegExp.test(sdp)) {
sdp = sdp.split(/^m=/gm).filter((section) => (section.substr(0, description.length) !== description)).join('m=');
}
return sdp;
}

Modifiers = {
stripTcpCandidates: function(description) {
description.sdp = description.sdp.replace(/^a=candidate:\d+ \d+ tcp .*?\r\n/img, "");
Expand All @@ -78,6 +86,11 @@ Modifiers = {
description.sdp = stripPayload(description.sdp, payload);
return SIP.Utils.Promise.resolve(description);
};
},

stripVideo: function(description) {
description.sdp = stripMediaDescription(description, "video");
return SIP.Utils.Promise.resolve(description);
}
};

Expand Down
113 changes: 78 additions & 35 deletions src/Web/SessionDescriptionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,34 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
.then(function() {
return SIP.Utils.reducePromises(modifiers, description);
})
.catch(function modifierError(e) {
self.logger.error("The modifiers did not resolve successfully");
self.logger.error(e);
throw e;
.catch((e) => {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("setDescription", e, "The modifiers did not resolve successfully");
this.logger.error(error.message);
self.emit('peerConnection-setRemoteDescriptionFailed', error);
throw error;
})
.then(function(modifiedDescription) {
self.emit('setDescription', modifiedDescription);
return self.peerConnection.setRemoteDescription(modifiedDescription);
})
.catch(function setRemoteDescriptionError(e) {
self.logger.error(e);
self.emit('peerConnection-setRemoteDescriptionFailed', e);
throw e;
.catch((e) => {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
// Check the original SDP for video, and ensure that we have want to do audio fallback
if ((/^m=video.+$/gm).test(sessionDescription) && !options.disableAudioFallback) {
// Do not try to audio fallback again
options.disableAudioFallback = true;
// Remove video first, then do the other modifiers
return this.setDescription(sessionDescription, options, [SIP.Web.Modifiers.stripVideo].concat(modifiers));
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("setDescription", e);
this.logger.error(error.error);
this.emit('peerConnection-setRemoteDescriptionFailed', error);
throw error;
})
.then(function setRemoteDescriptionSuccess() {
if (self.peerConnection.getReceivers) {
Expand Down Expand Up @@ -303,9 +318,13 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
methodName = self.hasOffer('remote') ? 'createAnswer' : 'createOffer';

return pc[methodName](RTCOfferOptions)
.catch(function methodError(e) {
self.emit('peerConnection-' + methodName + 'Failed', e);
throw e;
.catch((e) => {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("createOfferOrAnswer", e, 'peerConnection-' + methodName + 'Failed');
this.emit('peerConnection-' + methodName + 'Failed', error);
throw error;
})
.then(function(sdp) {
return SIP.Utils.reducePromises(modifiers, self.createRTCSessionDescriptionInit(sdp));
Expand All @@ -314,9 +333,13 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
self.resetIceGatheringComplete();
return pc.setLocalDescription(sdp);
})
.catch(function localDescError(e) {
self.emit('peerConnection-SetLocalDescriptionFailed', e);
throw e;
.catch((e) => {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("createOfferOrAnswer", e, 'peerConnection-SetLocalDescriptionFailed');
this.emit('peerConnection-SetLocalDescriptionFailed', error);
throw error;
})
.then(function onSetLocalDescriptionSuccess() {
return self.waitForIceGatheringComplete();
Expand All @@ -329,10 +352,13 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
self.setDirection(localDescription.sdp);
return localDescription;
})
.catch(function createOfferOrAnswerError (e) {
self.logger.error(e);
// TODO: Not sure if this is correct
throw new SIP.Exceptions.GetDescriptionError(e);
.catch((e) => {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("createOfferOrAnswer", e);
this.logger.error(error);
throw error;
});
}},

Expand Down Expand Up @@ -410,10 +436,14 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
};
}

this.peerConnection.onicecandidate = function(e) {
this.peerConnection.onicecandidate = function (e) {
self.emit('iceCandidate', e);
if (e.candidate) {
self.logger.log('ICE candidate received: '+ (e.candidate.candidate === null ? null : e.candidate.candidate.trim()));
self.logger.log('ICE candidate received: ' + (e.candidate.candidate === null ? null : e.candidate.candidate.trim()));
} else if (e.candidate === null) {
// indicates the end of candidate gathering
self.logger.log('ICE candidate gathering complete');
self.triggerIceGatheringComplete();
}
};

Expand Down Expand Up @@ -497,11 +527,16 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
resolve([]);
}
}.bind(this))
.catch(function acquireFailed(err) {
this.logger.error('unable to acquire streams');
this.logger.error(err);
return SIP.Utils.Promise.reject(err);
}.bind(this))
.catch((e) => {
// TODO: This propogates downwards
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("acquire", e, "unable to acquire streams");
this.logger.error(error.message);
this.logger.error(error.error);
throw error;
})
.then(function acquireSucceeded(streams) {
this.logger.log('acquired local media streams');
try {
Expand All @@ -516,11 +551,15 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
return SIP.Utils.Promise.reject(e);
}
}.bind(this))
.catch(function removeStreamsFailed(err) {
this.logger.error('error removing streams');
this.logger.error(err);
return SIP.Utils.Promise.reject(err);
}.bind(this))
.catch((e) => {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("acquire", e, "error removing streams");
this.logger.error(error.message);
this.logger.error(error.error);
throw error;
})
.then(function addStreams(streams) {
try {
streams = [].concat(streams);
Expand All @@ -539,11 +578,15 @@ SessionDescriptionHandler.prototype = Object.create(SIP.SessionDescriptionHandle
}
return SIP.Utils.Promise.resolve();
}.bind(this))
.catch(function addStreamsFailed(err) {
this.logger.error('error adding stream');
this.logger.error(err);
return SIP.Utils.Promise.reject(err);
}.bind(this));
.catch((e) => {
if (e instanceof SIP.Exceptions.SessionDescriptionHandlerError) {
throw e;
}
const error = new SIP.Exceptions.SessionDescriptionHandlerError("acquire", e, "error adding stream");
this.logger.error(error.message);
this.logger.error(error.error);
throw error;
});
}},

hasOffer: {writable: true, value: function hasOffer (where) {
Expand Down
Loading

0 comments on commit f1e8ea7

Please sign in to comment.