Skip to content
Permalink
Browse files

Enhance self contact handling

  • Loading branch information
jmillan committed Feb 17, 2013
1 parent 5e7d815 commit 8f5acb1c9af177b9794070e7b5a24cdc57582926
Showing with 23 additions and 24 deletions.
  1. +9 −15 src/Session.js
  2. +14 −9 src/UA.js
@@ -43,13 +43,6 @@ JsSIP.Session = function(ua) {
this.data = {};

this.initEvents(events);

// Self contact value. _gruu_ or not.
if (ua.contact.pub_gruu) {
this.contact = ua.contact.pub_gruu;
} else {
this.contact = ua.contact.uri;
}
};
JsSIP.Session.prototype = new JsSIP.EventEmitter();

@@ -62,10 +55,11 @@ JsSIP.Session.prototype = new JsSIP.EventEmitter();
*/
JsSIP.Session.prototype.init_incoming = function(request) {
// Session parameter initialization
this.from_tag = request.from_tag;
this.status = JsSIP.C.SESSION_INVITE_RECEIVED;
this.from_tag = request.from_tag;
this.id = request.call_id + this.from_tag;
this.request = request;
this.contact = '<'+ this.ua.contact +'>';

//Save the session into the ua sessions collection.
this.ua.sessions[this.id] = this;
@@ -133,18 +127,18 @@ JsSIP.Session.prototype.connect = function(target, views, options) {
requestParams = {from_tag: this.from_tag};

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

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 + ';ob>');
extraHeaders.push('Contact: '+ this.contact);
extraHeaders.push('Allow: '+ JsSIP.Utils.getAllowedMethods(this.ua));
extraHeaders.push('Content-Type: application/sdp');

@@ -424,7 +418,7 @@ JsSIP.Session.prototype.receiveInitialRequest = function(request) {
return;
}

extraHeaders.push('Contact: <' + session.contact + '>');
extraHeaders.push('Contact: '+ session.contact);
request.reply(status_code, reason_phrase, extraHeaders,
sdp,
// onSuccess
@@ -478,7 +472,7 @@ JsSIP.Session.prototype.receiveInitialRequest = function(request) {
if (this.status !== JsSIP.C.SESSION_TERMINATED) {
this.progress('local');

request.reply(180, null, ['Contact: <' + this.contact + '>']);
request.reply(180, null, ['Contact: '+ this.contact]);

This comment has been minimized.

Copy link
@ibc

ibc Feb 17, 2013

Member

I suggest always using name-addr syntax in Contact header to avoid possible issues (as the recent one). IMH ua.contact.toString() should ALWAYS return a name-addr formatted Contact value, and should also allow passing optional params (i.e. for setting "ob" param).

This comment has been minimized.

Copy link
@jmillan

jmillan Feb 17, 2013

Author Member

Right, instead for adding the '<' '>' manually, lets automate it in contact.toString() method. #60

}
} else {
request.reply(415);
@@ -655,7 +649,7 @@ JsSIP.Session.prototype.invite2xxRetransmission = function(retransmissions, requ
if((retransmissions * JsSIP.Timers.T1) <= JsSIP.Timers.T2) {
retransmissions += 1;

request.reply(200, null, ['Contact: <' + this.contact + '>'], body);
request.reply(200, null, ['Contact: '+ this.contact], body);

this.invite2xxTimer = window.setTimeout(
function() {
@@ -32,7 +32,7 @@ JsSIP.UA = function(configuration) {

this.sessions = {};
this.transport = null;
this.contact = {};
this.contact = null;
this.status = JsSIP.C.UA_STATUS_INIT;
this.error = null;
this.transactions = {
@@ -597,7 +597,7 @@ JsSIP.UA.prototype.recoverTransport = function(ua) {
*/
JsSIP.UA.prototype.loadConfig = function(configuration) {
// Settings and default values
var parameter, value, checked_value, contact, contact_uri, hostport_params,
var parameter, value, checked_value, hostport_params,
settings = {
/* Host address
* Value to be set in Via sent_by and host part of Contact FQDN
@@ -711,16 +711,21 @@ JsSIP.UA.prototype.loadConfig = function(configuration) {
settings.via_host = JsSIP.Utils.getRandomTestNetIP();
}

contact_uri = new JsSIP.URI('sip', JsSIP.Utils.createRandomToken(8), settings.via_host, null, {transport: 'ws'});
this.contact = {
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;

contact = {
uri: {
value: contact_uri,
writable: false,
configurable: false
if (anonymous) {
contact = this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
} else {
contact = this.pub_gruu || this.uri.toString();
}
return contact;
}
};
Object.defineProperties(this.contact, contact);

// Fill the value of the configuration_skeleton
console.log(JsSIP.C.LOG_UA + 'configuration parameters after validation:');

0 comments on commit 8f5acb1

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