From 6a5cfa58e3de867c948e58fe74973bd514b7adb1 Mon Sep 17 00:00:00 2001 From: Behrad Date: Sat, 16 Apr 2016 11:17:22 +0430 Subject: [PATCH] move publishSubscriptions check out of callback --- lib/server.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/server.js b/lib/server.js index fcae99e..8ea4b36 100755 --- a/lib/server.js +++ b/lib/server.js @@ -262,8 +262,8 @@ function Server(opts, callback) { ); }); - that.on("subscribed", function(topic, client) { - if(that.modernOpts.publishSubscriptions) { + if(that.modernOpts.publishSubscriptions) { + that.on("subscribed", function(topic, client) { that.publish({ topic: "$SYS/" + that.id + "/new/subscribes", payload: JSON.stringify({ @@ -271,11 +271,9 @@ function Server(opts, callback) { topic: topic }) }); - } - }); + }); - that.on("unsubscribed", function(topic, client) { - if(that.modernOpts.publishSubscriptions) { + that.on("unsubscribed", function(topic, client) { that.publish({ topic: "$SYS/" + that.id + "/new/unsubscribes", payload: JSON.stringify({ @@ -283,8 +281,8 @@ function Server(opts, callback) { topic: topic }) }); - } - }); + }); + } that.on("clientDisconnected", function(client) { if(that.modernOpts.publishClientDisconnect) {