@@ -64,6 +64,16 @@ Transport.prototype = {
64
64
console . log ( LOG_PREFIX + 'closing WebSocket ' + this . server . ws_uri ) ;
65
65
this . ws . close ( ) ;
66
66
}
67
+
68
+ if ( this . reconnectTimer !== null ) {
69
+ window . clearTimeout ( this . reconnectTimer ) ;
70
+ this . reconnectTimer = null ;
71
+ this . ua . emit ( 'disconnected' , this . ua , {
72
+ transport : this ,
73
+ code : this . lastTransportError . code ,
74
+ reason : this . lastTransportError . reason
75
+ } ) ;
76
+ }
67
77
} ,
68
78
69
79
/**
@@ -119,7 +129,12 @@ Transport.prototype = {
119
129
120
130
console . log ( LOG_PREFIX + 'WebSocket ' + this . server . ws_uri + ' connected' ) ;
121
131
// Clear reconnectTimer since we are not disconnected
122
- window . clearTimeout ( this . reconnectTimer ) ;
132
+ if ( this . reconnectTimer !== null ) {
133
+ window . clearTimeout ( this . reconnectTimer ) ;
134
+ this . reconnectTimer = null ;
135
+ }
136
+ // Reset reconnection_attempts
137
+ this . reconnection_attempts = 0 ;
123
138
// Disable closed
124
139
this . closed = false ;
125
140
// Trigger onTransportConnected callback
@@ -146,8 +161,6 @@ Transport.prototype = {
146
161
this . ua . onTransportClosed ( this ) ;
147
162
// Check whether the user requested to close.
148
163
if ( ! this . closed ) {
149
- // Reset reconnection_attempts
150
- this . reconnection_attempts = 0 ;
151
164
this . reConnect ( ) ;
152
165
} else {
153
166
this . ua . emit ( 'disconnected' , this . ua , {
@@ -261,7 +274,9 @@ Transport.prototype = {
261
274
console . log ( LOG_PREFIX + 'trying to reconnect to WebSocket ' + this . server . ws_uri + ' (reconnection attempt ' + this . reconnection_attempts + ')' ) ;
262
275
263
276
this . reconnectTimer = window . setTimeout ( function ( ) {
264
- transport . connect ( ) ; } , this . ua . configuration . ws_server_reconnection_timeout * 1000 ) ;
277
+ transport . connect ( ) ;
278
+ transport . reconnectTimer = null ;
279
+ } , this . ua . configuration . ws_server_reconnection_timeout * 1000 ) ;
265
280
}
266
281
}
267
282
} ;
0 commit comments