pub struct SocketIoBuilder<A: Adapter = LocalAdapter> { /* private fields */ }Expand description
A builder to create a SocketIo instance.
It contains everything to configure the socket.io server with a SocketIoConfig.
It can be used to build either a Tower Layer or a Service.
Implementations§
Source§impl SocketIoBuilder<LocalAdapter>
impl SocketIoBuilder<LocalAdapter>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new SocketIoBuilder with default config
Source§impl<A: Adapter> SocketIoBuilder<A>
impl<A: Adapter> SocketIoBuilder<A>
Sourcepub fn req_path(self, req_path: impl Into<Cow<'static, str>>) -> Self
pub fn req_path(self, req_path: impl Into<Cow<'static, str>>) -> Self
The path to listen for socket.io requests on.
Defaults to “/socket.io”.
Sourcepub fn ping_interval(self, ping_interval: Duration) -> Self
pub fn ping_interval(self, ping_interval: Duration) -> Self
The interval at which the server will send a ping packet to the client.
Defaults to 25 seconds.
Sourcepub fn ping_timeout(self, ping_timeout: Duration) -> Self
pub fn ping_timeout(self, ping_timeout: Duration) -> Self
The amount of time the server will wait for a ping response from the client before closing the connection.
Defaults to 20 seconds.
Sourcepub fn max_buffer_size(self, max_buffer_size: usize) -> Self
pub fn max_buffer_size(self, max_buffer_size: usize) -> Self
The maximum number of packets that can be buffered per connection before being emitted to the client.
If the buffer if full the emit() method will return an error
Defaults to 128 packets.
Sourcepub fn max_payload(self, max_payload: u64) -> Self
pub fn max_payload(self, max_payload: u64) -> Self
The maximum size of a payload in bytes.
If a payload is bigger than this value the emit() method will return an error.
Defaults to 100 kb.
Sourcepub fn ws_read_buffer_size(self, ws_read_buffer_size: usize) -> Self
pub fn ws_read_buffer_size(self, ws_read_buffer_size: usize) -> Self
The size of the read buffer for the websocket transport. You can tweak this value depending on your use case. Defaults to 4KiB.
Setting it to a higher value will improve performance on heavy read scenarios but will consume more memory.
Sourcepub fn transports<const N: usize>(self, transports: [TransportType; N]) -> Self
pub fn transports<const N: usize>(self, transports: [TransportType; N]) -> Self
Allowed transports on this server
The transports array should have a size of 1 or 2
Defaults to :
[TransportType::Polling, TransportType::Websocket]
Sourcepub fn ack_timeout(self, ack_timeout: Duration) -> Self
pub fn ack_timeout(self, ack_timeout: Duration) -> Self
The amount of time the server will wait for an acknowledgement from the client before closing the connection.
Defaults to 5 seconds.
Sourcepub fn connect_timeout(self, connect_timeout: Duration) -> Self
pub fn connect_timeout(self, connect_timeout: Duration) -> Self
The amount of time before disconnecting a client that has not successfully joined a namespace.
Defaults to 45 seconds.
Sourcepub fn with_config(self, config: SocketIoConfig) -> Self
pub fn with_config(self, config: SocketIoConfig) -> Self
Sets a custom SocketIoConfig created previously for this SocketIoBuilder
Sourcepub fn with_parser(self, parser: ParserConfig) -> Self
pub fn with_parser(self, parser: ParserConfig) -> Self
Set a custom ParserConfig for this SocketIoBuilder
let (io, layer) = SocketIo::builder()
.with_parser(ParserConfig::msgpack())
.build_layer();Sourcepub fn with_adapter<B: Adapter>(
self,
adapter_state: B::State,
) -> SocketIoBuilder<B>
pub fn with_adapter<B: Adapter>( self, adapter_state: B::State, ) -> SocketIoBuilder<B>
Set a custom Adapter for this SocketIoBuilder
Sourcepub fn with_state<S: Clone + Send + Sync + 'static>(self, state: S) -> Self
Available on crate feature state only.
pub fn with_state<S: Clone + Send + Sync + 'static>(self, state: S) -> Self
state only.Add a custom global state for the SocketIo instance.
This state will be accessible from every handler with the State extractor.
You can set any number of states as long as they have different types.
The state must be cloneable, therefore it is recommended to wrap it in an Arc if you want shared state.
Source§impl<A: Adapter> SocketIoBuilder<A>
impl<A: Adapter> SocketIoBuilder<A>
Sourcepub fn build_layer(self) -> (SocketIoLayer<A>, SocketIo<A>)
pub fn build_layer(self) -> (SocketIoLayer<A>, SocketIo<A>)
Build a SocketIoLayer and a SocketIo instance that can be used as a tower_layer::Layer.
Sourcepub fn build_svc(self) -> (SocketIoService<NotFoundService, A>, SocketIo<A>)
pub fn build_svc(self) -> (SocketIoService<NotFoundService, A>, SocketIo<A>)
Build a SocketIoService and a SocketIo instance that
can be used as a hyper::service::Service or a tower_service::Service.
This service will be a standalone service that return a 404 error for every non-socket.io request
Sourcepub fn build_with_inner_svc<S: Clone>(
self,
svc: S,
) -> (SocketIoService<S, A>, SocketIo<A>)
pub fn build_with_inner_svc<S: Clone>( self, svc: S, ) -> (SocketIoService<S, A>, SocketIo<A>)
Build a SocketIoService and a SocketIo instance with an inner service that
can be used as a hyper::service::Service or a tower_service::Service.