Gateway: Add connection timeout, add Config to gateway. (#51)

This change fixes tasks hanging due to rare cases of messages being lost between full Discord reconnections by placing a configurable timeout on the `ConnectionInfo` responses. This is a companion fix to [serenity#1255](https://github.com/serenity-rs/serenity/pull/1255). To make this doable, `Config`s are now used by all versions of `Songbird`/`Call`, and relevant functions are  added to simplify setup with configuration. These are now non-exhaustive, correcting an earlier oversight. For future extensibility, this PR moves the return type of `join`/`join_gateway` into a custom future (no longer leaking flume's `RecvFut` type).

Additionally, this fixes the Makefile's feature sets for driver/gateway-only compilation.

This is a breaking change in:
* the return types of `join`/`join_gateway`
* moving `crate::driver::Config` -> `crate::Config`,
* `Config` and `JoinError` becoming `#[non_breaking]`.

This was tested via `cargo make ready`, and by testing `examples/serenity/voice_receive` with various timeout settings.
This commit is contained in:
Kyle Simpson
2021-03-29 19:51:13 +01:00
parent f449d4f679
commit 1fc3dc2259
18 changed files with 426 additions and 119 deletions

View File

@@ -3,7 +3,7 @@
//!
//! [serenity]: https://crates.io/crates/serenity/0.9.0-rc.2
use crate::manager::Songbird;
use crate::{Config, Songbird};
use serenity::{
client::{ClientBuilder, Context},
prelude::TypeMapKey,
@@ -37,6 +37,14 @@ pub fn register_with(client_builder: ClientBuilder, voice: Arc<Songbird>) -> Cli
.type_map_insert::<SongbirdKey>(voice)
}
/// Installs a given songbird instance into the serenity client.
///
/// This should be called after any uses of `ClientBuilder::type_map`.
pub fn register_from_config(client_builder: ClientBuilder, config: Config) -> ClientBuilder {
let voice = Songbird::serenity_from_config(config);
register_with(client_builder, voice)
}
/// Retrieve the Songbird voice client from a serenity context's
/// shared key-value store.
pub async fn get(ctx: &Context) -> Option<Arc<Songbird>> {
@@ -58,6 +66,8 @@ pub trait SerenityInit {
fn register_songbird(self) -> Self;
/// Registers a given Songbird voice system with serenity, as above.
fn register_songbird_with(self, voice: Arc<Songbird>) -> Self;
/// Registers a Songbird voice system serenity, based on the given configuration.
fn register_songbird_from_config(self, config: Config) -> Self;
}
impl SerenityInit for ClientBuilder<'_> {
@@ -68,4 +78,8 @@ impl SerenityInit for ClientBuilder<'_> {
fn register_songbird_with(self, voice: Arc<Songbird>) -> Self {
register_with(self, voice)
}
fn register_songbird_from_config(self, config: Config) -> Self {
register_from_config(self, config)
}
}