pub struct ClientConnection { /* private fields */ }
Expand description
A live connection to a relay, and all related state.
This connects when created, but may persist beyond disconnection, so we can’t say that it is always connected. Reconnection is not done here; if it becomes disconnected and you want to reconnect then you should drop and recreate to reconnect (and probably take the Incoming data to not lose it)
Implementations§
Source§impl ClientConnection
impl ClientConnection
Sourcepub async fn new(
relay_url: &str,
timeout: Duration,
) -> Result<ClientConnection, Error>
pub async fn new( relay_url: &str, timeout: Duration, ) -> Result<ClientConnection, Error>
Create a new ClientConnection by connecting.
Sourcepub async fn new_with_data(
relay_url: &str,
timeout: Duration,
incoming: Arc<RwLock<Vec<RelayMessage>>>,
) -> Result<ClientConnection, Error>
pub async fn new_with_data( relay_url: &str, timeout: Duration, incoming: Arc<RwLock<Vec<RelayMessage>>>, ) -> Result<ClientConnection, Error>
Create a new ClientConnectdion by connecting, preserving data from a previous connection.
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Is disconnected
Sourcepub async fn disconnect(self) -> Result<(), Error>
pub async fn disconnect(self) -> Result<(), Error>
Disconnect from the relay, consuming self
Sourcepub fn incoming(&self) -> Arc<RwLock<Vec<RelayMessage>>>
pub fn incoming(&self) -> Arc<RwLock<Vec<RelayMessage>>>
Copy an Arc reference to the Incoming relay messages.
Sourcepub async fn subscribe(&self, filter: Filter) -> Result<SubscriptionId, Error>
pub async fn subscribe(&self, filter: Filter) -> Result<SubscriptionId, Error>
Subscribe to a filter. This does not wait for results.
Sourcepub async fn close_subscription(
&self,
sub_id: SubscriptionId,
) -> Result<(), Error>
pub async fn close_subscription( &self, sub_id: SubscriptionId, ) -> Result<(), Error>
Close a subscription
Sourcepub async fn send_message(&self, message: ClientMessage) -> Result<(), Error>
pub async fn send_message(&self, message: ClientMessage) -> Result<(), Error>
Send a ClientMessage
Sourcepub async fn send_ws_message(&self, message: Message) -> Result<(), Error>
pub async fn send_ws_message(&self, message: Message) -> Result<(), Error>
Send a websocket Message
Sourcepub async fn wait_for_relay_message<P>(
&self,
predicate: P,
timeout: Duration,
) -> Result<RelayMessage, Error>
pub async fn wait_for_relay_message<P>( &self, predicate: P, timeout: Duration, ) -> Result<RelayMessage, Error>
Wait for some matching RelayMessage.
The timeout will be reset when any event happens, so it make take longer than the timeout to give up.
Sourcepub async fn get_auth_state(&self) -> AuthState
pub async fn get_auth_state(&self) -> AuthState
Get AuthState