Driver: Automate (re)connection logic (#81)
This PR adds several enhancements to Driver connection logic: * Driver (re)connection attempts now have a default timeout of around 10s. * The driver will now attempt to retry full connection attempts using a user-provided strategy: currently, this defaults to 5 attempts under an exponential backoff strategy. * The driver will now fire `DriverDisconnect` events at the end of any session -- this unifies (re)connection failure events with session expiry as seen in #76, which should provide users with enough detail to know *which* voice channel to reconnect to. Users still need to be careful to read the session/channel IDs to ensure that they aren't overwriting another join. This has been tested using `cargo make ready`, and by setting low timeouts to force failures in the voice receive example (with some additional error handlers). Closes #68.
This commit is contained in:
@@ -203,7 +203,7 @@ impl Call {
|
||||
let (gw_tx, gw_rx) = flume::unbounded();
|
||||
|
||||
let do_conn = self
|
||||
.should_actually_join(|_| Ok(()), &tx, channel_id)
|
||||
.should_actually_join(|_| (), &gw_tx, channel_id)
|
||||
.await?;
|
||||
|
||||
if do_conn {
|
||||
@@ -218,6 +218,14 @@ impl Call {
|
||||
.await
|
||||
.map(|_| Join::new(rx.into_recv_async(), gw_rx.into_recv_async(), timeout))
|
||||
} else {
|
||||
// Skipping the gateway connection implies that the current connection is complete
|
||||
// AND the channel is a match.
|
||||
//
|
||||
// Send a polite request to the driver, which should only *actually* reconnect
|
||||
// if it had a problem earlier.
|
||||
let info = self.current_connection().unwrap().clone();
|
||||
self.driver.raw_connect(info, tx.clone());
|
||||
|
||||
Ok(Join::new(
|
||||
rx.into_recv_async(),
|
||||
gw_rx.into_recv_async(),
|
||||
|
||||
Reference in New Issue
Block a user