Skip to main content

WsIoClientBuilder

Struct WsIoClientBuilder 

Source
pub struct WsIoClientBuilder { /* private fields */ }
Expand description

Builder for configuring and creating a WsIoClient.

The URL passed to the client constructor selects the namespace from its path, while the actual WebSocket request path defaults to /ws.io.

Implementations§

Source§

impl WsIoClientBuilder

Source

pub fn build(self) -> WsIoClient

Builds a WsIoClient with the accumulated configuration.

Source

pub fn disconnect_timeout(self, duration: Duration) -> Self

Sets how long disconnect().await waits for graceful WebSocket shutdown before aborting the connection read/write tasks.

Source

pub fn init_handler_timeout(self, duration: Duration) -> Self

Sets the maximum duration allowed for the init handler to run.

The init handler is registered with Self::with_init_handler and is invoked after the server sends the init packet.

Source

pub fn init_packet_timeout(self, duration: Duration) -> Self

Sets how long the client waits for the server init packet after the WebSocket connection is established.

If the init packet is not received before this timeout, the session is closed and the runtime may reconnect according to Self::reconnect_delay.

Source

pub fn on_session_close<H, Fut>(self, handler: H) -> Self
where H: Fn(Arc<WsIoClientSession>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<()>> + Send + 'static,

Registers a handler that runs when a session closes.

The handler is awaited during session cleanup and is bounded by Self::on_session_close_handler_timeout.

Source

pub fn on_session_close_handler_timeout(self, duration: Duration) -> Self

Sets the maximum duration allowed for the session-close handler to run.

Source

pub fn on_session_ready<H, Fut>(self, handler: H) -> Self
where H: Fn(Arc<WsIoClientSession>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<()>> + Send + 'static,

Registers a handler that runs after a session becomes ready.

The handler is spawned asynchronously after the ready packet is received, so it does not block the connection handshake.

Source

pub fn packet_codec(self, packet_codec: WsIoPacketCodec) -> Self

Sets the packet codec used to encode and decode ws.io protocol packets.

This must match the server namespace codec.

Source

pub fn ping_interval(self, duration: Duration) -> Self

Sets the interval for client heartbeat frames.

After session initialization starts, the client periodically sends a one-byte binary WebSocket frame. The server treats single-byte binary frames as heartbeats and ignores them before packet decoding.

Source

pub fn ready_packet_timeout(self, duration: Duration) -> Self

Sets how long the client waits for the server ready packet.

The ready timeout starts after the client handles the server init packet and sends its init response.

Source

pub fn reconnect_delay(self, delay: Duration) -> Self

Sets the delay before the runtime attempts another connection.

This delay is used after a connection attempt/session ends while the client runtime is still running.

Source

pub fn request_modifier<M, Fut>(self, modifier: M) -> Self
where M: Fn(Request<()>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Request<()>>> + Send + 'static,

Registers an async modifier for the WebSocket HTTP request.

Use this to add headers or adjust request metadata before connect_async_with_config is called.

Source

pub fn request_path(self, request_path: impl AsRef<str>) -> Self

Sets the WebSocket HTTP request path.

Paths are normalized to a single leading slash with empty path segments removed. This controls the request URI path, not the namespace query value inferred from the original URL passed to the builder.

Source

pub fn websocket_config(self, websocket_config: WebSocketConfig) -> Self

Replaces the full Tungstenite WebSocket configuration.

This controls transport limits and buffer sizes passed to the WebSocket connection. It is also used to derive internal channel capacity from the configured max-write/write-buffer ratio.

Source

pub fn websocket_config_mut<F: FnOnce(&mut WebSocketConfig)>(self, f: F) -> Self

Mutates the current Tungstenite WebSocket configuration in place.

Prefer this when you want to adjust one or two fields while keeping the builder defaults for the rest.

Source

pub fn with_init_handler<H, Fut, D, R>(self, handler: H) -> WsIoClientBuilder
where H: Fn(Arc<WsIoClientSession>, Option<D>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Option<R>>> + Send + 'static, D: DeserializeOwned + Send + 'static, R: Serialize + Send + 'static,

Registers the client-side init handler.

The handler receives the session and the optional server init payload decoded as D. Its optional return value is encoded as R and sent back to the server as the client init response.

Trait Implementations§

Source§

impl Debug for WsIoClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V