diff --git a/NchanSubscriber.js b/NchanSubscriber.js index 63a2975..62a4578 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -76,6 +76,14 @@ var ughbind = (Function.prototype.bind ); var sharedSubscriberTable={}; +var conn = 0; // counter to save total connection made by one type of connector. +var maxConn = 3; // Switch to different protocol if it is reached to conn reached to maxConn. +var priorityIndex = 0; // Counter to switch to another protocol type. +var connError = false; // This helps to differentiate the errors and timeout of connection. +var disconnectError = false; +var time = 5000; // Hold time after iterating through every connection type. +var timeFactor = 1.3; // Increase hold time by timefactor. +var maxWaitTime = 120000; // Put cap on hold time upto 2 mins. "use strict"; function NchanSubscriber(url, opt) { @@ -98,6 +106,18 @@ function NchanSubscriber(url, opt) { } this.desiredTransport = opt.subscriber; + if(opt.maxTry) { + maxConn = opt.maxTry; + } + if(opt.holdTime) { + time = opt.holdTime; + } + if(opt.timeFactor) { + timeFactor = opt.timeFactor; + } + if(opt.maxWaitTime) { + maxWaitTime = opt.maxWaitTime; + } if(opt.shared) { if (!("localStorage" in global)) { throw "localStorage unavailable for use in shared NchanSubscriber"; @@ -420,9 +440,12 @@ function NchanSubscriber(url, opt) { Emitter(NchanSubscriber.prototype); NchanSubscriber.prototype.initializeTransport = function(possibleTransports) { - if(possibleTransports) { - this.desiredTransport = possibleTransports; - } + // This is commented out because the original client is not sending any data. + // We are reinitializing our client to unable the websocket fallback. + // this.desiredTransport contains all the mentioned type of connection protocols. + // if(possibleTransports) { + // this.desiredTransport = possibleTransports; + // } if(this.shared && this.shared.role == "slave") { this.transport = new this.SubscriberClass["__slave"](ughbind(this.emit, this)); //try it } @@ -438,12 +461,9 @@ NchanSubscriber.prototype.initializeTransport = function(possibleTransports) { }, this); var i; - if(this.desiredTransport) { - for(i=0; i