Interface IPacketProvider
IAudioSendSystem
and
JDA's internal audio system, providing access to audio packets built from data provided from
AudioSendHandlers
.
Note that this provider is not thread-safe!
-
Method Summary
Modifier and TypeMethodDescriptionProvides the current channel that this connection is transmitting to.Provides a unique String identifier for the connection.getNextPacket
(boolean changeTalking) Used to retrieve an audio packet to send to Discord.getNextPacketRaw
(boolean changeTalking) Used to retrieve an audio packet to send to Discord.The connected socket address for this audio connection.The UDP connection for this audio connection.void
onConnectionError
(ConnectionStatus status) This method is used to indicate a connection error to JDA so that the connection can be properly shutdown.void
This method is used to indicate to JDA that the UDP connection has been lost, whether that be due internet loss or some other unknown reason.
-
Method Details
-
getIdentifier
Provides a unique String identifier for the connection.
Uses shard information and specific audio connection information to build string.- Returns:
- Never-null String unique to this audio connection.
-
getConnectedChannel
Provides the current channel that this connection is transmitting to.- Returns:
- The
AudioChannel
that this connection is sending to.
-
getUdpSocket
The UDP connection for this audio connection. TheDefaultSendSystem
uses this socket to send audio packets to discord, and this is also the socket used to receive audio packets from discord.
If you are implementing your own system, it is recommended that you used this connection as it is part of JDA's internal system that JDA monitors for errors and closures. It should be noted however that using this is not required to send audio packets if the developer wishes to open their own UDP socket to send from.- Returns:
- The UDP socket connection used for audio sending.
-
getSocketAddress
The connected socket address for this audio connection. This can be useful for developers to open their own socket for datagram sending and allows to avoid usinggetNextPacket(boolean)
.- Returns:
InetSocketAddress
of the current UDP connection
-
getNextPacketRaw
Used to retrieve an audio packet to send to Discord. The packet provided is already converted to Opus and encrypted, and as such is completely ready to be sent to Discord. ThechangeTalking
parameter is used to control whether or not the talking indicator should be changed if theAudioSendHandler
cannot provide an audio packet.
TheBuffer.position()
will be positioned on the start of the packet to send and theBuffer.limit()
at the end of it. UseBuffer.remaining()
to check the length of the packet.Use case for this parameter would be front-loading or queuing many audio packets ahead of send time, and if the AudioSendHandler did not have enough to fill the entire queue, you would have
changeTalking
set tofalse
until the queue was empty. At that point, you would switch totrue
when requesting a new packet due to the fact that if one was not available, the developer would not have a packet to send, thus the logged in account is no longer "talking".Note: When the AudioSendHandler cannot or does not provide a new packet to send, this method will return null.
The buffer used here may be used again on the next call to this getter, if you plan on storing the data copy it. The buffer was created using
ByteBuffer.allocate(int)
and is not direct.- Parameters:
changeTalking
- Whether or not to change the talking indicator if the AudioSendHandler cannot provide a new audio packet.- Returns:
- Possibly-null
ByteBuffer
containing an encoded and encrypted packet of audio data ready to be sent to discord.
-
getNextPacket
Used to retrieve an audio packet to send to Discord. The packet provided is already converted to Opus and encrypted, and as such is completely ready to be sent to Discord. ThechangeTalking
parameter is used to control whether or not the talking indicator should be changed if theAudioSendHandler
cannot provide an audio packet.Use case for this parameter would be front-loading or queuing many audio packets ahead of send time, and if the AudioSendHandler did not have enough to fill the entire queue, you would have
changeTalking
set tofalse
until the queue was empty. At that point, you would switch totrue
when requesting a new packet due to the fact that if one was not available, the developer would not have a packet to send, thus the logged in account is no longer "talking".Note: When the AudioSendHandler cannot or does not provide a new packet to send, this method will return null.
- Parameters:
changeTalking
- Whether or not to change the talking indicator if the AudioSendHandler cannot provide a new audio packet.- Returns:
- Possibly-null
DatagramPacket
containing an encoded and encrypted packet of audio data ready to be sent to discord.
-
onConnectionError
This method is used to indicate a connection error to JDA so that the connection can be properly shutdown.
This is useful if, during setup or operation, an unrecoverable error is encountered.- Parameters:
status
- TheConnectionStatus
being reported to JDA indicating an error with connection.
-
onConnectionLost
void onConnectionLost()This method is used to indicate to JDA that the UDP connection has been lost, whether that be due internet loss or some other unknown reason. This is similar toonConnectionError(net.dv8tion.jda.api.audio.hooks.ConnectionStatus)
as it provides a default error reason ofConnectionStatus.ERROR_LOST_CONNECTION
.
-