use haply::{
device_model::{ ProfileConfig, SessionConfigure },
http::InverseHttpClient,
HaplyDevice,
};
use std::time::Duration;
use tokio::time::sleep;
const USE_HTTP: bool = false;
const HTTP_BASE: &str = "http://localhost:10001";
const WS_URL: &str = "ws://localhost:10001/";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let mut device = HaplyDevice::new(HTTP_BASE, WS_URL).await?;
let http = InverseHttpClient::new(HTTP_BASE);
println!("Connected");
sleep(Duration::from_millis(300)).await;
let state = device.read_state().await?;
let session_id = state.session_id;
println!("Session ID: {}", session_id);
if let Some(s) = &state.session {
if let Some(c) = &s.config {
if let Some(p) = &c.profile {
println!("Current profile: {}", p.name);
}
}
}
let new_name = "test_profile";
println!("Setting profile to '{}'...", new_name);
if USE_HTTP {
http.set_session_profile(
session_id,
&(ProfileConfig {
name: new_name.to_string(),
required_version: Some(">=3.5".to_string()),
})
).await?;
let confirmed = http.get_session_profile(session_id).await?;
println!("HTTP confirmed profile: {}", confirmed.name);
} else {
device.configure_session(
SessionConfigure {
profile: Some(ProfileConfig {
name: new_name.to_string(),
required_version: Some(">=3.5".to_string()),
}),
basis: None,
serialization: None,
sdf: None,
},
Some(true)
).await?;
sleep(Duration::from_millis(100)).await;
device.send_force_full_render().await?;
sleep(Duration::from_millis(200)).await;
let state = device.read_state().await?;
if let Some(s) = &state.session {
if let Some(c) = &s.config {
if let Some(p) = &c.profile {
println!("WS confirmed profile: {}", p.name);
}
}
} else {
println!(
"WS: session info not available (profile was sent but config not echoed in streaming frames)"
);
}
}
device.shutdown().await?;
println!("Done");
Ok(())
}