spoke/mqtt_js
Types
pub opaque type TransportOptions
A handle for update subscriptions
pub opaque type UpdateSubscription
Values
pub fn connect(
client: Client,
clean_session: Bool,
will: option.Option(mqtt.PublishData),
) -> Nil
Starts connecting to the MQTT server.
The connection state will be published as an update.
If a connection is already established or being established,
this will be a no-op.
Note that switching between clean_session
values
while already connecting is currently not well handled.
pub fn disconnect(
client: Client,
) -> promise.Promise(Result(Nil, mqtt.OperationError))
Disconnects from the MQTT server. The connection state change will also be published as an update. If a connection is not established or being established, this will be a no-op. Returns the serialized session state to be potentially restored later.
pub fn pending_publishes(
client: Client,
) -> promise.Promise(Result(Int, mqtt.OperationError))
Returns the number of QoS > 0 publishes that haven’t yet been completely published.
Also see wait_for_publishes_to_finish
.
pub fn publish(client: Client, data: mqtt.PublishData) -> Nil
Publishes a new message, which will be sent to the sever. If not connected, Qos 0 messages will be dropped, and higher QoS level messages will be sent once connected.
pub fn register_update_callback(
client: Client,
callback: fn(mqtt.Update) -> Nil,
) -> UpdateSubscription
Registers a callback to be executed on every client update.
pub fn start_session(
options: mqtt.ConnectOptions(TransportOptions),
) -> Client
Starts a new MQTT session with the given options. Does not automatically connect to the server.
pub fn subscribe(
client: Client,
requests: List(mqtt.SubscribeRequest),
) -> promise.Promise(
Result(List(mqtt.Subscription), mqtt.OperationError),
)
Subscribes to the given topics. The returned promise will resolve when we get a response from the server, returning the result of the operation.
pub fn subscribe_to_updates(
client: Client,
) -> #(channel.Channel(mqtt.Update), UpdateSubscription)
Returns a channel that publishes client updates.
pub fn unsubscribe(
client: Client,
topics: List(String),
) -> promise.Promise(Result(Nil, mqtt.OperationError))
Unsubscribes from the given topics. The returned promise will resolve when we get a response from the server, returning the result of the operation.
pub fn unsubscribe_from_updates(
client: Client,
subscription: UpdateSubscription,
) -> Nil
Stops publishing client updates associated to the subscription.
pub fn using_websocket(url: String) -> TransportOptions
Creates transport options for communicating with a MQTT server over a WebSocket.
pub fn wait_for_publishes_to_finish(
client: Client,
timeout: Int,
) -> promise.Promise(Result(Nil, mqtt.OperationError))
Wait for all pending QoS > 0 publishes to complete. Returns an error if the operation times out, or if the client is killed while waiting.