This commit is contained in:
parent
2126a142f4
commit
c148314742
17 changed files with 541 additions and 70 deletions
|
|
@ -267,16 +267,17 @@ pub struct WasmClient {
|
|||
impl WasmClient {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(
|
||||
on_state_change: &js_sys::Function,
|
||||
on_message: &js_sys::Function,
|
||||
on_error: &js_sys::Function,
|
||||
on_state_change: Option<js_sys::Function>,
|
||||
on_message: Option<js_sys::Function>,
|
||||
on_error: Option<js_sys::Function>,
|
||||
) -> Self {
|
||||
let noop = || js_sys::Function::new_no_args("");
|
||||
Self {
|
||||
transport: Rc::new(RefCell::new(None)),
|
||||
state: Rc::new(Cell::new(ConnectionState::Disconnected)),
|
||||
on_state_change: on_state_change.clone(),
|
||||
on_message: on_message.clone(),
|
||||
on_error: on_error.clone(),
|
||||
on_state_change: on_state_change.unwrap_or_else(noop),
|
||||
on_message: on_message.unwrap_or_else(noop),
|
||||
on_error: on_error.unwrap_or_else(noop),
|
||||
subscriptions: Rc::new(RefCell::new(HashMap::new())),
|
||||
next_subscription_id: Rc::new(Cell::new(1)),
|
||||
pending_requests: Rc::new(RefCell::new(HashMap::new())),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,13 @@ pub struct ConnectionConfig {
|
|||
pub(crate) description: Option<String>,
|
||||
}
|
||||
|
||||
/// Newer API name for the browser connection configuration.
|
||||
///
|
||||
/// `ConnectionConfig` remains the concrete wasm-bindgen class for backwards
|
||||
/// compatibility with the existing raw JavaScript bindings. The alias keeps
|
||||
/// Rust consumers aligned with the native/WASM naming used by the public API.
|
||||
pub type WasmClientConfig = ConnectionConfig;
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl ConnectionConfig {
|
||||
#[wasm_bindgen(constructor)]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ pub mod logging;
|
|||
pub mod subscription;
|
||||
pub mod transport;
|
||||
|
||||
pub use client::WasmClient;
|
||||
pub use config::{ConnectionConfig, WasmClientConfig};
|
||||
|
||||
#[cfg(not(test))]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -402,7 +402,14 @@ impl WasmTransport {
|
|||
if let Some(reader) = self.stream_reader.borrow_mut().take() {
|
||||
release_reader_lock(&reader);
|
||||
}
|
||||
self.buffer.borrow_mut().clear();
|
||||
// A frame is never allowed to span stream boundaries. The
|
||||
// native persistent-stream sender packs frames on one
|
||||
// stream, while the WASM sender uses one stream per frame;
|
||||
// either mode must reject a truncated frame instead of
|
||||
// silently dropping its prefix.
|
||||
if !self.buffer.borrow().is_empty() {
|
||||
return Err(js_error("stream ended in the middle of a frame"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue