Skip to content
Permalink
Browse files

Add hack_via_ws option to force "WS" in Via header when the server ha…

…s wss:// scheme.
  • Loading branch information
ibc committed Sep 23, 2014
1 parent 77e40ce commit 2274a7d937253287a00a38db59f59824eed41e06
Showing with 58 additions and 17 deletions.
  1. +44 −11 src/Transactions.js
  2. +14 −6 src/UA.js
@@ -34,6 +34,7 @@ var
*/
var NonInviteClientTransaction = function(request_sender, request, transport) {
var via,
via_transport,
events = ['stateChanged'];

this.type = C.NON_INVITE_CLIENT;
@@ -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);
@@ -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;
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -483,7 +516,7 @@ var InviteServerTransaction = function(request, ua) {
ua.newTransaction(this);

this.resendProvisionalTimer = null;

request.reply(100);

this.initEvents(events);
@@ -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);
};
@@ -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);
}
@@ -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;
@@ -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) {
@@ -806,6 +806,7 @@ UA.prototype.loadConfig = function(configuration) {

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

@@ -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;
@@ -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) {
@@ -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",
@@ -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;

0 comments on commit 2274a7d

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