Skip to content
Permalink
Browse files

Add 'extraHeaders' parameter to UA.register() and UA.unregister() met…

…hods
  • Loading branch information
jmillan committed Jan 20, 2013
1 parent 293fdcd commit 47cdb66ca097142517afc7b73d9c8d1bf2764283
Showing with 20 additions and 17 deletions.
  1. +16 −13 src/Registrator.js
  2. +4 −4 src/UA.js
@@ -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);

@@ -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: *");
@@ -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);
@@ -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();
}
@@ -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();
}

0 comments on commit 47cdb66

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