pub struct ConnectionPool { /* private fields */ }Expand description
Manages multiple WebSocket connections keyed by SessionId.
Thread-safe, supports concurrent access from multiple Windows. All Firefox windows connect to the same port, messages routed by session.
§Example
let pool = ConnectionPool::new().await?;
println!("WebSocket URL: {}", pool.ws_url());
// Wait for a specific session to connect
let ready_data = pool.wait_for_session(session_id).await?;
// Send a request to that session
let response = pool.send(session_id, request).await?;Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn ws_url(&self) -> &str
pub fn ws_url(&self) -> &str
Returns the WebSocket URL for this pool.
Uses the actual bound IP address instead of hardcoding 127.0.0.1.
Format: ws://{bound_ip}:{port}
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Returns the number of active connections.
Sourcepub async fn wait_for_session(&self, session_id: SessionId) -> Result<ReadyData>
pub async fn wait_for_session(&self, session_id: SessionId) -> Result<ReadyData>
Waits for a specific session to connect.
Called by spawn_window after launching Firefox.
Returns when Firefox with this sessionId connects and sends READY.
§Arguments
session_id- The session ID to wait for
§Errors
Error::ConnectionTimeoutif session doesn’t connect within 30s
Sourcepub async fn send(
&self,
session_id: SessionId,
request: Request,
) -> Result<Response>
pub async fn send( &self, session_id: SessionId, request: Request, ) -> Result<Response>
Sends a request to a specific session.
§Arguments
session_id- Target sessionrequest- Request to send
§Errors
Error::SessionNotFoundif session doesn’t existError::ConnectionClosedif connection is closedError::RequestTimeoutif response not received within timeout
Sourcepub async fn send_with_timeout(
&self,
session_id: SessionId,
request: Request,
request_timeout: Duration,
) -> Result<Response>
pub async fn send_with_timeout( &self, session_id: SessionId, request: Request, request_timeout: Duration, ) -> Result<Response>
Sends a request with custom timeout.
§Arguments
session_id- Target sessionrequest- Request to sendtimeout- Maximum time to wait for response
§Errors
Error::SessionNotFoundif session doesn’t existError::ConnectionClosedif connection is closedError::RequestTimeoutif response not received within timeout
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn add_event_handler(
&self,
session_id: SessionId,
key: String,
handler: EventHandler,
)
pub fn add_event_handler( &self, session_id: SessionId, key: String, handler: EventHandler, )
Adds an event handler for a session with a key label.
Multiple handlers can be registered for the same session. If a handler with the same key already exists, it is replaced.
§Arguments
session_id- Target sessionkey- Unique key for this handler (used for removal)handler- Event handler callback
Sourcepub fn remove_event_handler(&self, session_id: SessionId, key: &str)
pub fn remove_event_handler(&self, session_id: SessionId, key: &str)
Removes an event handler for a session by key.
§Arguments
session_id- Target sessionkey- Key of the handler to remove