#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct WebTransportOptions {
pub allow_pooling: bool,
pub congestion_control: CongestionControl,
pub require_unreliable: bool,
pub server_certificate_hashes: Vec<CertificateHash>,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum CongestionControl {
#[default]
Default,
Throughput,
LowLatency,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CertificateHash {
pub algorithm: HashAlgorithm,
pub value: Vec<u8>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HashAlgorithm {
Sha256,
}
impl WebTransportOptions {
pub fn to_js(&self) -> web_wt_sys::WebTransportOptions {
let js = web_wt_sys::WebTransportOptions::new();
js.set_allow_pooling(self.allow_pooling);
js.set_congestion_control(match self.congestion_control {
CongestionControl::Default => web_wt_sys::WebTransportCongestionControl::Default,
CongestionControl::Throughput => web_wt_sys::WebTransportCongestionControl::Throughput,
CongestionControl::LowLatency => web_wt_sys::WebTransportCongestionControl::LowLatency,
});
js.set_require_unreliable(self.require_unreliable);
let cert_hashes = self
.server_certificate_hashes
.iter()
.map(|cert| {
let hash = web_wt_sys::WebTransportHash::new();
hash.set_algorithm(match cert.algorithm {
HashAlgorithm::Sha256 => "sha-256",
});
hash.set_value(&cert.value);
hash
})
.collect::<Vec<_>>();
js.set_server_certificate_hashes(cert_hashes);
js
}
}