Struct ClientConnection

Source
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

Source

pub async fn new( relay_url: &str, timeout: Duration, ) -> Result<ClientConnection, Error>

Create a new ClientConnection by connecting.

Source

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.

Source

pub fn is_disconnected(&self) -> bool

Is disconnected

Source

pub async fn disconnect(self) -> Result<(), Error>

Disconnect from the relay, consuming self

Source

pub fn incoming(&self) -> Arc<RwLock<Vec<RelayMessage>>>

Copy an Arc reference to the Incoming relay messages.

Source

pub async fn subscribe(&self, filter: Filter) -> Result<SubscriptionId, Error>

Subscribe to a filter. This does not wait for results.

Source

pub async fn close_subscription( &self, sub_id: SubscriptionId, ) -> Result<(), Error>

Close a subscription

Source

pub async fn send_message(&self, message: ClientMessage) -> Result<(), Error>

Send a ClientMessage

Source

pub async fn send_ws_message(&self, message: Message) -> Result<(), Error>

Send a websocket Message

Source

pub async fn wait_for_relay_message<P>( &self, predicate: P, timeout: Duration, ) -> Result<RelayMessage, Error>
where P: Fn(&RelayMessage) -> bool,

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.

Source

pub async fn get_auth_state(&self) -> AuthState

Get AuthState

Source

pub async fn wait_for_auth_state_change( &self, timeout: Duration, ) -> Result<AuthState, Error>

Wait for the given AuthState to occur.

Source

pub async fn send_authenticate(&self, event: Event) -> Result<(), Error>

Authenticate

Trait Implementations§

Source§

impl Debug for ClientConnection

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T