Skip to content

Commit

Permalink
Fix #60, #61. Add optional parameters to ua.contact.toString(). Thanks
Browse files Browse the repository at this point in the history
…@ibc

- anonymous (boolean)
- outbound (boolean)
  • Loading branch information
jmillan committed Feb 17, 2013
1 parent 8f5acb1 commit f19842b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Registrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ JsSIP.Registrator = function(ua, transport) {

// Contact header
if(reg_id) {
this.contact = '<' + this.ua.contact.uri + '>';
this.contact = this.ua.contact.toString();
this.contact += ';reg-id='+ reg_id;
this.contact += ';+sip.instance="<urn:uuid:'+ this.ua.configuration.instance_id+'>"';
} else {
Expand Down
11 changes: 6 additions & 5 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ JsSIP.Session.prototype.init_incoming = function(request) {
this.from_tag = request.from_tag;
this.id = request.call_id + this.from_tag;
this.request = request;
this.contact = '<'+ this.ua.contact +'>';
this.contact = this.ua.contact.toString();

//Save the session into the ua sessions collection.
this.ua.sessions[this.id] = this;
Expand Down Expand Up @@ -126,16 +126,17 @@ JsSIP.Session.prototype.connect = function(target, views, options) {

requestParams = {from_tag: this.from_tag};

if (options.anonymous) {
this.contact = '<'+ this.ua.contact.toString(true) +';ob>';
this.contact = this.ua.contact.toString({
anonymous: this.anonymous,
outbound: true
});

if (this.anonymous) {
requestParams.from_display_name = 'Anonymous';
requestParams.from_uri = 'sip:anonymous@anonymous.invalid';

extraHeaders.push('P-Preferred-Identity: '+ this.ua.configuration.uri.toString());
extraHeaders.push('Privacy: id');
} else {
this.contact = '<'+ this.ua.contact +';ob>';
}

extraHeaders.push('Contact: '+ this.contact);
Expand Down
20 changes: 16 additions & 4 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,26 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {
pub_gruu: null,
temp_gruu: null,
uri: new JsSIP.URI('sip', JsSIP.Utils.createRandomToken(8), settings.via_host, null, {transport: 'ws'}),
toString: function(anonymous){
var contact;
toString: function(options){
options = options || {};

var
anonymous = options.anonymous || null,
outbound = options.outbound || null,
contact = '<';

if (anonymous) {
contact = this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
} else {
contact = this.pub_gruu || this.uri.toString();
contact += this.pub_gruu || this.uri.toString();
}

if (outbound) {
contact += ';ob';
}

contact += '>';

return contact;
}
};
Expand Down

2 comments on commit f19842b

@ibc
Copy link
Member

@ibc ibc commented on f19842b Feb 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍰

@jmillan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;-)

Please sign in to comment.