Events: Add SsrcKnown event

Knowing your own SSRC is useful for handling RTCP packets, which may detail information about *ourselves* rather than another host. In theory, at least: this confirms that Discord just sends ReceiverReports containing your own packet stats.

This would have been better to fit into Driver(Re)Connect, but that would be a breaking change: when this change is made, `SsrcKnown` shall be deprecated.
This commit is contained in:
Kyle Simpson
2021-02-10 14:33:34 +00:00
parent a40fac3109
commit f3f52427ea
3 changed files with 30 additions and 4 deletions

View File

@@ -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,
}
}

View File

@@ -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,
}