Skip to content

Commit

Permalink
Events: Add SsrcKnown event
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FelixMcFelix committed Feb 10, 2021
1 parent a40fac3 commit f3f5242
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/driver/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{
};
use crate::{
constants::*,
events::CoreContext,
model::{
payload::{Identify, Resume, SelectProtocol},
Event as GatewayEvent,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions src/events/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,25 @@ 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,
/// 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,
/// 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)]
Expand All @@ -105,6 +114,7 @@ pub enum CoreContext {
DriverReconnect,
DriverConnectFailed,
DriverReconnectFailed,
SsrcKnown(u32),
}

impl<'a> CoreContext {
Expand Down Expand Up @@ -143,6 +153,7 @@ impl<'a> CoreContext {
DriverReconnect => EventContext::DriverReconnect,
DriverConnectFailed => EventContext::DriverConnectFailed,
DriverReconnectFailed => EventContext::DriverReconnectFailed,
SsrcKnown(s) => EventContext::SsrcKnown(*s),
}
}
}
Expand All @@ -164,6 +175,7 @@ impl EventContext<'_> {
DriverReconnect => Some(CoreEvent::DriverReconnect),
DriverConnectFailed => Some(CoreEvent::DriverConnectFailed),
DriverReconnectFailed => Some(CoreEvent::DriverReconnectFailed),
SsrcKnown(_) => Some(CoreEvent::SsrcKnown),
_ => None,
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/events/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@ 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,
/// 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,
/// 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,
}

0 comments on commit f3f5242

Please sign in to comment.