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
impl WsIoClientBuilder
Sourcepub fn build(self) -> WsIoClient
pub fn build(self) -> WsIoClient
Builds a WsIoClient with the accumulated configuration.
Sourcepub fn connect_timeout(self, duration: impl Into<Option<Duration>>) -> Self
pub fn connect_timeout(self, duration: impl Into<Option<Duration>>) -> Self
Sets how long the client waits for the WebSocket connection attempt.
This timeout covers the transport connection and WebSocket HTTP upgrade
handshake. It does not cover ws.io protocol initialization after the
WebSocket connection is established; use Self::init_packet_timeout
and Self::ready_packet_timeout for that phase. Pass None to disable
the connection-attempt timeout.
Sourcepub fn disconnect_timeout(self, duration: Duration) -> Self
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.
Sourcepub fn init_handler_timeout(self, duration: Duration) -> Self
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.
Sourcepub fn init_packet_timeout(self, duration: Duration) -> Self
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.
Sourcepub fn on_session_close<H, Fut>(self, handler: H) -> Self
pub fn on_session_close<H, Fut>(self, handler: H) -> Self
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.
Sourcepub fn on_session_close_handler_timeout(self, duration: Duration) -> Self
pub fn on_session_close_handler_timeout(self, duration: Duration) -> Self
Sets the maximum duration allowed for the session-close handler to run.
Sourcepub fn on_session_ready<H, Fut>(self, handler: H) -> Self
pub fn on_session_ready<H, Fut>(self, handler: H) -> Self
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.
Sourcepub fn packet_codec(self, packet_codec: WsIoPacketCodec) -> Self
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.
Sourcepub fn ping_interval(self, duration: Duration) -> Self
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.
Sourcepub fn ready_packet_timeout(self, duration: Duration) -> Self
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.
Sourcepub fn reconnect_delay(self, delay: Duration) -> Self
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.
Sourcepub fn request_modifier<M, Fut>(self, modifier: M) -> Self
pub fn request_modifier<M, Fut>(self, modifier: M) -> Self
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.
Sourcepub fn request_path(self, request_path: impl AsRef<str>) -> Self
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.
Sourcepub fn websocket_config(self, websocket_config: WebSocketConfig) -> Self
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.
Sourcepub fn websocket_config_mut<F: FnOnce(&mut WebSocketConfig)>(self, f: F) -> Self
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.
Sourcepub fn with_init_handler<H, Fut, D, R>(self, handler: H) -> WsIoClientBuilder
pub fn with_init_handler<H, Fut, D, R>(self, handler: H) -> WsIoClientBuilder
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.