Package org.javacord.core.audio
Class AudioConnectionImpl
- java.lang.Object
-
- org.javacord.core.audio.AudioConnectionImpl
-
- All Implemented Interfaces:
AudioConnection
,AudioConnectionAttachableListenerManager
,InternalAudioConnectionAttachableListenerManager
public class AudioConnectionImpl extends java.lang.Object implements AudioConnection, InternalAudioConnectionAttachableListenerManager
-
-
Constructor Summary
Constructors Constructor Description AudioConnectionImpl(ServerVoiceChannel channel, java.util.concurrent.CompletableFuture<AudioConnection> readyFuture, boolean muted, boolean deafened)
Creates a new audio connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Void>
close()
DiscordApi
getApi()
Gets the discord api instance.java.util.Optional<AudioSource>
getAudioSource()
ServerVoiceChannel
getChannel()
AudioSource
getCurrentAudioSourceBlocking()
Gets the current audio source, blocking the thread until it is available.AudioSource
getCurrentAudioSourceBlocking(long timeout, java.util.concurrent.TimeUnit unit)
Gets the current audio source, waiting up to the specified wait time if necessary for an audio source to become available.java.util.concurrent.CompletableFuture<java.lang.Void>
getDisconnectFuture()
Gets a future that finishes once the connection has been disconnected.java.lang.String
getEndpoint()
Gets the endpoint for the audio websocket.long
getId()
Gets the id of this object.java.util.concurrent.CompletableFuture<AudioConnection>
getReadyFuture()
Gets a future that finishes once the connection is fully established.java.lang.String
getSessionId()
Gets the session id of the audio connection.java.util.Set<SpeakingFlag>
getSpeakingFlags()
Gets the current set of active speaking flags.java.lang.String
getToken()
Gets the token for the audio connection.boolean
isPrioritySpeaking()
Gets whether the connection is currently speaking with priority.boolean
isSelfDeafened()
boolean
isSelfMuted()
java.util.concurrent.CompletableFuture<java.lang.Void>
moveTo(ServerVoiceChannel destChannel)
java.util.concurrent.CompletableFuture<java.lang.Void>
moveTo(ServerVoiceChannel destChannel, boolean selfMute, boolean selfDeafen)
void
reconnect()
Performs a full reconnect of the audio connection by sending a new voice state update.void
removeAudioSource()
void
setAudioSource(AudioSource source)
void
setChannel(ServerVoiceChannel channel)
Sets the channel of the connection.void
setEndpoint(java.lang.String endpoint)
Sets the endpoint for the audio websocket.void
setPrioritySpeaking(boolean prioritySpeaking)
Sets whether the connection is priority speaking.void
setSelfDeafened(boolean deafened)
void
setSelfMuted(boolean muted)
void
setSessionId(java.lang.String sessionId)
Sets the session id of the connection.void
setSpeaking(boolean speaking)
Sets the current speaking mode.void
setSpeakingFlags(java.util.EnumSet<SpeakingFlag> speakingFlags)
Sets the current speaking flags and sends a speaking packet if they have changed.void
setToken(java.lang.String token)
Sets the token for the audio connection.java.lang.String
toString()
boolean
tryConnect()
Tries to establish a connection if all required information is available and there's not already a connection.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.javacord.api.audio.AudioConnection
getServer
-
Methods inherited from interface org.javacord.core.listener.audio.InternalAudioConnectionAttachableListenerManager
addAudioConnectionAttachableListener, addAudioSourceFinishedListener, getAudioConnectionAttachableListeners, getAudioSourceFinishedListeners, removeAudioConnectionAttachableListener, removeListener
-
-
-
-
Constructor Detail
-
AudioConnectionImpl
public AudioConnectionImpl(ServerVoiceChannel channel, java.util.concurrent.CompletableFuture<AudioConnection> readyFuture, boolean muted, boolean deafened)
Creates a new audio connection.- Parameters:
channel
- The channel of the audio connection.readyFuture
- An uncompleted future that gets completed when the connection is fully established.muted
- Whether to connect self-muted.deafened
- Whether to connect self-deafened.
-
-
Method Detail
-
getReadyFuture
public java.util.concurrent.CompletableFuture<AudioConnection> getReadyFuture()
Gets a future that finishes once the connection is fully established.- Returns:
- The future.
-
getDisconnectFuture
public java.util.concurrent.CompletableFuture<java.lang.Void> getDisconnectFuture()
Gets a future that finishes once the connection has been disconnected.- Returns:
- The future.
-
getSessionId
public java.lang.String getSessionId()
Gets the session id of the audio connection.- Returns:
- The session id of the audio connection.
-
getToken
public java.lang.String getToken()
Gets the token for the audio connection.- Returns:
- The token for the audio connection.
-
getEndpoint
public java.lang.String getEndpoint()
Gets the endpoint for the audio websocket.- Returns:
- The endpoint for the audio websocket.
-
setChannel
public void setChannel(ServerVoiceChannel channel)
Sets the channel of the connection.- Parameters:
channel
- The channel of the connection.
-
setSessionId
public void setSessionId(java.lang.String sessionId)
Sets the session id of the connection.- Parameters:
sessionId
- The session id of the connection.
-
setToken
public void setToken(java.lang.String token)
Sets the token for the audio connection.- Parameters:
token
- The token for the audio connection.
-
setEndpoint
public void setEndpoint(java.lang.String endpoint)
Sets the endpoint for the audio websocket.- Parameters:
endpoint
- The endpoint for the audio websocket.
-
setSpeaking
public void setSpeaking(boolean speaking)
Sets the current speaking mode.- Parameters:
speaking
- The speaking mode to set
-
isPrioritySpeaking
public boolean isPrioritySpeaking()
Gets whether the connection is currently speaking with priority.- Specified by:
isPrioritySpeaking
in interfaceAudioConnection
- Returns:
- Whether the connection is currently speaking with priority.
-
setPrioritySpeaking
public void setPrioritySpeaking(boolean prioritySpeaking)
Sets whether the connection is priority speaking.- Specified by:
setPrioritySpeaking
in interfaceAudioConnection
- Parameters:
prioritySpeaking
- Whether to speak with priority.
-
getSpeakingFlags
public java.util.Set<SpeakingFlag> getSpeakingFlags()
Gets the current set of active speaking flags.- Specified by:
getSpeakingFlags
in interfaceAudioConnection
- Returns:
- The current set of active speaking flags.
-
setSpeakingFlags
public void setSpeakingFlags(java.util.EnumSet<SpeakingFlag> speakingFlags)
Sets the current speaking flags and sends a speaking packet if they have changed.- Parameters:
speakingFlags
- The new speaking flags to set.
-
tryConnect
public boolean tryConnect()
Tries to establish a connection if all required information is available and there's not already a connection.- Returns:
- Whether it will try to connect or not.
-
reconnect
public void reconnect()
Performs a full reconnect of the audio connection by sending a new voice state update.
-
getCurrentAudioSourceBlocking
public AudioSource getCurrentAudioSourceBlocking() throws java.lang.InterruptedException
Gets the current audio source, blocking the thread until it is available.- Returns:
- The current audio source.
- Throws:
java.lang.InterruptedException
- If interrupted while waiting.
-
getCurrentAudioSourceBlocking
public AudioSource getCurrentAudioSourceBlocking(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Gets the current audio source, waiting up to the specified wait time if necessary for an audio source to become available.- Parameters:
timeout
- How long to wait before giving up.unit
- ATimeUnit
determining how to interpret thetimeout
parameter.- Returns:
- The current audio source, or
null
if the specified waiting time elapsed. - Throws:
java.lang.InterruptedException
- If interrupted while waiting.
-
getApi
public DiscordApi getApi()
Description copied from interface:InternalAudioConnectionAttachableListenerManager
Gets the discord api instance.- Specified by:
getApi
in interfaceInternalAudioConnectionAttachableListenerManager
- Returns:
- The discord api instance.
-
getId
public long getId()
Description copied from interface:InternalAudioConnectionAttachableListenerManager
Gets the id of this object.- Specified by:
getId
in interfaceInternalAudioConnectionAttachableListenerManager
- Returns:
- The id of this object.
-
moveTo
public java.util.concurrent.CompletableFuture<java.lang.Void> moveTo(ServerVoiceChannel destChannel)
- Specified by:
moveTo
in interfaceAudioConnection
-
moveTo
public java.util.concurrent.CompletableFuture<java.lang.Void> moveTo(ServerVoiceChannel destChannel, boolean selfMute, boolean selfDeafen)
- Specified by:
moveTo
in interfaceAudioConnection
-
close
public java.util.concurrent.CompletableFuture<java.lang.Void> close()
- Specified by:
close
in interfaceAudioConnection
-
getAudioSource
public java.util.Optional<AudioSource> getAudioSource()
- Specified by:
getAudioSource
in interfaceAudioConnection
-
setAudioSource
public void setAudioSource(AudioSource source)
- Specified by:
setAudioSource
in interfaceAudioConnection
-
removeAudioSource
public void removeAudioSource()
- Specified by:
removeAudioSource
in interfaceAudioConnection
-
getChannel
public ServerVoiceChannel getChannel()
- Specified by:
getChannel
in interfaceAudioConnection
-
isSelfMuted
public boolean isSelfMuted()
- Specified by:
isSelfMuted
in interfaceAudioConnection
-
setSelfMuted
public void setSelfMuted(boolean muted)
- Specified by:
setSelfMuted
in interfaceAudioConnection
-
isSelfDeafened
public boolean isSelfDeafened()
- Specified by:
isSelfDeafened
in interfaceAudioConnection
-
setSelfDeafened
public void setSelfDeafened(boolean deafened)
- Specified by:
setSelfDeafened
in interfaceAudioConnection
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-