Skip to content
Sebastian Clausen edited this page Oct 16, 2017 · 5 revisions

API

MqttService(options?: MqttServiceOptions, client?: MQTT.Client)

  • options is the client connection options. Defaults:
    • hostname:localhost
    • port:443
    • protocol:ws
    • path:mqtt
  • client is a already created MQTT.js client instance

MqttService#observe(filter: string)

With this method, you can observe messages for a mqtt topic. The observable will only emit messages matching the filter. The first one subscribing to the resulting observable executes a mqtt subscribe. The last one unsubscribing this filter executes a mqtt unsubscribe.

  • filter the mqtt filter to subscribe

MqttService#publish(topic: string, message: any, [options: PublishOptions])

This method publishes a message for a topic with optional options. The returned observable will complete, if publishing was successfull and will throw an error, if the publication fails

  • topic the topic to publish the message to
  • message any message to publish
  • options the options to publish with
    • qos the qos level
    • retain set to true if message should be retained

MqttService#filterMatchesTopic(filter: string, topic: string)

This static method shall be used to determine whether an MQTT topic matches a given filter. The matching rules are specified in the MQTT standard documenation and in the library test suite.

  • filter A filter may contain wildcards like '#' and '+'.
  • topic A topic may not contain wildcards.
Clone this wiki locally