diff --git a/src/Registrator.js b/src/Registrator.js index 423228d7e..a3d613cef 100644 --- a/src/Registrator.js +++ b/src/Registrator.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); diff --git a/src/Session.js b/src/Session.js index 2cbc35f83..1786653d2 100644 --- a/src/Session.js +++ b/src/Session.js @@ -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); diff --git a/src/UA.js b/src/UA.js index f1f63488e..296bf88e8 100644 --- a/src/UA.js +++ b/src/UA.js @@ -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 ]); } diff --git a/src/constants.js b/src/constants.js index 577b5d220..0d5bc35dd 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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' + } }; diff --git a/src/utils.js b/src/utils.js index f01127e75..bd22211b2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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) {