Skip to content

Commit

Permalink
Events: Deprecate ClientConnect (#112)
Browse files Browse the repository at this point in the history
Discord no longer send these websocket payloads, users should instead rely on the main part of their bot for determining actual connection events, or `SpeakingUpdate`s for SSRC mapping.

Closes #104.
  • Loading branch information
FelixMcFelix authored Feb 13, 2022
1 parent 2feadc7 commit c464fcc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
22 changes: 2 additions & 20 deletions examples/serenity/voice_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use serenity::{

use songbird::{
driver::DecodeMode,
model::payload::{ClientConnect, ClientDisconnect, Speaking},
model::payload::{ClientDisconnect, Speaking},
Config,
CoreEvent,
Event,
Expand Down Expand Up @@ -86,7 +86,7 @@ impl VoiceEventHandler for Receiver {
},
Ctx::SpeakingUpdate(data) => {
// You can implement logic here which reacts to a user starting
// or stopping speaking.
// or stopping speaking, and to map their SSRC to User ID.
println!(
"Source {} has {} speaking.",
data.ssrc,
Expand Down Expand Up @@ -114,19 +114,6 @@ impl VoiceEventHandler for Receiver {
// containing the call statistics and reporting information.
println!("RTCP packet received: {:?}", data.packet);
},
Ctx::ClientConnect(
ClientConnect {audio_ssrc, video_ssrc, user_id, ..}
) => {
// You can implement your own logic here to handle a user who has joined the
// voice channel e.g., allocate structures, map their SSRC to User ID.

println!(
"Client connected: user {:?} has audio SSRC {:?}, video SSRC {:?}",
user_id,
audio_ssrc,
video_ssrc,
);
},
Ctx::ClientDisconnect(
ClientDisconnect {user_id, ..}
) => {
Expand Down Expand Up @@ -224,11 +211,6 @@ async fn join(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
Receiver::new(),
);

handler.add_global_event(
CoreEvent::ClientConnect.into(),
Receiver::new(),
);

handler.add_global_event(
CoreEvent::ClientDisconnect.into(),
Receiver::new(),
Expand Down
17 changes: 15 additions & 2 deletions src/events/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,19 @@ pub enum EventContext<'a> {
VoicePacket(VoiceData<'a>),
/// Telemetry/statistics packet, received from another stream.
RtcpPacket(RtcpData<'a>),
/// Fired whenever a client connects to a call for the first time, allowing SSRC/UserID
/// matching.
#[deprecated(
since = "0.2.2",
note = "ClientConnect events are no longer sent by Discord. Please use SpeakingUpdate or Discord gateway events."
)]
/// Formerly fired whenever a client connects to a call for the first time, allowing SSRC/UserID
/// matching. This event no longer fires.
///
/// To detect when a user connects, you must correlate gateway (e.g., VoiceStateUpdate) events
/// from the main part of your bot.
///
/// To obtain a user's SSRC, you must use [`SpeakingUpdate`] events.
///
/// [`SpeakingUpdate`]: Self::SpeakingUpdate
ClientConnect(ClientConnect),
/// Fired whenever a client disconnects.
ClientDisconnect(ClientDisconnect),
Expand Down Expand Up @@ -114,6 +125,7 @@ impl<'a> CoreContext {
SpeakingUpdate(evt) => EventContext::SpeakingUpdate(SpeakingUpdateData::from(evt)),
VoicePacket(evt) => EventContext::VoicePacket(VoiceData::from(evt)),
RtcpPacket(evt) => EventContext::RtcpPacket(RtcpData::from(evt)),
#[allow(deprecated)]
ClientConnect(evt) => EventContext::ClientConnect(*evt),
ClientDisconnect(evt) => EventContext::ClientDisconnect(*evt),
DriverConnect(evt) => EventContext::DriverConnect(ConnectData::from(evt)),
Expand All @@ -140,6 +152,7 @@ impl EventContext<'_> {
SpeakingUpdate(_) => Some(CoreEvent::SpeakingUpdate),
VoicePacket(_) => Some(CoreEvent::VoicePacket),
RtcpPacket(_) => Some(CoreEvent::RtcpPacket),
#[allow(deprecated)]
ClientConnect(_) => Some(CoreEvent::ClientConnect),
ClientDisconnect(_) => Some(CoreEvent::ClientDisconnect),
DriverConnect(_) => Some(CoreEvent::DriverConnect),
Expand Down
14 changes: 13 additions & 1 deletion src/events/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@ pub enum CoreEvent {
/// Fires on receipt of an RTCP packet, containing various call stats
/// such as latency reports.
RtcpPacket,
/// Fires whenever a user connects to the same stream as the bot.
#[deprecated(
since = "0.2.2",
note = "ClientConnect events are no longer sent by Discord. Please use SpeakingUpdate or Discord gateway events."
)]
/// Formerly fired whenever a client connects to a call for the first time, allowing SSRC/UserID
/// matching. This event no longer fires.
///
/// To detect when a user connects, you must correlate gateway (e.g., VoiceStateUpdate) events
/// from the main part of your bot.
///
/// To obtain a user's SSRC, you must use [`SpeakingUpdate`] events.
///
/// [`SpeakingUpdate`]: Self::SpeakingUpdate
ClientConnect,
/// Fires whenever a user disconnects from the same stream as the bot.
ClientDisconnect,
Expand Down

0 comments on commit c464fcc

Please sign in to comment.