Events: Deprecate ClientConnect (#112)
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.
This commit is contained in:
@@ -29,7 +29,7 @@ use serenity::{
|
|||||||
|
|
||||||
use songbird::{
|
use songbird::{
|
||||||
driver::DecodeMode,
|
driver::DecodeMode,
|
||||||
model::payload::{ClientConnect, ClientDisconnect, Speaking},
|
model::payload::{ClientDisconnect, Speaking},
|
||||||
Config,
|
Config,
|
||||||
CoreEvent,
|
CoreEvent,
|
||||||
Event,
|
Event,
|
||||||
@@ -86,7 +86,7 @@ impl VoiceEventHandler for Receiver {
|
|||||||
},
|
},
|
||||||
Ctx::SpeakingUpdate(data) => {
|
Ctx::SpeakingUpdate(data) => {
|
||||||
// You can implement logic here which reacts to a user starting
|
// 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!(
|
println!(
|
||||||
"Source {} has {} speaking.",
|
"Source {} has {} speaking.",
|
||||||
data.ssrc,
|
data.ssrc,
|
||||||
@@ -114,19 +114,6 @@ impl VoiceEventHandler for Receiver {
|
|||||||
// containing the call statistics and reporting information.
|
// containing the call statistics and reporting information.
|
||||||
println!("RTCP packet received: {:?}", data.packet);
|
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(
|
Ctx::ClientDisconnect(
|
||||||
ClientDisconnect {user_id, ..}
|
ClientDisconnect {user_id, ..}
|
||||||
) => {
|
) => {
|
||||||
@@ -224,11 +211,6 @@ async fn join(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
|||||||
Receiver::new(),
|
Receiver::new(),
|
||||||
);
|
);
|
||||||
|
|
||||||
handler.add_global_event(
|
|
||||||
CoreEvent::ClientConnect.into(),
|
|
||||||
Receiver::new(),
|
|
||||||
);
|
|
||||||
|
|
||||||
handler.add_global_event(
|
handler.add_global_event(
|
||||||
CoreEvent::ClientDisconnect.into(),
|
CoreEvent::ClientDisconnect.into(),
|
||||||
Receiver::new(),
|
Receiver::new(),
|
||||||
|
|||||||
@@ -38,8 +38,19 @@ pub enum EventContext<'a> {
|
|||||||
VoicePacket(VoiceData<'a>),
|
VoicePacket(VoiceData<'a>),
|
||||||
/// Telemetry/statistics packet, received from another stream.
|
/// Telemetry/statistics packet, received from another stream.
|
||||||
RtcpPacket(RtcpData<'a>),
|
RtcpPacket(RtcpData<'a>),
|
||||||
/// Fired whenever a client connects to a call for the first time, allowing SSRC/UserID
|
#[deprecated(
|
||||||
/// matching.
|
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),
|
ClientConnect(ClientConnect),
|
||||||
/// Fired whenever a client disconnects.
|
/// Fired whenever a client disconnects.
|
||||||
ClientDisconnect(ClientDisconnect),
|
ClientDisconnect(ClientDisconnect),
|
||||||
@@ -114,6 +125,7 @@ impl<'a> CoreContext {
|
|||||||
SpeakingUpdate(evt) => EventContext::SpeakingUpdate(SpeakingUpdateData::from(evt)),
|
SpeakingUpdate(evt) => EventContext::SpeakingUpdate(SpeakingUpdateData::from(evt)),
|
||||||
VoicePacket(evt) => EventContext::VoicePacket(VoiceData::from(evt)),
|
VoicePacket(evt) => EventContext::VoicePacket(VoiceData::from(evt)),
|
||||||
RtcpPacket(evt) => EventContext::RtcpPacket(RtcpData::from(evt)),
|
RtcpPacket(evt) => EventContext::RtcpPacket(RtcpData::from(evt)),
|
||||||
|
#[allow(deprecated)]
|
||||||
ClientConnect(evt) => EventContext::ClientConnect(*evt),
|
ClientConnect(evt) => EventContext::ClientConnect(*evt),
|
||||||
ClientDisconnect(evt) => EventContext::ClientDisconnect(*evt),
|
ClientDisconnect(evt) => EventContext::ClientDisconnect(*evt),
|
||||||
DriverConnect(evt) => EventContext::DriverConnect(ConnectData::from(evt)),
|
DriverConnect(evt) => EventContext::DriverConnect(ConnectData::from(evt)),
|
||||||
@@ -140,6 +152,7 @@ impl EventContext<'_> {
|
|||||||
SpeakingUpdate(_) => Some(CoreEvent::SpeakingUpdate),
|
SpeakingUpdate(_) => Some(CoreEvent::SpeakingUpdate),
|
||||||
VoicePacket(_) => Some(CoreEvent::VoicePacket),
|
VoicePacket(_) => Some(CoreEvent::VoicePacket),
|
||||||
RtcpPacket(_) => Some(CoreEvent::RtcpPacket),
|
RtcpPacket(_) => Some(CoreEvent::RtcpPacket),
|
||||||
|
#[allow(deprecated)]
|
||||||
ClientConnect(_) => Some(CoreEvent::ClientConnect),
|
ClientConnect(_) => Some(CoreEvent::ClientConnect),
|
||||||
ClientDisconnect(_) => Some(CoreEvent::ClientDisconnect),
|
ClientDisconnect(_) => Some(CoreEvent::ClientDisconnect),
|
||||||
DriverConnect(_) => Some(CoreEvent::DriverConnect),
|
DriverConnect(_) => Some(CoreEvent::DriverConnect),
|
||||||
|
|||||||
@@ -25,7 +25,19 @@ pub enum CoreEvent {
|
|||||||
/// Fires on receipt of an RTCP packet, containing various call stats
|
/// Fires on receipt of an RTCP packet, containing various call stats
|
||||||
/// such as latency reports.
|
/// such as latency reports.
|
||||||
RtcpPacket,
|
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,
|
ClientConnect,
|
||||||
/// Fires whenever a user disconnects from the same stream as the bot.
|
/// Fires whenever a user disconnects from the same stream as the bot.
|
||||||
ClientDisconnect,
|
ClientDisconnect,
|
||||||
|
|||||||
Reference in New Issue
Block a user