pub struct BridgeClient { /* private fields */ }Expand description
WebSocket client that relays messages between Brain and a remote gateway.
Implementations§
Source§impl BridgeClient
impl BridgeClient
Sourcepub fn new(url: impl Into<String>, config: BridgeConfig) -> Self
pub fn new(url: impl Into<String>, config: BridgeConfig) -> Self
Create a new client pointing at url.
Sourcepub fn backoff_duration(&self, attempt: u32) -> Duration
pub fn backoff_duration(&self, attempt: u32) -> Duration
Calculate the backoff duration for a given retry attempt number (0-indexed).
Uses exponential back-off: initial * 2^attempt, capped at max.
Sourcepub async fn connect_and_relay<F, Fut>(
&self,
handler: F,
) -> Result<(), BridgeError>
pub async fn connect_and_relay<F, Fut>( &self, handler: F, ) -> Result<(), BridgeError>
Connect to the remote WebSocket gateway and relay messages indefinitely.
For each inbound BridgeMessage, handler is called and its return
value is sent back as a text frame. On disconnect the client waits for
the appropriate backoff period then reconnects automatically.
Returns Err(BridgeError::MaxRetriesExceeded) only when
BridgeConfig::max_reconnect_attempts is set and exceeded.
Sourcepub async fn connect_and_relay_bidirectional<F, Fut>(
&self,
handler: F,
proactive_rx: Option<Receiver<BridgeMessage>>,
) -> Result<(), BridgeError>
pub async fn connect_and_relay_bidirectional<F, Fut>( &self, handler: F, proactive_rx: Option<Receiver<BridgeMessage>>, ) -> Result<(), BridgeError>
Connect with optional proactive push channel.
When proactive_rx is provided, proactive notifications are forwarded
to the gateway as outbound BridgeMessage frames alongside the normal
request-response relay.