Skip to content

Commit

Permalink
Add 'extraHeaders' parameter to UA.register() and UA.unregister() met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
jmillan committed Jan 20, 2013
1 parent 293fdcd commit 47cdb66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
29 changes: 16 additions & 13 deletions src/Registrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ JsSIP.Registrator = function(ua, transport) {
};

JsSIP.Registrator.prototype = {
register: function() {
register: function(extraHeaders) {
var request_sender, cause,
self = this;

extraHeaders = extraHeaders || [];
extraHeaders.push('Contact: '+ this.contact + ';expires=' + this.expires);
extraHeaders.push('Allow: '+ JsSIP.utils.getAllowedMethods(this.ua));

this.request = new JsSIP.OutgoingRequest(JsSIP.c.REGISTER, this.registrar, this.ua, {
'to_uri': this.from_uri,
'call_id': this.call_id,
'cseq': (this.cseq += 1)
}, [
'Contact: '+ this.contact + ';expires=' + this.expires,
'Allow: '+ JsSIP.utils.getAllowedMethods(this.ua)
]);
}, extraHeaders);

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

Expand Down Expand Up @@ -176,7 +177,7 @@ JsSIP.Registrator.prototype = {
/**
* @param {Boolean} [all=false]
*/
unregister: function(all) {
unregister: function(all, extraHeaders) {
/* Parameters:
*
* - all: If true, then perform a "unregister all" action ("Contact: *");
Expand All @@ -186,29 +187,31 @@ JsSIP.Registrator.prototype = {
return;
}

extraHeaders = extraHeaders || [];

this.registered = false;
this.ua.emit('unregistered', this.ua);

// Clear the registration timer.
window.clearTimeout(this.registrationTimer);

if(all) {
extraHeaders.push('Contact: *');
extraHeaders.push('Expires: 0');

this.request = new JsSIP.OutgoingRequest(JsSIP.c.REGISTER, this.registrar, this.ua, {
'to_uri': this.from_uri,
'call_id': this.call_id,
'cseq': (this.cseq += 1)
}, [
'Contact: *',
'Expires : 0'
]);
}, extraHeaders);
} else {
extraHeaders.push('Contact: '+ this.contact + ';expires=0');

this.request = new JsSIP.OutgoingRequest(JsSIP.c.REGISTER, this.registrar, this.ua, {
'to_uri': this.from_uri,
'call_id': this.call_id,
'cseq': (this.cseq += 1)
}, [
'Contact: '+ this.contact + ';expires=0'
]);
}, extraHeaders);
}

var request_sender = new JsSIP.RequestSender(this, this.ua);
Expand Down
8 changes: 4 additions & 4 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ JsSIP.UA.prototype = new JsSIP.EventEmitter();
*
* @throws {JsSIP.exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters).
*/
JsSIP.UA.prototype.register = function() {
JsSIP.UA.prototype.register = function(extraHeaders) {
if(this.status === JsSIP.c.UA_STATUS_READY) {
this.configuration.register = true;
this.registrator.register();
this.registrator.register(extraHeaders);
} else {
throw new JsSIP.exceptions.NotReadyError();
}
Expand All @@ -83,10 +83,10 @@ JsSIP.UA.prototype.register = function() {
*
* @throws {JsSIP.exceptions.NotReadyError} If JsSIP.UA is not ready (see JsSIP.UA.status, JsSIP.UA.error parameters).
*/
JsSIP.UA.prototype.unregister = function(all) {
JsSIP.UA.prototype.unregister = function(all, extraHeaders) {
if(this.status === JsSIP.c.UA_STATUS_READY) {
this.configuration.register = false;
this.registrator.unregister(all);
this.registrator.unregister(all, extraHeaders);
} else {
throw new JsSIP.exceptions.NotReadyError();
}
Expand Down

0 comments on commit 47cdb66

Please sign in to comment.