Struct songbird::driver::Driver

source ·
pub struct Driver { /* private fields */ }
Available on crate feature driver only.
Expand description

The control object for a Discord voice connection, handling connection, mixing, encoding, en/decryption, and event generation.

When compiled with the "builtin-queue" feature, each driver includes a track queue as a convenience to prevent the additional overhead of per-guild state management.

Implementations§

source§

impl Driver

source

pub fn new(config: Config) -> Self

Creates a new voice driver.

This will create the core voice tasks in the background.

source

pub fn connect(&mut self, info: ConnectionInfo) -> Connect

Connects to a voice channel using the specified server.

This method instantly contacts the driver tasks, and its does not need to be awaited to start the actual connection.

source

pub fn leave(&mut self)

Leaves the current voice channel, disconnecting from it.

This does not forget settings, like whether to be self-deafened or self-muted.

source

pub fn mute(&mut self, mute: bool)

Sets whether the current connection is to be muted.

If there is no live voice connection, then this only acts as a settings update for future connections.

source

pub fn is_mute(&self) -> bool

Returns whether the driver is muted (i.e., processes audio internally but submits none).

source

pub fn play_input(&mut self, input: Input) -> TrackHandle

Plays audio from an input, returning a handle for further control.

source

pub fn play_only_input(&mut self, input: Input) -> TrackHandle

Plays audio from an input, returning a handle for further control.

Unlike Self::play_input, this stops all other inputs attached to the channel.

source

pub fn play(&mut self, track: Track) -> TrackHandle

Plays audio from a Track object.

The main difference between this function and Self::play_input is that this allows for direct manipulation of the Track object before it is passed over to the voice and mixing contexts.

source

pub fn play_only(&mut self, track: Track) -> TrackHandle

Exclusively plays audio from a Track object.

As in Self::play_only_input, this stops all other sources attached to the channel. Like Self::play, however, this allows for direct manipulation of the Track object before it is passed over to the voice and mixing contexts.

source

pub fn set_bitrate(&mut self, bitrate: Bitrate)

Sets the bitrate for encoding Opus packets sent along the channel being managed.

The default rate is 128 kbps. Sensible values range between Bits(512) and Bits(512_000) bits per second. Alternatively, Auto and Max remain available.

source

pub fn stop(&mut self)

Stops playing audio from all sources, if any are set.

source

pub fn set_config(&mut self, config: Config)

Sets the configuration for this driver (and parent Call, if applicable).

source

pub fn config(&self) -> &Config

Returns a view of this driver’s configuration.

source

pub fn add_global_event<F: EventHandler + 'static>( &mut self, event: Event, action: F )

Attach a global event handler to an audio context. Global events may receive any EventContext.

Global timing events will tick regardless of whether audio is playing, so long as the bot is connected to a voice channel, and have no tracks. TrackEvents will respond to all relevant tracks, giving some audio elements.

Users must ensure that no costly work or blocking occurs within the supplied function or closure. Taking excess time could prevent timely sending of packets, causing audio glitches and delays.

source

pub fn remove_all_global_events(&mut self)

Removes all global event handlers from an audio context.

source§

impl Driver

source

pub fn queue(&self) -> &TrackQueue

Available on crate feature builtin-queue only.

Returns a reference to this driver’s built-in queue.

Requires the "builtin-queue" feature. Queue additions should be made via Driver::enqueue and Driver::enqueue_input.

source

pub async fn enqueue_input(&mut self, input: Input) -> TrackHandle

Available on crate feature builtin-queue only.

Adds an audio Input to this driver’s built-in queue.

Requires the "builtin-queue" feature.

source

pub async fn enqueue(&mut self, track: Track) -> TrackHandle

Available on crate feature builtin-queue only.

Adds an existing Track to this driver’s built-in queue.

Requires the "builtin-queue" feature.

source

pub fn enqueue_with_preload( &mut self, track: Track, preload_time: Option<Duration> ) -> TrackHandle

Available on crate feature builtin-queue only.

Add an existing Track to the queue, using a known time to preload the next track.

See TrackQueue::add_with_preload for how preload_time is used.

Requires the "builtin-queue" feature.

Trait Implementations§

source§

impl Clone for Driver

source§

fn clone(&self) -> Driver

Returns a copy 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 Driver

source§

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

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

impl Default for Driver

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for Driver

source§

fn drop(&mut self)

Leaves the current connected voice channel, if connected to one, and forgets all configurations relevant to this Handler.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Driver

§

impl Send for Driver

§

impl Sync for Driver

§

impl Unpin for Driver

§

impl !UnwindSafe for Driver

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> CloneDebuggableStorage for T

source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,