Skip to content

Commit 63d4365

Browse files
committed
Add example for parsing directions
1 parent f764601 commit 63d4365

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use clap::Parser;
2+
use futures::StreamExt;
3+
use lighthouse_client::{protocol::Authentication, Lighthouse, Result, TokioWebSocket, LIGHTHOUSE_URL};
4+
use tracing::info;
5+
6+
async fn run(lh: Lighthouse<TokioWebSocket>) -> Result<()> {
7+
info!("Connected to the Lighthouse server");
8+
9+
// Stream input events
10+
let mut stream = lh.stream_input().await?;
11+
while let Some(msg) = stream.next().await {
12+
let event = msg?.payload;
13+
if let Some(direction) = event.direction() {
14+
info!("Input direction: {:?}", direction);
15+
}
16+
}
17+
18+
Ok(())
19+
}
20+
21+
#[derive(Parser)]
22+
struct Args {
23+
/// The username.
24+
#[arg(short, long, env = "LIGHTHOUSE_USER")]
25+
username: String,
26+
/// The API token.
27+
#[arg(short, long, env = "LIGHTHOUSE_TOKEN")]
28+
token: String,
29+
/// The server URL.
30+
#[arg(long, env = "LIGHTHOUSE_URL", default_value = LIGHTHOUSE_URL)]
31+
url: String,
32+
}
33+
34+
#[tokio::main(flavor = "current_thread")]
35+
async fn main() -> Result<()> {
36+
tracing_subscriber::fmt().init();
37+
_ = dotenvy::dotenv();
38+
39+
let args = Args::parse();
40+
let auth = Authentication::new(&args.username, &args.token);
41+
let lh = Lighthouse::connect_with_tokio_to(&args.url, auth).await?;
42+
43+
run(lh).await
44+
}

0 commit comments

Comments
 (0)