Interface IPacketProvider
@NotThreadSafe
public interface IPacketProvider
Represents the connection between a
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 unused) Used to retrieve an audio packet to send to Discord.getNextPacketRaw
(boolean unused) 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.The
Buffer.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.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.- 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.Note: When the AudioSendHandler cannot or does not provide a new packet to send, this method will return null.
- 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
.
-