File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,7 @@ The arguments are:
174
174
the ` connect ` event. Typically a ` net.Socket ` .
175
175
* ` options ` is the client connection options (see: the [ connect packet] ( https://github.com/mcollina/mqtt-packet#connect ) ). Defaults:
176
176
* ` keepalive ` : ` 10 ` seconds, set to ` 0 ` to disable
177
+ * ` reschedulePings ` : reschedule ping messages after sending packets (default ` true ` )
177
178
* ` clientId ` : ` 'mqttjs_' + Math.random().toString(16).substr(2, 8) `
178
179
* ` protocolId ` : ` 'MQTT' `
179
180
* ` protocolVersion ` : ` 4 `
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ var events = require('events'),
16
16
} ,
17
17
defaultConnectOptions = {
18
18
keepalive : 10 ,
19
+ reschedulePings : true ,
19
20
protocolId : 'MQTT' ,
20
21
protocolVersion : 4 ,
21
22
reconnectPeriod : 1000 ,
@@ -642,7 +643,7 @@ MqttClient.prototype._setupPingTimer = function () {
642
643
* @api private
643
644
*/
644
645
MqttClient . prototype . _shiftPingInterval = function ( ) {
645
- if ( this . pingTimer && this . options . keepalive ) {
646
+ if ( this . pingTimer && this . options . keepalive && this . options . reschedulePings ) {
646
647
this . pingTimer . reschedule ( this . options . keepalive * 1000 ) ;
647
648
}
648
649
} ;
Original file line number Diff line number Diff line change @@ -605,6 +605,38 @@ module.exports = function (server, config) {
605
605
done ( ) ;
606
606
} ) ;
607
607
} ) ;
608
+ it ( 'should not checkPing if publishing at a higher rate than keepalive' , function ( done ) {
609
+ var intervalMs = 3000 ,
610
+ client = connect ( { keepalive : intervalMs / 1000 } ) ;
611
+
612
+ client . _checkPing = sinon . spy ( ) ;
613
+
614
+ client . once ( 'connect' , function ( ) {
615
+ client . publish ( 'foo' , 'bar' ) ;
616
+ clock . tick ( intervalMs - 1 ) ;
617
+ client . publish ( 'foo' , 'bar' ) ;
618
+ clock . tick ( 2 ) ;
619
+ client . _checkPing . callCount . should . equal ( 0 ) ;
620
+ client . end ( ) ;
621
+ done ( ) ;
622
+ } ) ;
623
+ } ) ;
624
+ it ( 'should checkPing if publishing at a higher rate than keepalive and reschedulePings===false' , function ( done ) {
625
+ var intervalMs = 3000 ,
626
+ client = connect ( { keepalive : intervalMs / 1000 , reschedulePings :false } ) ;
627
+
628
+ client . _checkPing = sinon . spy ( ) ;
629
+
630
+ client . once ( 'connect' , function ( ) {
631
+ client . publish ( 'foo' , 'bar' ) ;
632
+ clock . tick ( intervalMs - 1 ) ;
633
+ client . publish ( 'foo' , 'bar' ) ;
634
+ clock . tick ( 2 ) ;
635
+ client . _checkPing . callCount . should . equal ( 1 ) ;
636
+ client . end ( ) ;
637
+ done ( ) ;
638
+ } ) ;
639
+ } ) ;
608
640
} ) ;
609
641
610
642
describe ( 'pinging' , function ( ) {
You can’t perform that action at this time.
0 commit comments