various small improvements

This commit is contained in:
Toshit Chawda 2024-02-28 23:08:56 -08:00
parent 8b2a8a3eb3
commit 5be02151e6
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
11 changed files with 146 additions and 105 deletions

View file

@ -15,10 +15,16 @@ use js_sys::Function;
use std::str::from_utf8;
use tokio::io::WriteHalf;
#[wasm_bindgen]
#[wasm_bindgen(inspectable)]
pub struct EpxWebSocket {
tx: Arc<Mutex<WebSocketWrite<WriteHalf<TokioIo<Upgraded>>>>>,
onerror: Function,
#[wasm_bindgen(readonly, getter_with_clone)]
pub url: String,
#[wasm_bindgen(readonly, getter_with_clone)]
pub protocols: Vec<String>,
#[wasm_bindgen(readonly, getter_with_clone)]
pub origin: String,
}
#[wasm_bindgen]
@ -53,7 +59,7 @@ impl EpxWebSocket {
.method("GET")
.uri(url.clone())
.header("Host", host)
.header("Origin", origin)
.header("Origin", origin.clone())
.header(UPGRADE, "websocket")
.header(CONNECTION, "upgrade")
.header("Sec-WebSocket-Key", key)
@ -109,7 +115,7 @@ impl EpxWebSocket {
.call0(&Object::default())
.replace_err("Failed to call onopen")?;
Ok(Self { tx, onerror })
Ok(Self { tx, onerror, origin, protocols, url: url.to_string() })
}
.await;
if let Err(ret) = ret {