diff --git a/src/driver/connection/mod.rs b/src/driver/connection/mod.rs index 3f33a1650..1c8979798 100644 --- a/src/driver/connection/mod.rs +++ b/src/driver/connection/mod.rs @@ -7,6 +7,7 @@ use super::{ }; use crate::{ constants::*, + events::CoreContext, model::{ payload::{Identify, Resume, SelectProtocol}, Event as GatewayEvent, @@ -195,6 +196,10 @@ impl Connection { .mixer .send(MixerMessage::SetConn(mix_conn, ready.ssrc))?; + let _ = interconnect + .events + .send(EventMessage::FireCoreEvent(CoreContext::SsrcKnown(ssrc))); + spawn(ws_task::runner( interconnect.clone(), ws_msg_rx, diff --git a/src/events/context.rs b/src/events/context.rs index 5e5798c32..160a6f605 100644 --- a/src/events/context.rs +++ b/src/events/context.rs @@ -69,9 +69,9 @@ pub enum EventContext<'a> { ClientConnect(ClientConnect), /// Fired whenever a client disconnects. ClientDisconnect(ClientDisconnect), - /// Fires when this driver successully connects to a voice channel. + /// Fires when this driver successfully connects to a voice channel. DriverConnect, - /// Fires when this driver successful reconnects after a network error. + /// Fires when this driver successfully reconnects after a network error. DriverReconnect, /// Fires when this driver fails to connect to a voice channel. DriverConnectFailed, @@ -79,6 +79,15 @@ pub enum EventContext<'a> { /// /// Users will need to manually reconnect on receipt of this error. DriverReconnectFailed, + /// Fires whenever the driver is assigned a new [RTP SSRC] by the voice server. + /// + /// This typically fires alongside a [DriverConnect], or a full [DriverReconnect]. + /// + /// [RTP SSRC]: https://tools.ietf.org/html/rfc3550#section-3 + /// [DriverConnect]: Self::DriverConnect + /// [DriverReconnect]: Self::DriverReconnect + // TODO: move assigned SSRC into payload of Driver(Re)Connect as part of next breaking, and deprecate this. + SsrcKnown(u32), } #[derive(Clone, Debug)] @@ -105,6 +114,7 @@ pub enum CoreContext { DriverReconnect, DriverConnectFailed, DriverReconnectFailed, + SsrcKnown(u32), } impl<'a> CoreContext { @@ -143,6 +153,7 @@ impl<'a> CoreContext { DriverReconnect => EventContext::DriverReconnect, DriverConnectFailed => EventContext::DriverConnectFailed, DriverReconnectFailed => EventContext::DriverReconnectFailed, + SsrcKnown(s) => EventContext::SsrcKnown(*s), } } } @@ -164,6 +175,7 @@ impl EventContext<'_> { DriverReconnect => Some(CoreEvent::DriverReconnect), DriverConnectFailed => Some(CoreEvent::DriverConnectFailed), DriverReconnectFailed => Some(CoreEvent::DriverReconnectFailed), + SsrcKnown(_) => Some(CoreEvent::SsrcKnown), _ => None, } } diff --git a/src/events/core.rs b/src/events/core.rs index 768577238..218182cfb 100644 --- a/src/events/core.rs +++ b/src/events/core.rs @@ -29,9 +29,9 @@ 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. + /// Fires when this driver successfully connects to a voice channel. DriverConnect, - /// Fires when this driver successful reconnects after a network error. + /// Fires when this driver successfully reconnects after a network error. DriverReconnect, /// Fires when this driver fails to connect to a voice channel. DriverConnectFailed, @@ -39,4 +39,13 @@ pub enum CoreEvent { /// /// Users will need to manually reconnect on receipt of this error. DriverReconnectFailed, + /// Fires whenever the driver is assigned a new [RTP SSRC] by the voice server. + /// + /// This typically fires alongside a [DriverConnect], or a full [DriverReconnect]. + /// + /// [RTP SSRC]: https://tools.ietf.org/html/rfc3550#section-3 + /// [DriverConnect]: Self::DriverConnect + /// [DriverReconnect]: Self::DriverReconnect + // TODO: deprecate in next breaking after fusing with Driver(Re)Connect. + SsrcKnown, }