Skip to content
Permalink
Browse files

Intelligent 'Allow' header field value.

Do not set a method in the 'Allow' header field if its corresponding event is not defined or has zero listeners.
  • Loading branch information
jmillan committed Nov 20, 2012
1 parent 4e70a25 commit 1ab34233c989bdca65fc97371b57bc26dfa40756
Showing with 23 additions and 4 deletions.
  1. +1 −1 src/Registrator.js
  2. +1 −1 src/Session.js
  3. +1 −1 src/UA.js
  4. +7 −1 src/constants.js
  5. +13 −0 src/utils.js
@@ -57,7 +57,7 @@ JsSIP.Registrator.prototype = {
'cseq': (this.cseq += 1)
}, [
'Contact: '+ this.contact + ';expires=' + this.expires,
'Allow: '+ JsSIP.c.ALLOWED_METHODS
'Allow: '+ JsSIP.utils.getAllowedMethods(this.ua)
]);

request_sender = new JsSIP.RequestSender(this, this.ua);
@@ -134,7 +134,7 @@ JsSIP.Session.prototype.connect = function(target, options) {
}

extraHeaders.push('Contact: <'+ this.contact + ';ob>');
extraHeaders.push('Allow: '+ JsSIP.c.ALLOWED_METHODS);
extraHeaders.push('Allow: '+ JsSIP.utils.getAllowedMethods(this.ua));
extraHeaders.push('Content-Type: application/sdp');

request = new JsSIP.OutgoingRequest(JsSIP.c.INVITE, target, this.ua, requestParams, extraHeaders);
@@ -361,7 +361,7 @@ JsSIP.UA.prototype.receiveRequest = function(request) {
*/
if(method === JsSIP.c.OPTIONS) {
request.reply(200, JsSIP.c.REASON_200, [
'Allow: '+ JsSIP.c.ALLOWED_METHODS,
'Allow: '+ JsSIP.utils.getAllowedMethods(this),
'Accept: '+ JsSIP.c.ACCEPTED_BODY_TYPES
]);
}
@@ -198,5 +198,11 @@ JsSIP.c = {
ALLOWED_METHODS: 'INVITE, ACK, CANCEL, BYE, OPTIONS, MESSAGE, SUBSCRIBE',
SUPPORTED: 'path, outbound, gruu',
ACCEPTED_BODY_TYPES: 'application/sdp',
TAG_LENGTH: 10
TAG_LENGTH: 10,

// User Agent EVENT METHODS
UA_EVENT_METHODS: {
'newSession': 'INVITE',
'newMessage': 'MESSAGE'
}
};
@@ -129,6 +129,19 @@ JsSIP.utils = {
}
},

getAllowedMethods: function(ua) {
var event,
allowed = JsSIP.c.ALLOWED_METHODS.split(', ');

for (event in JsSIP.c.UA_EVENT_METHODS) {
if (!ua.checkEvent(event) || ua.listeners(event).length === 0) {
allowed.splice(allowed.indexOf(JsSIP.c.UA_EVENT_METHODS[event]), 1);
}
}

return allowed.join(', ');
},

// MD5 (Message-Digest Algorithm) http://www.webtoolkit.info
MD5: function(string) {
function RotateLeft(lValue, iShiftBits) {

0 comments on commit 1ab3423

Please sign in to comment.
You can’t perform that action at this time.