Commit Graph

3 Commits (3b1be2d01cd3ea3baed77ba348a462d3e0e6f10c)

Author SHA1 Message Date
Dustin 4820d0f6cd Begin MQTT control implementation
The pieces are starting to come together.  To control the browser via
MQTT messages, the `MqttClient` dispatches messages via a
`MessageHandler`, which parses them and makes the appropriate Marionette
requests.  The `MessageHandler` trait defines callback methods for each
MQTT control operation, which currently is just `navigate`.  The
operation type is determined by the MQTT topic on which the message was
received.

Several new types are necessary to make this work.  The `MessageHandler`
trait and implementation are of course the core, reacting to incoming
MQTT messages.  In order for the handler to be able to *send* MQTT
messages, though, it needs a reference to the Paho MQTT client.  The
`MqttPublisher` provides a convenient wrapper around the client, with
specific methods for each type of message to send.  Finally, there's the
`MessageType` enumeration, which works in conjunction with the
`TopicMatcher` to match topic names to message types using topic filter
patterns.
2022-12-30 19:06:27 -06:00
Dustin ee8ed0c644 Add basic MQTT client functionality
Naturally, we need a way to configure the MQTT connection parameters
(host, port, username, etc.).  For that, we'll use a TOML configuration
file, which is read at startup and deserialized into a structure owned
by the Session.

The Session object now has a `run` method, which establishes the MQTT
connection and then repeatedly waits for messages from the broker.  It
will continuously attempt to connect to the broker until it succeeds.
This way, if the broker is unavailable when the application starts, it
will eventually connect when it becomes available.  Once the initial
connection is established, the client will automatically reconnect if it
gets disconnected later.

Since the `run` method loops forever and never returns, we need to use a
separate Tokio task to manage it.  We keep the task handle so we can
cancel the task when the application shuts down.
2022-12-30 13:49:01 -06:00
Dustin f3815e2b12 Initial commit 2022-12-30 09:10:05 -06:00