Skip to content

Commit f19842b

Browse files
committed
Fix #60, #61. Add optional parameters to ua.contact.toString(). Thanks @ibc
- anonymous (boolean) - outbound (boolean)
1 parent 8f5acb1 commit f19842b

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/Registrator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ JsSIP.Registrator = function(ua, transport) {
3636

3737
// Contact header
3838
if(reg_id) {
39-
this.contact = '<' + this.ua.contact.uri + '>';
39+
this.contact = this.ua.contact.toString();
4040
this.contact += ';reg-id='+ reg_id;
4141
this.contact += ';+sip.instance="<urn:uuid:'+ this.ua.configuration.instance_id+'>"';
4242
} else {

src/Session.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ JsSIP.Session.prototype.init_incoming = function(request) {
5959
this.from_tag = request.from_tag;
6060
this.id = request.call_id + this.from_tag;
6161
this.request = request;
62-
this.contact = '<'+ this.ua.contact +'>';
62+
this.contact = this.ua.contact.toString();
6363

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

127127
requestParams = {from_tag: this.from_tag};
128128

129-
if (options.anonymous) {
130-
this.contact = '<'+ this.ua.contact.toString(true) +';ob>';
129+
this.contact = this.ua.contact.toString({
130+
anonymous: this.anonymous,
131+
outbound: true
132+
});
131133

134+
if (this.anonymous) {
132135
requestParams.from_display_name = 'Anonymous';
133136
requestParams.from_uri = 'sip:anonymous@anonymous.invalid';
134137

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

141142
extraHeaders.push('Contact: '+ this.contact);

src/UA.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,26 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {
715715
pub_gruu: null,
716716
temp_gruu: null,
717717
uri: new JsSIP.URI('sip', JsSIP.Utils.createRandomToken(8), settings.via_host, null, {transport: 'ws'}),
718-
toString: function(anonymous){
719-
var contact;
718+
toString: function(options){
719+
options = options || {};
720+
721+
var
722+
anonymous = options.anonymous || null,
723+
outbound = options.outbound || null,
724+
contact = '<';
720725

721726
if (anonymous) {
722-
contact = this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
727+
contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
723728
} else {
724-
contact = this.pub_gruu || this.uri.toString();
729+
contact += this.pub_gruu || this.uri.toString();
730+
}
731+
732+
if (outbound) {
733+
contact += ';ob';
725734
}
735+
736+
contact += '>';
737+
726738
return contact;
727739
}
728740
};

0 commit comments

Comments
 (0)