Struct IoEmitter

Source
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

Source

pub fn new() -> Self

Creates a new IoEmitter with the default settings.

Source

pub fn new_msgpack() -> Self

Available on crate feature msgpack-parser only.

Creates a new IoEmitter with the msgpack parser.

Source

pub fn of(self, ns: impl Into<Str>) -> IoEmitter

Sets the namespace for this IoEmitter. By default, the namespace is set to /.

Source

pub fn to(self, rooms: impl RoomParam) -> IoEmitter

Sets the rooms for this IoEmitter. By default, events are sent to all rooms.

Source

pub fn within(self, rooms: impl RoomParam) -> IoEmitter

Alias for IoEmitter::to.

Source

pub fn except(self, rooms: impl RoomParam) -> IoEmitter

Excludes the specified rooms.

Source

pub fn prefix(self, prefix: impl Into<String>) -> IoEmitter

You may have set a custom prefix on your adapter config, which will be used as a prefix for the channel name. By default, the prefix is socket.io.

Source§

impl IoEmitter

Source

pub async fn join<D: Driver>( self, rooms: impl RoomParam, driver: &D, ) -> Result<(), D::Error>

Makes the selected sockets join the specified rooms.

§Example
// Makes the sockets in the root namespace and in the room1 and room2, join the room4.
IoEmitter::new()
    .to(["room1", "room2"])
    .join("room4", &driver)
    .await?;
Source

pub async fn leave<D: Driver>( self, rooms: impl RoomParam, driver: &D, ) -> Result<(), D::Error>

Makes the selected sockets leave the specified rooms.

§Example
// Makes the sockets in the root namespace and in the room1 and room2, leave the room4.
IoEmitter::new()
    .to(["room1", "room2"])
    .leave("room4", &driver)
    .await?;
Source

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?;
Source

pub 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.

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§

Source§

impl Clone for IoEmitter

Source§

fn clone(&self) -> IoEmitter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IoEmitter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IoEmitter

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V