Interface ConnectionListener
- All Known Implementing Classes:
ListenerProxy
This provides functionality similar to the functionalities present in the Discord client related to an audio connection.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
onPing
(long ping) Called when JDA send a heartbeat packet to Discord and Discord sends an acknowledgement.void
onStatusChange
(ConnectionStatus status) Called when the status of the audio channel changes.default void
onUserSpeaking
(User user, boolean speaking) Deprecated.This method no longer represents the actual speaking state of the user.default void
onUserSpeaking
(User user, boolean speaking, boolean soundshare) Deprecated.This method no longer represents the actual speaking state of the user.default void
onUserSpeaking
(User user, EnumSet<SpeakingMode> modes) Deprecated.This method no longer represents the actual speaking state of the user.default void
onUserSpeakingModeUpdate
(User user, EnumSet<SpeakingMode> modes) This method is used to listen for users changing their speaking mode.default void
onUserSpeakingModeUpdate
(UserSnowflake user, EnumSet<SpeakingMode> modes) This method is used to listen for users changing their speaking mode.
-
Method Details
-
onPing
void onPing(long ping) Called when JDA send a heartbeat packet to Discord and Discord sends an acknowledgement. The time difference between sending and receiving the acknowledgement is calculated as the ping.- Parameters:
ping
- The time, in milliseconds, for round-trip packet travel to discord.
-
onStatusChange
Called when the status of the audio channel changes. Used to track the connection state of the audio connection for easy debug and status display for clients.- Parameters:
status
- The newConnectionStatus
of the audio connection.
-
onUserSpeaking
@Deprecated @ForRemoval @ReplaceWith("onUserSpeakingModeUpdate(User, EnumSet<SpeakingMode>)") default void onUserSpeaking(@Nonnull User user, boolean speaking) Deprecated.This method no longer represents the actual speaking state of the user. Discord does not send updates when a user starts and stops speaking anymore. You can useonUserSpeakingModeUpdate(UserSnowflake, EnumSet)
to see when a user changes their speaking mode, or use anAudioReceiveHandler
to check when a user is speaking.This method is an easy way to detect if a user is talking. Discord sends us an event when a user starts or stops talking and it is parallel to the audio socket, so this event could come milliseconds before or after audio begins or stops. This method is brilliant for clients wanting to display that a user is currently talking.Unlike the
AudioReceiveHandler.handleCombinedAudio(CombinedAudio)
andAudioReceiveHandler.handleUserAudio(UserAudio)
methods which are fired extremely often, this method is fired as a flag for the beginning and ending of audio transmission, and as such is only fired when that changes. So while theAudioReceiveHandler.handleUserAudio(UserAudio)
method is fired every time JDA receives audio data from Discord, this is only fired when that stream starts and when it stops.
If the user speaks for 3 minutes straight without ever stopping, then this would fire 2 times, once at the beginning and once after 3 minutes when they stop talking even though theAudioReceiveHandler.handleUserAudio(UserAudio)
method was fired thousands of times over the course of the 3 minutes.- Parameters:
user
- Never-nullUser
who's talking status has changed.speaking
- If true, the user has begun transmitting audio.
-
onUserSpeaking
@Deprecated @ForRemoval @ReplaceWith("onUserSpeakingModeUpdate(User, EnumSet<SpeakingMode>)") default void onUserSpeaking(@Nonnull User user, @Nonnull EnumSet<SpeakingMode> modes) Deprecated.This method no longer represents the actual speaking state of the user. Discord does not send updates when a user starts and stops speaking anymore. You can useonUserSpeakingModeUpdate(UserSnowflake, EnumSet)
to see when a user changes their speaking mode, or use anAudioReceiveHandler
to check when a user is speaking.This method is an easy way to detect if a user is talking. Discord sends us an event when a user starts or stops talking and it is parallel to the audio socket, so this event could come milliseconds before or after audio begins or stops. This method is brilliant for clients wanting to display that a user is currently talking.Unlike the
AudioReceiveHandler.handleCombinedAudio(CombinedAudio)
andAudioReceiveHandler.handleUserAudio(UserAudio)
methods which are fired extremely often, this method is fired as a flag for the beginning and ending of audio transmission, and as such is only fired when that changes. So while theAudioReceiveHandler.handleUserAudio(UserAudio)
method is fired every time JDA receives audio data from Discord, this is only fired when that stream starts and when it stops.
If the user speaks for 3 minutes straight without ever stopping, then this would fire 2 times, once at the beginning and once after 3 minutes when they stop talking even though theAudioReceiveHandler.handleUserAudio(UserAudio)
method was fired thousands of times over the course of the 3 minutes.- Parameters:
user
- Never-nullUser
who's talking status has changed.modes
- EnumSet, containing the active speaking modes. Empty if the user has stopped transmitting audio.- See Also:
-
onUserSpeaking
@Deprecated @ForRemoval @ReplaceWith("onUserSpeakingModeUpdate(User, EnumSet<SpeakingMode>)") default void onUserSpeaking(@Nonnull User user, boolean speaking, boolean soundshare) Deprecated.This method no longer represents the actual speaking state of the user. Discord does not send updates when a user starts and stops speaking anymore. You can useonUserSpeakingModeUpdate(UserSnowflake, EnumSet)
to see when a user changes their speaking mode, or use anAudioReceiveHandler
to check when a user is speaking.This method is an easy way to detect if a user is talking. Discord sends us an event when a user starts or stops talking and it is parallel to the audio socket, so this event could come milliseconds before or after audio begins or stops. This method is brilliant for clients wanting to display that a user is currently talking.Unlike the
AudioReceiveHandler.handleCombinedAudio(CombinedAudio)
andAudioReceiveHandler.handleUserAudio(UserAudio)
methods which are fired extremely often, this method is fired as a flag for the beginning and ending of audio transmission, and as such is only fired when that changes. So while theAudioReceiveHandler.handleUserAudio(UserAudio)
method is fired every time JDA receives audio data from Discord, this is only fired when that stream starts and when it stops.
If the user speaks for 3 minutes straight without ever stopping, then this would fire 2 times, once at the beginning and once after 3 minutes when they stop talking even though theAudioReceiveHandler.handleUserAudio(UserAudio)
method was fired thousands of times over the course of the 3 minutes.- Parameters:
user
- Never-nullUser
who's talking status has changed.speaking
- If true, the user has begun transmitting audio.soundshare
- If true, the user is using soundshare
-
onUserSpeakingModeUpdate
This method is used to listen for users changing their speaking mode.Whenever a user joins a voice channel, this is fired once to define the initial speaking modes.
To detect when a user is speaking, a
AudioReceiveHandler
should be used instead.Note: This requires the user to be currently in the cache. You can use
MemberCachePolicy.VOICE
to cache currently connected users. Alternatively, useonUserSpeakingModeUpdate(UserSnowflake, EnumSet)
to avoid cache.- Parameters:
user
- The user who changed their speaking modemodes
- The new speaking modes of the user
-
onUserSpeakingModeUpdate
default void onUserSpeakingModeUpdate(@Nonnull UserSnowflake user, @Nonnull EnumSet<SpeakingMode> modes) This method is used to listen for users changing their speaking mode.Whenever a user joins a voice channel, this is fired once to define the initial speaking modes.
To detect when a user is speaking, a
AudioReceiveHandler
should be used instead.This method works independently of the user cache. The provided user might not be cached.
- Parameters:
user
- The user who changed their speaking modemodes
- The new speaking modes of the user
-