diff --git a/src/driver/tasks/mod.rs b/src/driver/tasks/mod.rs index 838d501b2..f6e341185 100644 --- a/src/driver/tasks/mod.rs +++ b/src/driver/tasks/mod.rs @@ -12,6 +12,7 @@ use super::{ connection::{error::Error as ConnectionError, Connection}, Config, }; +use crate::events::CoreContext; use flume::{Receiver, RecvError, Sender}; use message::*; use tokio::runtime::Handle; @@ -75,12 +76,21 @@ async fn runner(mut config: Config, rx: Receiver, tx: Sender { // Other side may not be listening: this is fine. let _ = tx.send(Ok(())); + + let _ = interconnect + .events + .send(EventMessage::FireCoreEvent(CoreContext::DriverConnect)); + Some(connection) }, Err(why) => { // See above. let _ = tx.send(Err(why)); + let _ = interconnect.events.send(EventMessage::FireCoreEvent( + CoreContext::DriverConnectFailed, + )); + None }, }; @@ -145,10 +155,19 @@ async fn runner(mut config: Config, rx: Receiver, tx: Sender @@ -159,9 +178,18 @@ async fn runner(mut config: Config, rx: Receiver, tx: Sender { interconnect.restart_volatile_internals(); diff --git a/src/events/context.rs b/src/events/context.rs index 7b9809fc5..5e5798c32 100644 --- a/src/events/context.rs +++ b/src/events/context.rs @@ -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, } } diff --git a/src/events/core.rs b/src/events/core.rs index 27a559a8b..768577238 100644 --- a/src/events/core.rs +++ b/src/events/core.rs @@ -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, }