|
@@ -7,12 +7,16 @@ var WSSource = function(url, options) {
|
7
|
7
|
this.callbacks = {connect: [], data: []};
|
8
|
8
|
this.destination = null;
|
9
|
9
|
|
10
|
|
- this.reconnectInterval = options.reconnectInterval || 5;
|
|
10
|
+ this.reconnectInterval = options.reconnectInterval !== undefined
|
|
11
|
+ ? options.reconnectInterval
|
|
12
|
+ : 5;
|
11
|
13
|
this.shouldAttemptReconnect = !!this.reconnectInterval;
|
12
|
14
|
|
13
|
15
|
this.completed = false;
|
14
|
16
|
this.established = false;
|
15
|
17
|
this.progress = 0;
|
|
18
|
+
|
|
19
|
+ this.reconnectTimeoutId = 0;
|
16
|
20
|
};
|
17
|
21
|
|
18
|
22
|
WSSource.prototype.connect = function(destination) {
|
|
@@ -48,7 +52,8 @@ WSSource.prototype.onOpen = function() {
|
48
|
52
|
|
49
|
53
|
WSSource.prototype.onClose = function() {
|
50
|
54
|
if (this.shouldAttemptReconnect) {
|
51
|
|
- setTimeout(function(){
|
|
55
|
+ clearTimeout(this.reconnectTimeoutId);
|
|
56
|
+ this.reconnectTimeoutId = setTimeout(function(){
|
52
|
57
|
this.start();
|
53
|
58
|
}.bind(this), this.reconnectInterval*1000);
|
54
|
59
|
}
|