use rumqttc::{
AsyncClient,
QoS,
};
use tracing::trace;
use crate::error::MessengerError;
use crate::gateway::lightspeed::{
Topic,
build_bootstrap_frames,
};
use crate::state::State;
pub(crate) async fn publish_lightspeed_bootstrap(
client: &AsyncClient,
state: &State,
online: bool,
) -> Result<(), MessengerError> {
let frames = build_bootstrap_frames(state, online)?;
for frame in frames {
trace!(
topic = frame.topic.as_str(),
request_id = frame.request_id,
payload = String::from_utf8_lossy(&frame.payload)
.chars()
.take(512)
.collect::<String>(),
"publishing lightspeed bootstrap payload"
);
client
.publish(frame.topic.as_str(), QoS::AtLeastOnce, false, frame.payload)
.await?;
if frame.topic == Topic::LsResp {
trace!("published lightspeed control frame");
}
}
Ok(())
}