Docs & wasm
This commit is contained in:
parent
29427d301b
commit
be4b76dcd5
7 changed files with 953 additions and 6 deletions
|
|
@ -28,6 +28,8 @@ web-sys = { version = "0.3", features = [
|
|||
] }
|
||||
console_error_panic_hook = "0.1"
|
||||
|
||||
hex = "0.4"
|
||||
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.6"
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ impl WasmClient {
|
|||
#[wasm_bindgen]
|
||||
pub async fn connect(&mut self, config: &ConnectionConfig) -> Result<(), JsValue> {
|
||||
self.set_state(ConnectionState::Connecting);
|
||||
let transport = WasmTransport::connect(&config.url).await?;
|
||||
let transport = WasmTransport::connect(&config.url, config.server_certificate_hashes.clone()).await?;
|
||||
let inner = transport.inner().clone();
|
||||
|
||||
let version_str = format!("{}", PROTOCOL_VERSION);
|
||||
|
|
@ -157,7 +157,7 @@ impl WasmClient {
|
|||
.add_typed_default(DataType::Signature, DataValue::Bytes(signature))
|
||||
.to_bytes();
|
||||
|
||||
let transport = WasmTransport::connect(&config.url).await?;
|
||||
let transport = WasmTransport::connect(&config.url, config.server_certificate_hashes.clone()).await?;
|
||||
let inner = transport.inner().clone();
|
||||
transport.send_frame(&frame).await?;
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ impl WasmClient {
|
|||
.add_typed_default(DataType::Signature, DataValue::Bytes(signature))
|
||||
.to_bytes();
|
||||
|
||||
let transport = WasmTransport::connect(&config.url).await?;
|
||||
let transport = WasmTransport::connect(&config.url, config.server_certificate_hashes.clone()).await?;
|
||||
let inner = transport.inner().clone();
|
||||
transport.send_frame(&frame).await?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::WebTransport;
|
||||
use web_sys::{WebTransport, WebTransportHash, WebTransportOptions};
|
||||
|
||||
use crate::error::js_error;
|
||||
|
||||
|
|
@ -11,8 +11,28 @@ pub struct WasmTransport {
|
|||
}
|
||||
|
||||
impl WasmTransport {
|
||||
pub async fn connect(url: &str) -> Result<Self, JsValue> {
|
||||
let transport = WebTransport::new(url)?;
|
||||
pub async fn connect(url: &str, cert_hashes: Option<Vec<String>>) -> Result<Self, JsValue> {
|
||||
let transport = match cert_hashes {
|
||||
Some(hashes) => {
|
||||
let opts = WebTransportOptions::new();
|
||||
let mut wt_hashes = Vec::new();
|
||||
for h in hashes {
|
||||
if let Some((algo, hex_val)) = h.split_once(':') {
|
||||
if let Ok(bytes) = hex::decode(hex_val) {
|
||||
let hash = WebTransportHash::new();
|
||||
hash.set_algorithm(algo);
|
||||
hash.set_value_u8_array(&js_sys::Uint8Array::from(&bytes[..]));
|
||||
wt_hashes.push(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !wt_hashes.is_empty() {
|
||||
opts.set_server_certificate_hashes(&wt_hashes);
|
||||
}
|
||||
WebTransport::new_with_options(url, &opts)?
|
||||
}
|
||||
None => WebTransport::new(url)?,
|
||||
};
|
||||
JsFuture::from(transport.ready()).await
|
||||
.map_err(|e| js_error(&format!("WebTransport ready failed: {:?}", e)))?;
|
||||
Ok(Self { inner: transport })
|
||||
|
|
|
|||
Loading…
Reference in a new issue