Skip to content

Commit 1ab3423

Browse files
committed
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.
1 parent 4e70a25 commit 1ab3423

5 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/Registrator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ JsSIP.Registrator.prototype = {
5757
'cseq': (this.cseq += 1)
5858
}, [
5959
'Contact: '+ this.contact + ';expires=' + this.expires,
60-
'Allow: '+ JsSIP.c.ALLOWED_METHODS
60+
'Allow: '+ JsSIP.utils.getAllowedMethods(this.ua)
6161
]);
6262

6363
request_sender = new JsSIP.RequestSender(this, this.ua);

src/Session.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ JsSIP.Session.prototype.connect = function(target, options) {
134134
}
135135

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

140140
request = new JsSIP.OutgoingRequest(JsSIP.c.INVITE, target, this.ua, requestParams, extraHeaders);

src/UA.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ JsSIP.UA.prototype.receiveRequest = function(request) {
361361
*/
362362
if(method === JsSIP.c.OPTIONS) {
363363
request.reply(200, JsSIP.c.REASON_200, [
364-
'Allow: '+ JsSIP.c.ALLOWED_METHODS,
364+
'Allow: '+ JsSIP.utils.getAllowedMethods(this),
365365
'Accept: '+ JsSIP.c.ACCEPTED_BODY_TYPES
366366
]);
367367
}

src/constants.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,11 @@ JsSIP.c = {
198198
ALLOWED_METHODS: 'INVITE, ACK, CANCEL, BYE, OPTIONS, MESSAGE, SUBSCRIBE',
199199
SUPPORTED: 'path, outbound, gruu',
200200
ACCEPTED_BODY_TYPES: 'application/sdp',
201-
TAG_LENGTH: 10
201+
TAG_LENGTH: 10,
202+
203+
// User Agent EVENT METHODS
204+
UA_EVENT_METHODS: {
205+
'newSession': 'INVITE',
206+
'newMessage': 'MESSAGE'
207+
}
202208
};

src/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ JsSIP.utils = {
129129
}
130130
},
131131

132+
getAllowedMethods: function(ua) {
133+
var event,
134+
allowed = JsSIP.c.ALLOWED_METHODS.split(', ');
135+
136+
for (event in JsSIP.c.UA_EVENT_METHODS) {
137+
if (!ua.checkEvent(event) || ua.listeners(event).length === 0) {
138+
allowed.splice(allowed.indexOf(JsSIP.c.UA_EVENT_METHODS[event]), 1);
139+
}
140+
}
141+
142+
return allowed.join(', ');
143+
},
144+
132145
// MD5 (Message-Digest Algorithm) http://www.webtoolkit.info
133146
MD5: function(string) {
134147
function RotateLeft(lValue, iShiftBits) {

0 commit comments

Comments
 (0)