Skip to content

Commit

Permalink
fixup! feat(binding_mqtt): support MQTT URI scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Dec 31, 2023
1 parent 7594eac commit d5a6b06
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/src/binding_mqtt/mqtt_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ extension MqttUriExtension on Uri {

throw StateError('MQTT URI scheme $scheme is not supported.');
}

String get _mqttTopic {
final path = Uri.decodeComponent(this.path);

if (path.isEmpty) {
return path;
}

return path.substring(1);
}
}

/// Additional methods for making MQTT [Form]s easier to work with.
Expand Down Expand Up @@ -99,28 +109,21 @@ extension MqttFormExtension on Form {
return topic;
}

final path = Uri.decodeComponent(href.path);

if (path.isEmpty) {
return path;
}

return path.substring(1);
return href._mqttTopic;
}

/// Gets the MQTT topic for subscribing from this [Form].
///
/// If present, this getter uses the dedicated vocabulary term `filter`.
/// Otherwise, the URI query from the `href` field is being used as a
/// fallback.
/// Otherwise, the URI path from the `href` field is being used as a fallback.
String get topicFilter {
final topic = _obtainVocabularyTerm<String>('filter');

if (topic != null) {
return topic;
}

return Uri.decodeComponent(href.query.replaceAll('&', '/'));
return href._mqttTopic;
}

/// Gets the MQTT `retain` value from this [Form] if present.
Expand Down

0 comments on commit d5a6b06

Please sign in to comment.