Skip to content

Commit

Permalink
Add hack_via_ws option to force "WS" in Via header when the server ha…
Browse files Browse the repository at this point in the history
…s wss:// scheme.
  • Loading branch information
ibc committed Sep 23, 2014
1 parent 77e40ce commit 2274a7d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
55 changes: 44 additions & 11 deletions src/Transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var
*/
var NonInviteClientTransaction = function(request_sender, request, transport) {
var via,
via_transport,
events = ['stateChanged'];

this.type = C.NON_INVITE_CLIENT;
Expand All @@ -44,7 +45,17 @@ var NonInviteClientTransaction = function(request_sender, request, transport) {

this.logger = request_sender.ua.getLogger('jssip.transaction.nict', this.id);

via = 'SIP/2.0/' + (request_sender.ua.configuration.hack_via_tcp ? 'TCP' : transport.server.scheme);
if (request_sender.ua.configuration.hack_via_tcp) {
via_transport = 'TCP';
}
else if (request_sender.ua.configuration.hack_via_ws) {
via_transport = 'WS';
}
else {
via_transport = transport.server.scheme;
}

via = 'SIP/2.0/' + via_transport;
via += ' ' + request_sender.ua.configuration.via_host + ';branch=' + this.id;

this.request.setHeader('via', via);
Expand Down Expand Up @@ -138,6 +149,7 @@ NonInviteClientTransaction.prototype.receiveResponse = function(response) {
var InviteClientTransaction = function(request_sender, request, transport) {
var via,
tr = this,
via_transport,
events = ['stateChanged'];

this.type = C.INVITE_CLIENT;
Expand All @@ -148,7 +160,17 @@ var InviteClientTransaction = function(request_sender, request, transport) {

this.logger = request_sender.ua.getLogger('jssip.transaction.ict', this.id);

via = 'SIP/2.0/' + (request_sender.ua.configuration.hack_via_tcp ? 'TCP' : transport.server.scheme);
if (request_sender.ua.configuration.hack_via_tcp) {
via_transport = 'TCP';
}
else if (request_sender.ua.configuration.hack_via_ws) {
via_transport = 'WS';
}
else {
via_transport = transport.server.scheme;
}

via = 'SIP/2.0/' + via_transport;
via += ' ' + request_sender.ua.configuration.via_host + ';branch=' + this.id;

this.request.setHeader('via', via);
Expand Down Expand Up @@ -329,7 +351,8 @@ InviteClientTransaction.prototype.receiveResponse = function(response) {
* @param {JsSIP.Transport} transport
*/
var AckClientTransaction = function(request_sender, request, transport) {
var via;
var via,
via_transport;

this.transport = transport;
this.id = 'z9hG4bK' + Math.floor(Math.random() * 10000000);
Expand All @@ -338,7 +361,17 @@ var AckClientTransaction = function(request_sender, request, transport) {

this.logger = request_sender.ua.getLogger('jssip.transaction.nict', this.id);

via = 'SIP/2.0/' + (request_sender.ua.configuration.hack_via_tcp ? 'TCP' : transport.server.scheme);
if (request_sender.ua.configuration.hack_via_tcp) {
via_transport = 'TCP';
}
else if (request_sender.ua.configuration.hack_via_ws) {
via_transport = 'WS';
}
else {
via_transport = transport.server.scheme;
}

via = 'SIP/2.0/' + via_transport;
via += ' ' + request_sender.ua.configuration.via_host + ';branch=' + this.id;

this.request.setHeader('via', via);
Expand Down Expand Up @@ -398,7 +431,7 @@ NonInviteServerTransaction.prototype.timer_J = function() {
NonInviteServerTransaction.prototype.onTransportError = function() {
if (!this.transportError) {
this.transportError = true;

this.logger.log('transport error occurred, deleting non-INVITE server transaction ' + this.id);

window.clearTimeout(this.J);
Expand Down Expand Up @@ -483,7 +516,7 @@ var InviteServerTransaction = function(request, ua) {
ua.newTransaction(this);

this.resendProvisionalTimer = null;

request.reply(100);

this.initEvents(events);
Expand All @@ -501,7 +534,7 @@ InviteServerTransaction.prototype.timer_H = function() {
if(this.state === C.STATUS_COMPLETED) {
this.logger.warn('transactions', 'ACK for INVITE server transaction was never received, call will be terminated');
}

this.stateChanged(C.STATUS_TERMINATED);
this.ua.destroyTransaction(this);
};
Expand Down Expand Up @@ -531,11 +564,11 @@ InviteServerTransaction.prototype.onTransportError = function() {
window.clearInterval(this.resendProvisionalTimer);
this.resendProvisionalTimer = null;
}

window.clearTimeout(this.L);
window.clearTimeout(this.H);
window.clearTimeout(this.I);

this.stateChanged(C.STATUS_TERMINATED);
this.ua.destroyTransaction(this);
}
Expand Down Expand Up @@ -576,7 +609,7 @@ InviteServerTransaction.prototype.receiveResponse = function(status_code, respon
this.L = window.setTimeout(function() {
tr.timer_L();
}, JsSIP.Timers.TIMER_L);

if (this.resendProvisionalTimer !== null) {
window.clearInterval(this.resendProvisionalTimer);
this.resendProvisionalTimer = null;
Expand All @@ -601,7 +634,7 @@ InviteServerTransaction.prototype.receiveResponse = function(status_code, respon
window.clearInterval(this.resendProvisionalTimer);
this.resendProvisionalTimer = null;
}

if(!this.transport.send(response)) {
this.onTransportError();
if (onFailure) {
Expand Down
20 changes: 14 additions & 6 deletions src/UA.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ UA.prototype.loadConfig = function(configuration) {

// Hacks
hack_via_tcp: false,
hack_via_ws: false,
hack_ip_in_contact: false
};

Expand Down Expand Up @@ -835,9 +836,9 @@ UA.prototype.loadConfig = function(configuration) {
* or it's a number with NaN value, then apply its default value.
*/
if (JsSIP.Utils.isEmpty(value)) {
continue;
continue;
}

checked_value = UA.configuration_check.optional[parameter](value);
if (checked_value !== undefined) {
settings[parameter] = checked_value;
Expand Down Expand Up @@ -895,7 +896,7 @@ UA.prototype.loadConfig = function(configuration) {
if (settings.hack_ip_in_contact) {
settings.via_host = JsSIP.Utils.getRandomTestNetIP();
}

// Set empty Stun Server Set if explicitly passed an empty Array
value = configuration.stun_servers;
if (value instanceof Array && value.length === 0) {
Expand Down Expand Up @@ -983,12 +984,13 @@ UA.configuration_skeleton = (function() {
"connection_recovery_max_interval",
"connection_recovery_min_interval",
"display_name",
"hack_via_tcp", // false.
"hack_via_tcp", // false
"hack_via_ws", // false
"hack_ip_in_contact", //false
"instance_id",
"no_answer_timeout", // 30 seconds.
"no_answer_timeout", // 30 seconds
"password",
"register_expires", // 600 seconds.
"register_expires", // 600 seconds
"registrar_server",
"stun_servers",
"trace_sip",
Expand Down Expand Up @@ -1147,6 +1149,12 @@ UA.configuration_check = {
}
},

hack_via_ws: function(hack_via_ws) {
if (typeof hack_via_ws === 'boolean') {
return hack_via_ws;
}
},

hack_ip_in_contact: function(hack_ip_in_contact) {
if (typeof hack_ip_in_contact === 'boolean') {
return hack_ip_in_contact;
Expand Down

0 comments on commit 2274a7d

Please sign in to comment.