pub struct IoEmitter { /* private fields */ }Expand description
The IoEmitter is the main structure for emitting events to a socket.io cluster.
It provides a convenient way to broadcast events to all connected nodes and clients.
It acts as a simple builder for creating socket.io messages to send through the driver.
Implementations§
Source§impl IoEmitter
impl IoEmitter
Sourcepub fn new_msgpack() -> Self
Available on crate feature msgpack-parser only.
pub fn new_msgpack() -> Self
msgpack-parser only.Creates a new IoEmitter with the msgpack parser.
Sourcepub fn of(self, ns: impl Into<Str>) -> IoEmitter
pub fn of(self, ns: impl Into<Str>) -> IoEmitter
Sets the namespace for this IoEmitter. By default, the namespace is set to /.
Sourcepub fn to(self, rooms: impl RoomParam) -> IoEmitter
pub fn to(self, rooms: impl RoomParam) -> IoEmitter
Sets the rooms for this IoEmitter. By default, events are sent to all rooms.
Sourcepub fn within(self, rooms: impl RoomParam) -> IoEmitter
pub fn within(self, rooms: impl RoomParam) -> IoEmitter
Alias for IoEmitter::to.
Source§impl IoEmitter
impl IoEmitter
Sourcepub async fn join<D: Driver>(
self,
rooms: impl RoomParam,
driver: &D,
) -> Result<(), D::Error>
pub async fn join<D: Driver>( self, rooms: impl RoomParam, driver: &D, ) -> Result<(), D::Error>
Sourcepub async fn leave<D: Driver>(
self,
rooms: impl RoomParam,
driver: &D,
) -> Result<(), D::Error>
pub async fn leave<D: Driver>( self, rooms: impl RoomParam, driver: &D, ) -> Result<(), D::Error>
Sourcepub async fn disconnect<D: Driver>(self, driver: &D) -> Result<(), D::Error>
pub async fn disconnect<D: Driver>(self, driver: &D) -> Result<(), D::Error>
Disconnects the selected sockets from their namespace.
ⓘ
// Makes the sockets in the root namespace and in the room1 and room2, disconnect.
IoEmitter::new()
.to(["room1", "room2"])
.disconnect(&driver)
.await?;Sourcepub async fn emit<D: Driver, T: Serialize + ?Sized>(
self,
event: &str,
msg: &T,
driver: &D,
) -> Result<(), EmitError<D>>
Available on crate features msgpack-parser or common-parser only.
pub async fn emit<D: Driver, T: Serialize + ?Sized>( self, event: &str, msg: &T, driver: &D, ) -> Result<(), EmitError<D>>
msgpack-parser or common-parser only.Emits a socket.io event to the selected sockets.
ⓘ
// Emits the event "message" with the message "Hello, world!" to the root namespace sockets
// that are in the room1 and room2
IoEmitter::new()
.to(["room1", "room2"])
.emit("message", "Hello, world!", &driver)
.await?;Trait Implementations§
Auto Trait Implementations§
impl !Freeze for IoEmitter
impl RefUnwindSafe for IoEmitter
impl Send for IoEmitter
impl Sync for IoEmitter
impl Unpin for IoEmitter
impl UnwindSafe for IoEmitter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more