Class ListenerProxy
- java.lang.Object
-
- net.dv8tion.jda.api.audio.hooks.ListenerProxy
-
- All Implemented Interfaces:
ConnectionListener
public class ListenerProxy extends Object implements ConnectionListener
-
-
Constructor Summary
Constructors Constructor Description ListenerProxy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConnectionListener
getListener()
void
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.void
onUserSpeaking(User user, boolean speaking)
This method is an easy way to detect if a user is talking.void
onUserSpeaking(User user, EnumSet<SpeakingMode> modes)
This method is an easy way to detect if a user is talking.void
setListener(ConnectionListener listener)
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.dv8tion.jda.api.audio.hooks.ConnectionListener
onUserSpeaking
-
-
-
-
Method Detail
-
onPing
public void onPing(long ping)
Description copied from interface:ConnectionListener
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.- Specified by:
onPing
in interfaceConnectionListener
- Parameters:
ping
- The time, in milliseconds, for round-trip packet travel to discord.
-
onStatusChange
public void onStatusChange(@Nonnull ConnectionStatus status)
Description copied from interface:ConnectionListener
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.- Specified by:
onStatusChange
in interfaceConnectionListener
- Parameters:
status
- The newConnectionStatus
of the audio connection.
-
onUserSpeaking
public void onUserSpeaking(@Nonnull User user, @Nonnull EnumSet<SpeakingMode> modes)
Description copied from interface:ConnectionListener
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.- Specified by:
onUserSpeaking
in interfaceConnectionListener
- 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:
EnumSet
,SpeakingMode
-
onUserSpeaking
public void onUserSpeaking(@Nonnull User user, boolean speaking)
Description copied from interface:ConnectionListener
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.- Specified by:
onUserSpeaking
in interfaceConnectionListener
- Parameters:
user
- Never-nullUser
who's talking status has changed.speaking
- If true, the user has begun transmitting audio.
-
setListener
public void setListener(ConnectionListener listener)
-
getListener
public ConnectionListener getListener()
-
-