Struct vtubestudio::client::ClientBuilder
source · [−]pub struct ClientBuilder { /* private fields */ }
Expand description
A builder to configure a new Client
with a set of recommended tower
middleware.
- retrying requests on disconnect (using
Reconnect
andRetryPolicy
) - if
authentication
is provided, automatically reauthenticate and retry when it encounters an auth error (usingAuthenticationLayer
).
Example
use vtubestudio::{Client, ClientEvent};
// An auth token from a previous successful authentication request
let stored_token = Some("...".to_string());
let (mut client, mut events) = Client::builder()
.authentication("Plugin name", "Developer name", None)
.auth_token(stored_token)
.build_tungstenite();
tokio::spawn(async move {
while let Some(event) = events.next().await {
match event {
ClientEvent::NewAuthToken(token) =>
println!("Got new token: {token}"),
_ =>
println!("Received event {:?}", event),
}
}
});
Implementations
sourceimpl ClientBuilder
impl ClientBuilder
sourcepub fn build_tungstenite(self) -> (Client, ClientEventStream)
Available on crate feature tokio-tungstenite
only.
pub fn build_tungstenite(self) -> (Client, ClientEventStream)
tokio-tungstenite
only.Consumes the builder and initializes a Client
and ClientEventStream
using
tokio_tungstenite
as the underlying websocket transport library.
sourcepub fn authentication<S1, S2, S3>(self, name: S1, developer: S2, icon: S3) -> Selfwhere
S1: Into<Cow<'static, str>>,
S2: Into<Cow<'static, str>>,
S3: Into<Option<Cow<'static, str>>>,
pub fn authentication<S1, S2, S3>(self, name: S1, developer: S2, icon: S3) -> Selfwhere
S1: Into<Cow<'static, str>>,
S2: Into<Cow<'static, str>>,
S3: Into<Option<Cow<'static, str>>>,
If this is provided, whenever the underlying service encounters an authentication error, it will try to obtain a new auth token and retry the request.
sourcepub fn url<S: Into<String>>(self, url: S) -> Self
pub fn url<S: Into<String>>(self, url: S) -> Self
Sets the websocket URL. The default value is ws://localhost:8001
.
sourcepub fn auth_token(self, token: Option<String>) -> Self
pub fn auth_token(self, token: Option<String>) -> Self
Initial token to use for reauthentication (if authentication
is
provided). This should be the result of a previous successful authentication attempt.
sourcepub fn retry_on_disconnect(self, retry: bool) -> Self
pub fn retry_on_disconnect(self, retry: bool) -> Self
Retry requests on disconnect. The default value is true
.
sourcepub fn request_buffer_size(self, size: usize) -> Self
pub fn request_buffer_size(self, size: usize) -> Self
The max number of outstanding requests/responses.
The default value is 128
.
sourcepub fn event_buffer_size(self, size: usize) -> Self
pub fn event_buffer_size(self, size: usize) -> Self
The max capacity of the ClientEventStream
buffer.
This represents the max number of unacknowledged new events before the client stops sending them.
The default value is 128
.
sourcepub fn build_service<S>(self, service: S) -> (Client, ClientEventStream)where
S: Service<RequestEnvelope, Response = ResponseEnvelope> + Send + 'static,
S::Error: Into<BoxError> + Send + Sync,
S::Future: Send,
pub fn build_service<S>(self, service: S) -> (Client, ClientEventStream)where
S: Service<RequestEnvelope, Response = ResponseEnvelope> + Send + 'static,
S::Error: Into<BoxError> + Send + Sync,
S::Future: Send,
Consumes the builder and initializes a Client
and ClientEventStream
using a custom
[Service
].
Note the ClientEventStream
will only yield ClientEvent::NewAuthToken
events. To
receive all events, use ClientBuilder::build_connector
.
sourcepub fn build_connector<M>(self, connector: M) -> (Client, ClientEventStream)where
M: MakeTransport<String, RequestEnvelope, Item = ResponseEnvelope> + Send + Clone + 'static,
M::Future: Send + 'static,
M::Transport: Send + 'static,
M::MakeError: StdError + Send + Sync + 'static,
M::Error: Send,
BoxError: From<M::Error> + From<M::SinkError>,
pub fn build_connector<M>(self, connector: M) -> (Client, ClientEventStream)where
M: MakeTransport<String, RequestEnvelope, Item = ResponseEnvelope> + Send + Clone + 'static,
M::Future: Send + 'static,
M::Transport: Send + 'static,
M::MakeError: StdError + Send + Sync + 'static,
M::Error: Send,
BoxError: From<M::Error> + From<M::SinkError>,
Consumes the builder and initializes a Client
and ClientEventStream
with a
connector.
The input connector should be a MakeTransport
that meets
the requirements of Reconnect
.
sourcepub fn build_reconnecting_service<S>(
self,
maker: S
) -> (Client, ClientEventStream)where
S: Service<String> + Send + 'static,
S::Error: StdError + Send + Sync,
S::Future: Send + Unpin,
S::Response: Service<RequestEnvelope, Response = ResponseEnvelope> + Send + 'static,
<S::Response as Service<RequestEnvelope>>::Error: StdError + Send + Sync,
<S::Response as Service<RequestEnvelope>>::Future: Send,
pub fn build_reconnecting_service<S>(
self,
maker: S
) -> (Client, ClientEventStream)where
S: Service<String> + Send + 'static,
S::Error: StdError + Send + Sync,
S::Future: Send + Unpin,
S::Response: Service<RequestEnvelope, Response = ResponseEnvelope> + Send + 'static,
<S::Response as Service<RequestEnvelope>>::Error: StdError + Send + Sync,
<S::Response as Service<RequestEnvelope>>::Future: Send,
Consumes the builder and initializes a Client
and ClientEventStream
with a
reconnecting service.
The input service should be a MakeService
that satisfies the
requirements of Reconnect
.
Note the ClientEventStream
will only yield ClientEvent::NewAuthToken
events. To
receive all events, use ClientBuilder::build_connector
.
Trait Implementations
sourceimpl Clone for ClientBuilder
impl Clone for ClientBuilder
sourcefn clone(&self) -> ClientBuilder
fn clone(&self) -> ClientBuilder
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more