@@ -555,13 +555,13 @@ public class MQTTClient: MQTTConnectionDelegate, MQTTSubscriptionsHandlerDelegat
555
555
556
556
/// Adds an observer callback which will be called when the client has received an `MQTTMessage` for a specific topic.
557
557
/// - Parameters:
558
- /// - topic : The topic to receive messages for.
558
+ /// - topicFilter : The topic filter to receive messages for.
559
559
/// - callback: The observer callback to add which will be called with the received message.
560
560
/// - Returns: An `MQTTCancellable` which can be used to cancel the observer callback.
561
561
@discardableResult
562
- public func whenMessage( forTopic topic : String , _ callback: @escaping ( _ message: MQTTMessage ) -> Void ) -> MQTTCancellable {
562
+ public func whenMessage( forTopic topicFilter : String , _ callback: @escaping ( _ message: MQTTMessage ) -> Void ) -> MQTTCancellable {
563
563
return messageCallbacks. append { message in
564
- guard message. topic == topic else {
564
+ guard message. topic. matchesMqttTopicFilter ( topicFilter ) else {
565
565
return
566
566
}
567
567
callback ( message)
@@ -628,13 +628,13 @@ public class MQTTClient: MQTTConnectionDelegate, MQTTSubscriptionsHandlerDelegat
628
628
}
629
629
630
630
/// Returns a publisher for receiving MQTT messages to a specific topic.
631
- /// - Parameter topic : The topic to receive messages for.
631
+ /// - Parameter topicFilter : The topic filter to receive messages for.
632
632
///
633
633
/// This is only available on platforms where `Combine` is available.
634
634
@available ( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * )
635
- public func messagePublisher( forTopic topic : String ) -> AnyPublisher < MQTTMessage , Never > {
635
+ public func messagePublisher( forTopic topicFilter : String ) -> AnyPublisher < MQTTMessage , Never > {
636
636
return messageSubject
637
- . filter { $0. topic == topic }
637
+ . filter { $0. topic. matchesMqttTopicFilter ( topicFilter ) }
638
638
. eraseToAnyPublisher ( )
639
639
}
640
640
0 commit comments