Events: Add (re)connect success/fail events.
These should allow bots to hook up events to a variety of important connection events as required. This was primarily motivated by the user who raised dcb6ad9.
Although I really would have liked to squeeze in (finite) reconnection attempts with exponential backoff, so that automated repeat attempts could be neatly handled, `Config` was accidentally *not* made non-exhaustive. Adding this and its needed configuration would then be a breaking change. This should warn users about an accidentally dead connection, until the next version can be put forth.
This commit is contained in:
@@ -69,6 +69,16 @@ pub enum EventContext<'a> {
|
||||
ClientConnect(ClientConnect),
|
||||
/// Fired whenever a client disconnects.
|
||||
ClientDisconnect(ClientDisconnect),
|
||||
/// Fires when this driver successully connects to a voice channel.
|
||||
DriverConnect,
|
||||
/// Fires when this driver successful reconnects after a network error.
|
||||
DriverReconnect,
|
||||
/// Fires when this driver fails to connect to a voice channel.
|
||||
DriverConnectFailed,
|
||||
/// Fires when this driver fails to reconnect to a voice channel after a network error.
|
||||
///
|
||||
/// Users will need to manually reconnect on receipt of this error.
|
||||
DriverReconnectFailed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -91,6 +101,10 @@ pub enum CoreContext {
|
||||
},
|
||||
ClientConnect(ClientConnect),
|
||||
ClientDisconnect(ClientDisconnect),
|
||||
DriverConnect,
|
||||
DriverReconnect,
|
||||
DriverConnectFailed,
|
||||
DriverReconnectFailed,
|
||||
}
|
||||
|
||||
impl<'a> CoreContext {
|
||||
@@ -125,6 +139,10 @@ impl<'a> CoreContext {
|
||||
},
|
||||
ClientConnect(evt) => EventContext::ClientConnect(*evt),
|
||||
ClientDisconnect(evt) => EventContext::ClientDisconnect(*evt),
|
||||
DriverConnect => EventContext::DriverConnect,
|
||||
DriverReconnect => EventContext::DriverReconnect,
|
||||
DriverConnectFailed => EventContext::DriverConnectFailed,
|
||||
DriverReconnectFailed => EventContext::DriverReconnectFailed,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,6 +160,10 @@ impl EventContext<'_> {
|
||||
RtcpPacket { .. } => Some(CoreEvent::RtcpPacket),
|
||||
ClientConnect { .. } => Some(CoreEvent::ClientConnect),
|
||||
ClientDisconnect { .. } => Some(CoreEvent::ClientDisconnect),
|
||||
DriverConnect => Some(CoreEvent::DriverConnect),
|
||||
DriverReconnect => Some(CoreEvent::DriverReconnect),
|
||||
DriverConnectFailed => Some(CoreEvent::DriverConnectFailed),
|
||||
DriverReconnectFailed => Some(CoreEvent::DriverReconnectFailed),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,14 @@ pub enum CoreEvent {
|
||||
ClientConnect,
|
||||
/// Fires whenever a user disconnects from the same stream as the bot.
|
||||
ClientDisconnect,
|
||||
/// Fires when this driver successully connects to a voice channel.
|
||||
DriverConnect,
|
||||
/// Fires when this driver successful reconnects after a network error.
|
||||
DriverReconnect,
|
||||
/// Fires when this driver fails to connect to a voice channel.
|
||||
DriverConnectFailed,
|
||||
/// Fires when this driver fails to reconnect to a voice channel after a network error.
|
||||
///
|
||||
/// Users will need to manually reconnect on receipt of this error.
|
||||
DriverReconnectFailed,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user