39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
|
use matrix_sdk::{config::SyncSettings, crypto::types::events::room, ruma::RoomId};
|
||
|
use tokio::sync::mpsc;
|
||
|
|
||
|
mod config;
|
||
|
mod matrix;
|
||
|
mod meshtastic;
|
||
|
|
||
|
#[tokio::main]
|
||
|
async fn main() -> anyhow::Result<()> {
|
||
|
let config = config::read_config().await;
|
||
|
|
||
|
let (matrix_tx, matrix_rx) = mpsc::channel(32);
|
||
|
|
||
|
let room_id = RoomId::parse(&config.matrix.room).expect("invalid room id");
|
||
|
println!("matrix room: {:?}", room_id);
|
||
|
|
||
|
let matrix_client = matrix::build(config.matrix)
|
||
|
.await
|
||
|
.expect("error logging into matrix");
|
||
|
|
||
|
matrix_client.sync_once(SyncSettings::default()).await?;
|
||
|
|
||
|
let meshtastic_client = meshtastic::build(config.meshtastic)
|
||
|
.await
|
||
|
.expect("error connecting to meshtastic");
|
||
|
|
||
|
tokio::spawn(async {
|
||
|
meshtastic_client.receive(matrix_tx).await.expect("error receiving message from meshtastic");
|
||
|
});
|
||
|
|
||
|
tokio::spawn(matrix::sender(matrix_client.clone(), matrix_rx, room_id));
|
||
|
|
||
|
// Syncing is important to synchronize the client state with the server.
|
||
|
// This method will never return unless there is an error.
|
||
|
matrix_client.sync(SyncSettings::default()).await?;
|
||
|
|
||
|
Ok(())
|
||
|
}
|