Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Merge d71129b into 37497cf
Browse files Browse the repository at this point in the history
  • Loading branch information
jingwang committed Apr 21, 2016
2 parents 37497cf + d71129b commit f68168d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ db

profile-*
.__*
.idea
11 changes: 11 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Client.prototype._setup = function() {
client.on("pingreq", function() {
that.logger.debug("pingreq");
that.setUpTimer();
that.handlePingreq();
that.connection.pingresp();
});

Expand Down Expand Up @@ -370,6 +371,16 @@ Client.prototype.handleConnect = function(packet, completeConnection) {
});
};

/**
* Handle a pingreq
*
* @api private
*/
Client.prototype.handlePingreq = function() {
var that = this;
that.server.emit("pingreq", that);
};

/**
* Handle a puback packet.
*
Expand Down
21 changes: 21 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ describe("mosca.Server", function() {
});
});

it("should emit \"pingreq\" of the corresponding client at a pingreq", function(done) {

var instance = this.instance;
buildClient(instance, done, function(client) {

var clientId = 'client';
var opts = buildOpts();
opts.clientId = clientId;

client.connect(opts);

instance.on('pingreq', function(c){
expect(c.id).to.equal(clientId);
client.disconnect();
});

client.pingreq();

});
});

it("should pass mosca options to backend when publishing", function(done) {
var instance = this.instance;
buildClient(instance, done, function(client) {
Expand Down

0 comments on commit f68168d

Please sign in to comment.