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

@@ -28,14 +28,14 @@ use serenity::{
};
use songbird::{
driver::{Config as DriverConfig, DecodeMode},
driver::DecodeMode,
model::payload::{ClientConnect, ClientDisconnect, Speaking},
Config,
CoreEvent,
Event,
EventContext,
EventHandler as VoiceEventHandler,
SerenityInit,
Songbird,
};
struct Handler;
@@ -167,16 +167,13 @@ async fn main() {
// Here, we need to configure Songbird to decode all incoming voice packets.
// If you want, you can do this on a per-call basis---here, we need it to
// read the audio data that other people are sending us!
let songbird = Songbird::serenity();
songbird.set_config(
DriverConfig::default()
.decode_mode(DecodeMode::Decode)
);
let songbird_config = Config::default()
.decode_mode(DecodeMode::Decode);
let mut client = Client::builder(&token)
.event_handler(Handler)
.framework(framework)
.register_songbird_with(songbird.into())
.register_songbird_from_config(songbird_config)
.await
.expect("Err creating client");