2025-06-01 16:04:00 -05:00
|
|
|
|
//! navka-client – forward keyboard/mouse HID reports to navka-server
|
|
|
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
|
|
|
2025-06-01 14:46:12 -05:00
|
|
|
|
use anyhow::Result;
|
2025-06-01 16:04:00 -05:00
|
|
|
|
use navka_common::navka::{hid_report::*, relay_client::RelayClient, HidReport};
|
|
|
|
|
|
use tokio::{sync::mpsc, time::sleep};
|
2025-06-01 14:46:12 -05:00
|
|
|
|
use tokio_stream::wrappers::ReceiverStream;
|
2025-06-01 16:04:00 -05:00
|
|
|
|
use tonic::{transport::Channel, Request};
|
2025-06-01 13:31:22 -05:00
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
2025-06-01 14:46:12 -05:00
|
|
|
|
async fn main() -> Result<()> {
|
2025-06-01 16:04:00 -05:00
|
|
|
|
// Connect to navka-server (adjust the address if server not local)
|
|
|
|
|
|
let channel = Channel::from_static("http://127.0.0.1:50051")
|
|
|
|
|
|
.connect()
|
|
|
|
|
|
.await?;
|
2025-06-01 14:46:12 -05:00
|
|
|
|
|
2025-06-01 16:04:00 -05:00
|
|
|
|
// mpsc channel -> ReceiverStream -> gRPC bidirectional stream
|
|
|
|
|
|
let (tx, rx) = mpsc::channel::<HidReport>(32);
|
|
|
|
|
|
let outbound = ReceiverStream::new(rx);
|
2025-06-01 14:46:12 -05:00
|
|
|
|
|
2025-06-01 16:04:00 -05:00
|
|
|
|
// Kick off the RPC – note: in tonic 0.11 the request object is built
|
|
|
|
|
|
// by wrapping the outbound stream in `Request::new(...)`.
|
|
|
|
|
|
let mut inbound = RelayClient::new(channel)
|
|
|
|
|
|
.stream(Request::new(outbound))
|
|
|
|
|
|
.await?
|
|
|
|
|
|
.into_inner();
|
2025-06-01 14:46:12 -05:00
|
|
|
|
|
2025-06-01 16:04:00 -05:00
|
|
|
|
// Example task: press and release the 'a' key once.
|
2025-06-01 14:46:12 -05:00
|
|
|
|
tokio::spawn(async move {
|
2025-06-01 16:04:00 -05:00
|
|
|
|
// 8-byte boot-keyboard report: [mods, reserved, key1..6]
|
|
|
|
|
|
let press_a = HidReport {
|
|
|
|
|
|
data: vec![0x00, 0x00, 0x04, 0, 0, 0, 0, 0],
|
|
|
|
|
|
};
|
|
|
|
|
|
let release = HidReport { data: vec![0; 8] };
|
2025-06-01 13:31:22 -05:00
|
|
|
|
|
2025-06-01 16:04:00 -05:00
|
|
|
|
tx.send(press_a).await.ok();
|
|
|
|
|
|
sleep(std::time::Duration::from_millis(100)).await;
|
|
|
|
|
|
tx.send(release).await.ok();
|
2025-06-01 14:46:12 -05:00
|
|
|
|
});
|
2025-06-01 13:31:22 -05:00
|
|
|
|
|
2025-06-01 16:04:00 -05:00
|
|
|
|
// Print whatever the server echoes back.
|
|
|
|
|
|
while let Some(report) = inbound.message().await? {
|
|
|
|
|
|
println!("🔄 received: {:?}", report.data);
|
2025-06-01 13:31:22 -05:00
|
|
|
|
}
|
2025-06-01 16:04:00 -05:00
|
|
|
|
|
2025-06-01 14:46:12 -05:00
|
|
|
|
Ok(())
|
2025-06-01 13:31:22 -05:00
|
|
|
|
}
|