(feat): add auth() function
All checks were successful
CI / checks (push) Successful in 4m52s

(fix): wasm error
This commit is contained in:
Alois 2026-07-02 23:38:38 +02:00
commit 8ae8377662
5 changed files with 28 additions and 19 deletions

View file

@ -705,19 +705,19 @@ impl WasmClient {
let loop_pending_requests = pending_requests.clone();
let ping_timer = self.ping_timer.clone();
wasm_bindgen_futures::spawn_local(async move {
let route_frame = Closure::wrap(Box::new(move |frame: JsValue| {
route_incoming_frame(&frame, &on_msg, &subscriptions, &loop_pending_requests);
}) as Box<dyn FnMut(JsValue)>);
loop_transport
.receive_loop(
route_frame
.as_ref()
.unchecked_ref::<js_sys::Function>()
.clone(),
move |frame: JsValue| {
route_incoming_frame(
&frame,
&on_msg,
&subscriptions,
&loop_pending_requests,
);
},
on_err.clone(),
)
.await;
drop(route_frame);
state.set(ConnectionState::Disconnected);
stop_ping_timer(&ping_timer);
reject_pending_requests(&pending_requests, "disconnected");

View file

@ -347,12 +347,15 @@ impl WasmTransport {
/// Background loop: deliver every incoming frame to `on_message` until the
/// connection closes. Shares reader state with `read_one_frame`, so frames
/// buffered during the handshake are not lost.
pub async fn receive_loop(&self, on_message: js_sys::Function, on_error: js_sys::Function) {
pub async fn receive_loop<F>(&self, mut on_message: F, on_error: js_sys::Function)
where
F: FnMut(JsValue),
{
loop {
match self.next_frame().await {
Ok(FrameOutcome::Frame(frame)) => match parse_frame_value(&frame) {
Ok(parsed) => {
let _ = on_message.call1(&JsValue::NULL, &parsed);
on_message(parsed);
}
Err(e) => {
let message = e.as_string().unwrap_or_else(|| format!("{:?}", e));