Skip to content

Commit

Permalink
Fix will retained messages
Browse files Browse the repository at this point in the history
  • Loading branch information
davidepianca98 committed Mar 16, 2020
1 parent 2e69544 commit 2db247e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/commonMain/kotlin/mqtt/broker/Broker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Broker(
properties.responseTopic = will.responseTopic
properties.correlationData = will.correlationData
properties.userProperty += will.userProperty
publish(session.clientId, will.retain, will.topic, will.qos, false, properties, will.payload)
publish(session.clientId, will.retain, will.topic, will.qos, properties, will.payload)
// The will must be removed after sending
session.will = null
}
Expand Down Expand Up @@ -160,7 +160,8 @@ class Broker(
}
}

fun publish(
private fun publish(
publisherClientId: String,
retain: Boolean,
topicName: String,
qos: Qos,
Expand All @@ -185,10 +186,20 @@ class Broker(
)
setRetained(topicName, packet, "")
}
publish("", retain, topicName, qos, false, properties, payload)
publish(publisherClientId, retain, topicName, qos, false, properties, payload)
return true
}

fun publish(
retain: Boolean,
topicName: String,
qos: Qos,
properties: MQTTProperties,
payload: UByteArray?
): Boolean {
return publish("", retain, topicName, qos, properties, payload)
}

internal fun setRetained(topicName: String, message: MQTTPublish, clientId: String) {
if (retainedAvailable) {
if (message.payload?.isNotEmpty() == true)
Expand Down

0 comments on commit 2db247e

Please sign in to comment.