File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ var Connection = require('./connection')
12
12
var defaultConnectOptions = {
13
13
keepalive : 10 ,
14
14
protocolId : 'MQIsdp' ,
15
- protocolVersion : 3
15
+ protocolVersion : 3 ,
16
+ reconnectPeriod : 1000
16
17
} ;
17
18
18
19
var defaultId = function ( ) {
@@ -159,7 +160,7 @@ function MqttClient(stream, options) {
159
160
if ( ! that . reconnectTimer ) {
160
161
that . reconnectTimer = setInterval ( function ( ) {
161
162
that . _reconnect ( ) ;
162
- } , 1000 ) ;
163
+ } , that . options . reconnectPeriod ) ;
163
164
}
164
165
} ) ;
165
166
Original file line number Diff line number Diff line change @@ -667,5 +667,29 @@ describe('MqttClient', function () {
667
667
done ( ) ;
668
668
} ) ;
669
669
} ) ;
670
+
671
+ it ( 'should allow specification of a reconnect period' , function ( done ) {
672
+ this . timeout ( 2200 ) ;
673
+ var client = createClient ( port , { reconnectPeriod : 2000 } )
674
+ , reconnect = false ;
675
+
676
+ var start = process . hrtime ( )
677
+ , end ;
678
+
679
+ client . on ( 'connect' , function ( ) {
680
+ if ( ! reconnect ) {
681
+ client . stream . end ( ) ;
682
+ reconnect = true ;
683
+ } else {
684
+ end = process . hrtime ( start ) ;
685
+ if ( end [ 0 ] === 2 ) {
686
+ // Connected in about 2 seconds, that's good enough
687
+ done ( ) ;
688
+ } else {
689
+ done ( new Error ( 'Strange reconnect period' ) ) ;
690
+ }
691
+ }
692
+ } ) ;
693
+ } ) ;
670
694
} ) ;
671
695
} ) ;
You can’t perform that action at this time.
0 commit comments