From ad591aa7b795e3c235b4405c79162eada3443bee Mon Sep 17 00:00:00 2001 From: Rishi Date: Tue, 30 May 2017 15:06:04 +0530 Subject: [PATCH 1/7] Websocket Fallback --- NchanSubscriber.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/NchanSubscriber.js b/NchanSubscriber.js index 63a2975..924ec7e 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -459,7 +459,8 @@ NchanSubscriber.prototype.initializeTransport = function(possibleTransports) { }; var storageEventListener; - +var conn = 0 +var maxConn = 3 NchanSubscriber.prototype.start = function() { if(this.running) throw "Can't start NchanSubscriber, it's already started."; @@ -532,16 +533,26 @@ NchanSubscriber.prototype.start = function() { } } else { - if(!this.transport) { - this.initializeTransport(); + if (conn Date: Tue, 30 May 2017 15:39:03 +0530 Subject: [PATCH 2/7] Code refactor --- NchanSubscriber.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/NchanSubscriber.js b/NchanSubscriber.js index 924ec7e..47e026c 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -420,9 +420,9 @@ function NchanSubscriber(url, opt) { Emitter(NchanSubscriber.prototype); NchanSubscriber.prototype.initializeTransport = function(possibleTransports) { - if(possibleTransports) { - this.desiredTransport = possibleTransports; - } + // 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 +438,9 @@ NchanSubscriber.prototype.initializeTransport = function(possibleTransports) { }, this); var i; - if(this.desiredTransport) { - for(i=0; i Date: Wed, 7 Jun 2017 12:51:21 +0530 Subject: [PATCH 3/7] Change throw message --- NchanSubscriber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NchanSubscriber.js b/NchanSubscriber.js index 47e026c..3f0e661 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -547,7 +547,7 @@ NchanSubscriber.prototype.start = function() { if (priorityIndex Date: Wed, 21 Jun 2017 19:08:16 +0530 Subject: [PATCH 4/7] Handle timeout errors --- NchanSubscriber.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/NchanSubscriber.js b/NchanSubscriber.js index 3f0e661..a3f99d5 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -459,6 +459,8 @@ var storageEventListener; var conn = 0 var maxConn = 3 var priorityIndex = 0 +var connError = false +var disconnectError = false NchanSubscriber.prototype.start = function() { if(this.running) @@ -532,6 +534,11 @@ NchanSubscriber.prototype.start = function() { } } else { + if (!connError && disconnectError) { + conn = 0; + } + connError = false; + disconnectError = false; if (conn Date: Mon, 26 Jun 2017 20:09:22 +0530 Subject: [PATCH 5/7] Set timeout --- NchanSubscriber.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/NchanSubscriber.js b/NchanSubscriber.js index a3f99d5..b004df5 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -456,11 +456,13 @@ NchanSubscriber.prototype.initializeTransport = function(possibleTransports) { }; var storageEventListener; -var conn = 0 -var maxConn = 3 -var priorityIndex = 0 -var connError = false -var disconnectError = false +var conn = 0; +var maxConn = 3; +var priorityIndex = 0; +var connError = false; +var disconnectError = false; +var time = 5000; +var timeFactor = 1.3; NchanSubscriber.prototype.start = function() { if(this.running) @@ -553,12 +555,14 @@ NchanSubscriber.prototype.start = function() { this.transport = null if (priorityIndex Date: Tue, 27 Jun 2017 15:15:54 +0530 Subject: [PATCH 6/7] Add more configs --- NchanSubscriber.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/NchanSubscriber.js b/NchanSubscriber.js index b004df5..e6f014a 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -76,6 +76,14 @@ var ughbind = (Function.prototype.bind ); var sharedSubscriberTable={}; +var conn = 0; +var maxConn = 3; +var priorityIndex = 0; +var connError = false; +var disconnectError = false; +var time = 5000; +var timeFactor = 1.3; +var maxWaitTime = 120000; "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"; @@ -456,13 +476,6 @@ NchanSubscriber.prototype.initializeTransport = function(possibleTransports) { }; var storageEventListener; -var conn = 0; -var maxConn = 3; -var priorityIndex = 0; -var connError = false; -var disconnectError = false; -var time = 5000; -var timeFactor = 1.3; NchanSubscriber.prototype.start = function() { if(this.running) @@ -561,7 +574,7 @@ NchanSubscriber.prototype.start = function() { }else{ priorityIndex = 0; setTimeout(this.start.bind(this), time); - time = Math.min(time * timeFactor, 2 * 60 * 1000); + time = Math.min(time * timeFactor, maxWaitTime); } } } From 44a5192c7dbf5b220613351d3b3d1f1b19ab56e6 Mon Sep 17 00:00:00 2001 From: rishiloyola Date: Tue, 27 Jun 2017 17:24:07 +0530 Subject: [PATCH 7/7] Add comment --- NchanSubscriber.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/NchanSubscriber.js b/NchanSubscriber.js index e6f014a..62a4578 100644 --- a/NchanSubscriber.js +++ b/NchanSubscriber.js @@ -76,14 +76,14 @@ var ughbind = (Function.prototype.bind ); var sharedSubscriberTable={}; -var conn = 0; -var maxConn = 3; -var priorityIndex = 0; -var connError = false; +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; -var timeFactor = 1.3; -var maxWaitTime = 120000; +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) { @@ -440,6 +440,9 @@ function NchanSubscriber(url, opt) { Emitter(NchanSubscriber.prototype); NchanSubscriber.prototype.initializeTransport = function(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; // } @@ -549,6 +552,10 @@ NchanSubscriber.prototype.start = function() { } } else { + // First it will select one protocol and try to establish connection upto maxConn type. + // If it fails alll the time then it will switch to next protocol. + // If all the configured protocols fail to establish connection then client will go on hold state. + // It will wait upto holdtime and then it will again try to make connection using configured protocols. if (!connError && disconnectError) { conn = 0; }