30 lines
852 B
Rust
30 lines
852 B
Rust
|
|
// client/src/handshake.rs
|
|||
|
|
#![forbid(unsafe_code)]
|
|||
|
|
|
|||
|
|
use lesavka_common::lesavka::{self as pb, handshake_client::HandshakeClient};
|
|||
|
|
use tonic::Code;
|
|||
|
|
|
|||
|
|
#[derive(Default, Clone, Copy, Debug)]
|
|||
|
|
pub struct PeerCaps {
|
|||
|
|
pub camera: bool,
|
|||
|
|
pub microphone: bool,
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
pub async fn negotiate(uri: &str) -> PeerCaps {
|
|||
|
|
let mut cli = HandshakeClient::connect(uri.to_owned())
|
|||
|
|
.await
|
|||
|
|
.expect("\"dial handshake\"");
|
|||
|
|
|
|||
|
|
match cli.get_capabilities(pb::Empty {}).await {
|
|||
|
|
Ok(rsp) => PeerCaps {
|
|||
|
|
camera: rsp.get_ref().camera,
|
|||
|
|
microphone: rsp.get_ref().microphone,
|
|||
|
|
},
|
|||
|
|
Err(e) if e.code() == Code::Unimplemented => {
|
|||
|
|
// ↺ old server – pretend it supports nothing special.
|
|||
|
|
PeerCaps::default()
|
|||
|
|
}
|
|||
|
|
Err(e) => panic!("\"handshake failed: {e}\""),
|
|||
|
|
}
|
|||
|
|
}
|