Implement Songbird driver configuration (#1074)

This commit is contained in:
Kyle Simpson
2020-11-11 22:40:09 +00:00
committed by GitHub
parent 26c9c9117c
commit 8b7f388f7b
14 changed files with 604 additions and 113 deletions

View File

@@ -1,5 +1,8 @@
#[cfg(feature = "driver")]
use crate::{driver::Driver, error::ConnectionResult};
use crate::{
driver::{Config, Driver},
error::ConnectionResult,
};
use crate::{
error::{JoinError, JoinResult},
id::{ChannelId, GuildId, UserId},
@@ -59,6 +62,19 @@ impl Call {
Self::new_raw(guild_id, Some(ws), user_id)
}
#[cfg(feature = "driver")]
/// Creates a new Call, configuring the driver as specified.
#[inline]
#[instrument]
pub fn from_driver_config(
guild_id: GuildId,
ws: Shard,
user_id: UserId,
config: Config,
) -> Self {
Self::new_raw_cfg(guild_id, Some(ws), user_id, config)
}
/// Creates a new, standalone Call which is not connected via
/// WebSocket to the Gateway.
///
@@ -73,6 +89,18 @@ impl Call {
Self::new_raw(guild_id, None, user_id)
}
#[cfg(feature = "driver")]
/// Creates a new standalone Call, configuring the driver as specified.
#[inline]
#[instrument]
pub fn standalone_from_driver_config(
guild_id: GuildId,
user_id: UserId,
config: Config,
) -> Self {
Self::new_raw_cfg(guild_id, None, user_id, config)
}
fn new_raw(guild_id: GuildId, ws: Option<Shard>, user_id: UserId) -> Self {
Call {
connection: None,
@@ -86,6 +114,19 @@ impl Call {
}
}
#[cfg(feature = "driver")]
fn new_raw_cfg(guild_id: GuildId, ws: Option<Shard>, user_id: UserId, config: Config) -> Self {
Call {
connection: None,
driver: Driver::new(config),
guild_id,
self_deaf: false,
self_mute: false,
user_id,
ws,
}
}
#[instrument(skip(self))]
fn do_connect(&mut self) {
match &self.connection {