Skip to content

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
gnought committed Aug 11, 2019
1 parent ad5197d commit d57e20d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/handlers/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function handleConnect (client, packet, done) {
if (packet.protocolVersion === 3 && clientId.length > 23) {
returnCode = 2
}
// console.log(returnCode)
if (returnCode > 0) {
var error = new Error(errorMessages[returnCode])
error.errorCode = returnCode
Expand Down Expand Up @@ -137,18 +136,18 @@ function setKeepAlive (arg, done) {
}

function fetchSubs (arg, done) {
var client = this.client
if (!this.packet.clean) {
this.client.broker.persistence.subscriptionsByClient({
id: this.client.id,
return client.broker.persistence.subscriptionsByClient({
id: client.id,
done: done,
arg: arg
}, gotSubs)
} else {
arg.sessionPresent = false // [MQTT-3.2.2-1]
this.client.broker.persistence.cleanSubscriptions(
this.client,
done)
}
arg.sessionPresent = false // [MQTT-3.2.2-1]
client.broker.persistence.cleanSubscriptions(
client,
done)
}

function gotSubs (err, subs, client) {
Expand All @@ -163,22 +162,22 @@ function restoreSubs (arg, done) {
if (arg.subs) {
handleSubscribe(this.client, { subscriptions: arg.subs, restore: true }, done)
arg.sessionPresent = !!arg.subs // cast to boolean, [MQTT-3.2.2-2]
} else {
arg.sessionPresent = false // [MQTT-3.2.2-1], [MQTT-3.2.2-3]
done()
return
}
arg.sessionPresent = false // [MQTT-3.2.2-1], [MQTT-3.2.2-3]
done()
}

function storeWill (arg, done) {
this.client.will = this.client._will
if (this.client.will) {
this.client.broker.persistence.putWill(
this.client,
this.client.will,
var client = this.client
client.will = client._will
if (client.will) {
return client.broker.persistence.putWill(
client,
client.will,
done)
} else {
done()
}
done()
}

function registerClient (arg, done) {
Expand Down Expand Up @@ -213,7 +212,6 @@ function emptyQueue (arg, done) {

function emptyQueueFilter (err, client, packet) {
var next = packet.writeCallback
var persistence = client.broker.persistence

if (err) {
client.emit('error', err)
Expand All @@ -226,6 +224,8 @@ function emptyQueueFilter (err, client, packet) {
authorized = client.broker.authorizeForward(client, packet)
}

var persistence = client.broker.persistence

if (client.clean || !authorized) {
persistence.outgoingClearMessageId(client, packet, next)
} else {
Expand Down

0 comments on commit d57e20d

Please sign in to comment.