Trait socketioxide::adapter::Adapter
source · pub trait Adapter: Debug + Send + Sync + 'static {
type Error: Error + Into<AdapterError> + Send + Sync + 'static;
Show 16 methods
// Required methods
fn new(ns: Weak<Namespace<Self>>) -> Self
where Self: Sized;
fn init(&self) -> Result<(), Self::Error>;
fn close(&self) -> Result<(), Self::Error>;
fn server_count(&self) -> Result<u16, Self::Error>;
fn add_all(
&self,
sid: Sid,
rooms: impl RoomParam
) -> Result<(), Self::Error>;
fn del(&self, sid: Sid, rooms: impl RoomParam) -> Result<(), Self::Error>;
fn del_all(&self, sid: Sid) -> Result<(), Self::Error>;
fn broadcast(
&self,
packet: Packet<'_>,
opts: BroadcastOptions
) -> Result<(), BroadcastError>;
fn broadcast_with_ack(
&self,
packet: Packet<'static>,
opts: BroadcastOptions,
timeout: Option<Duration>
) -> AckInnerStream ⓘ;
fn sockets(&self, rooms: impl RoomParam) -> Result<Vec<Sid>, Self::Error>;
fn socket_rooms(&self, sid: Sid) -> Result<Vec<Room>, Self::Error>;
fn fetch_sockets(
&self,
opts: BroadcastOptions
) -> Result<Vec<SocketRef<Self>>, Self::Error>
where Self: Sized;
fn add_sockets(
&self,
opts: BroadcastOptions,
rooms: impl RoomParam
) -> Result<(), Self::Error>;
fn del_sockets(
&self,
opts: BroadcastOptions,
rooms: impl RoomParam
) -> Result<(), Self::Error>;
fn disconnect_socket(
&self,
opts: BroadcastOptions
) -> Result<(), Vec<DisconnectError>>;
fn rooms(&self) -> Result<Vec<Room>, Self::Error>;
}Expand description
An adapter is responsible for managing the state of the server.
This adapter can be implemented to share the state between multiple servers.
The default adapter is the LocalAdapter, which stores the state in memory.
Required Associated Types§
sourcetype Error: Error + Into<AdapterError> + Send + Sync + 'static
type Error: Error + Into<AdapterError> + Send + Sync + 'static
An error that can occur when using the adapter. The default LocalAdapter has an Infallible error.
Required Methods§
sourcefn new(ns: Weak<Namespace<Self>>) -> Selfwhere
Self: Sized,
fn new(ns: Weak<Namespace<Self>>) -> Selfwhere
Self: Sized,
Create a new adapter and give the namespace ref to retrieve sockets.
sourcefn server_count(&self) -> Result<u16, Self::Error>
fn server_count(&self) -> Result<u16, Self::Error>
Returns the number of servers.
sourcefn add_all(&self, sid: Sid, rooms: impl RoomParam) -> Result<(), Self::Error>
fn add_all(&self, sid: Sid, rooms: impl RoomParam) -> Result<(), Self::Error>
Adds the socket to all the rooms.
sourcefn del(&self, sid: Sid, rooms: impl RoomParam) -> Result<(), Self::Error>
fn del(&self, sid: Sid, rooms: impl RoomParam) -> Result<(), Self::Error>
Removes the socket from the rooms.
sourcefn broadcast(
&self,
packet: Packet<'_>,
opts: BroadcastOptions
) -> Result<(), BroadcastError>
fn broadcast( &self, packet: Packet<'_>, opts: BroadcastOptions ) -> Result<(), BroadcastError>
Broadcasts the packet to the sockets that match the BroadcastOptions.
sourcefn broadcast_with_ack(
&self,
packet: Packet<'static>,
opts: BroadcastOptions,
timeout: Option<Duration>
) -> AckInnerStream ⓘ
fn broadcast_with_ack( &self, packet: Packet<'static>, opts: BroadcastOptions, timeout: Option<Duration> ) -> AckInnerStream ⓘ
Broadcasts the packet to the sockets that match the BroadcastOptions and return a stream of ack responses.
sourcefn sockets(&self, rooms: impl RoomParam) -> Result<Vec<Sid>, Self::Error>
fn sockets(&self, rooms: impl RoomParam) -> Result<Vec<Sid>, Self::Error>
Returns the sockets ids that match the BroadcastOptions.
sourcefn socket_rooms(&self, sid: Sid) -> Result<Vec<Room>, Self::Error>
fn socket_rooms(&self, sid: Sid) -> Result<Vec<Room>, Self::Error>
Returns the rooms of the socket.
sourcefn fetch_sockets(
&self,
opts: BroadcastOptions
) -> Result<Vec<SocketRef<Self>>, Self::Error>where
Self: Sized,
fn fetch_sockets(
&self,
opts: BroadcastOptions
) -> Result<Vec<SocketRef<Self>>, Self::Error>where
Self: Sized,
Returns the sockets that match the BroadcastOptions.
sourcefn add_sockets(
&self,
opts: BroadcastOptions,
rooms: impl RoomParam
) -> Result<(), Self::Error>
fn add_sockets( &self, opts: BroadcastOptions, rooms: impl RoomParam ) -> Result<(), Self::Error>
Adds the sockets that match the BroadcastOptions to the rooms.
sourcefn del_sockets(
&self,
opts: BroadcastOptions,
rooms: impl RoomParam
) -> Result<(), Self::Error>
fn del_sockets( &self, opts: BroadcastOptions, rooms: impl RoomParam ) -> Result<(), Self::Error>
Removes the sockets that match the BroadcastOptions from the rooms.
sourcefn disconnect_socket(
&self,
opts: BroadcastOptions
) -> Result<(), Vec<DisconnectError>>
fn disconnect_socket( &self, opts: BroadcastOptions ) -> Result<(), Vec<DisconnectError>>
Disconnects the sockets that match the BroadcastOptions.