File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -212,9 +212,10 @@ version 1.3 and 1.4 works fine without those.
212
212
213
213
#### Event ` 'connect' `
214
214
215
- ` function() {} `
215
+ ` function(connack ) {} `
216
216
217
- Emitted on successful (re)connection (i.e. connack rc=0).
217
+ Emitted on successful (re)connection (i.e. connack rc=0).
218
+ * ` connack ` received connack packet
218
219
219
220
#### Event ` 'reconnect' `
220
221
Original file line number Diff line number Diff line change @@ -667,7 +667,7 @@ MqttClient.prototype._handleConnack = function (packet) {
667
667
clearTimeout ( this . connackTimer ) ;
668
668
669
669
if ( 0 === rc ) {
670
- this . emit ( 'connect' , null , { sessionPresent : packet . sessionPresent } ) ;
670
+ this . emit ( 'connect' , packet ) ;
671
671
} else if ( 0 < rc ) {
672
672
this . emit ( 'error' ,
673
673
new Error ( 'Connection refused: ' + errors [ rc ] ) ) ;
Original file line number Diff line number Diff line change @@ -199,6 +199,26 @@ module.exports = function (server, config) {
199
199
client . once ( 'error' , done ) ;
200
200
} ) ;
201
201
202
+ it ( 'should provide connack packet with connect event' , function ( done ) {
203
+ server . once ( 'client' , function ( serverClient ) {
204
+ serverClient . connack ( { returnCode : 0 , sessionPresent : true } ) ;
205
+
206
+ server . once ( 'client' , function ( serverClient ) {
207
+ serverClient . connack ( { returnCode : 0 , sessionPresent : false } ) ;
208
+ } ) ;
209
+ } ) ;
210
+
211
+ var client = connect ( ) ;
212
+ client . once ( 'connect' , function ( packet ) {
213
+ should ( packet . sessionPresent ) . be . equal ( true ) ;
214
+ client . once ( 'connect' , function ( packet ) {
215
+ should ( packet . sessionPresent ) . be . equal ( false ) ;
216
+ client . end ( ) ;
217
+ done ( ) ;
218
+ } ) ;
219
+ } ) ;
220
+ } ) ;
221
+
202
222
it ( 'should mark the client as connected' , function ( done ) {
203
223
var client = connect ( ) ;
204
224
client . once ( 'connect' , function ( ) {
You can’t perform that action at this time.
0 commit comments