Skip to content

Commit

Permalink
Merge pull request #2 from thieupham-wf/add_sockjs_client_parameters
Browse files Browse the repository at this point in the history
DT-951 DT-1012 SockJS Client - Add "roundTrips" and "timeout" parameters
  • Loading branch information
katiesanderson-wf committed Mar 6, 2015
2 parents 4d8a64e + 2c61685 commit 6b281d4
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@ class Client extends Object with event.Emitter {
num rtt;
num rto;
List<String> protocolsWhitelist = [];
num roundTrips;
num timeout;

var _ir;

var _transport = null;
Timer _transportTref;

Client(String url, {
this.devel: false, this.debug: false, this.protocolsWhitelist,
this.info, this.rtt: 0, this.server}) {
Client(String url, {this.devel: false,
this.debug: false,
this.protocolsWhitelist,
this.info,
this.rtt: 0,
this.server,
this.roundTrips,
this.timeout}) {

_baseUrl = utils.amendUrl(url);

Expand Down Expand Up @@ -204,9 +211,17 @@ class Client extends Object with event.Emitter {
!PROTOCOLS[protocol].enabled) {
_debug('Skipping transport: $protocol');
} else {
var roundTrips = PROTOCOLS[protocol].roundTrips;
var to = rto * roundTrips;
if (to == 0) to = 5000;
// if roundTrips is passed in, we will use it
// instead of the defaulted value for the protocol.
var roundTrips = (this.roundTrips != null && this.roundTrips > 0)
? this.roundTrips
: PROTOCOLS[protocol].roundTrips;

var to = this.timeout;
if (to == null || to < 1) {
to = rto * roundTrips;
if (to == 0) to = 5000;
}
_transportTref = new Timer(new Duration(milliseconds:to), () {
if (readyState == CONNECTING) {
// I can't understand how it is possible to run
Expand All @@ -218,7 +233,7 @@ class Client extends Object with event.Emitter {

var connid = utils.random_string(8);
var trans_url = "$_baseUrl/$server/$connid";
_debug('Opening transport: $protocol url:$trans_url RTO:$rto');
_debug('Opening transport: $protocol url:$trans_url RTO:$rto roundTrips:$roundTrips timeout:$to');
_transport = PROTOCOLS[protocol].create(this, trans_url, _baseUrl);
return true;
}
Expand Down

0 comments on commit 6b281d4

Please sign in to comment.