VoicePacket
in package
A voice packet received from Discord.
Huge thanks to Austin and Michael from JDA for the constants and audio packets. Check out their repo: https://github.com/discord-jda/JDA
Tags
Table of Contents
Constants
- AUTH_TAG_LENGTH = 16
- RTP_HEADER_BYTE_LENGTH = 12
- RTP_PAYLOAD_INDEX = 1
- RTP_PAYLOAD_TYPE = 0x78
- This is Discord's RTP Profile Payload type, which is the same as Opus audio RTP stream's default payload type of 120 (0x78 & 0x7F).
- RTP_VERSION_PAD_EXTEND = 0x80
- Bit index 0 and 1 represent the RTP Protocol version used. Discord uses the latest RTP protocol version, 2.
- RTP_VERSION_PAD_EXTEND_INDEX = 0
- SEQ_INDEX = 2
- SSRC_INDEX = 8
- TIMESTAMP_INDEX = 4
Properties
- $buffer : Buffer
- The voice packet buffer.
- $seq : int
- The packet sequence.
- $ssrc : int
- The client SSRC.
- $timestamp : float
- The packet timestamp.
Methods
- __construct() : mixed
- Constructs the voice packet.
- __toString() : string
- Handles to string casting of object.
- getData() : string
- Returns the data.
- getHeader() : string
- Returns the header.
- getSequence() : int
- Returns the sequence.
- getSSRC() : int
- Returns the SSRC.
- getTimestamp() : float
- Returns the timestamp.
- make() : VoicePacket
- Creates a voice packet from data sent from Discord.
- setBuffer() : $this
- Sets the buffer.
- validatePacket() : bool
- Validates a VoicePacket for sending.
- buildHeader() : Buffer
- Builds the header.
- initBufferEncryption() : void
- Initilizes the buffer with encryption.
- initBufferNoEncryption() : void
- Initilizes the buffer with no encryption.
Constants
AUTH_TAG_LENGTH
public
mixed
AUTH_TAG_LENGTH
= 16
RTP_HEADER_BYTE_LENGTH
public
mixed
RTP_HEADER_BYTE_LENGTH
= 12
RTP_PAYLOAD_INDEX
public
mixed
RTP_PAYLOAD_INDEX
= 1
RTP_PAYLOAD_TYPE
This is Discord's RTP Profile Payload type, which is the same as Opus audio RTP stream's default payload type of 120 (0x78 & 0x7F).
public
mixed
RTP_PAYLOAD_TYPE
= 0x78
Tags
RTP_VERSION_PAD_EXTEND
Bit index 0 and 1 represent the RTP Protocol version used. Discord uses the latest RTP protocol version, 2.
public
mixed
RTP_VERSION_PAD_EXTEND
= 0x80
Bit index 2 represents whether or not we pad. Opus uses an internal padding system, so RTP padding is not used. Bit index 3 represents if we use extensions. Bit index 4 to 7 represent the CC or CSRC count. CSRC is Combined SSRC.
RTP_VERSION_PAD_EXTEND_INDEX
public
mixed
RTP_VERSION_PAD_EXTEND_INDEX
= 0
SEQ_INDEX
public
mixed
SEQ_INDEX
= 2
SSRC_INDEX
public
mixed
SSRC_INDEX
= 8
TIMESTAMP_INDEX
public
mixed
TIMESTAMP_INDEX
= 4
Properties
$buffer
The voice packet buffer.
protected
Buffer
$buffer
$seq
The packet sequence.
protected
int
$seq
The packet sequence.
$ssrc
The client SSRC.
protected
int
$ssrc
The client SSRC.
$timestamp
The packet timestamp.
protected
float
$timestamp
The packet timestamp.
Methods
__construct()
Constructs the voice packet.
public
__construct(string $data, int $ssrc, int $seq, float $timestamp[, bool $encryption = false ][, string|null $key = null ]) : mixed
Parameters
- $data : string
-
The Opus data to encode.
- $ssrc : int
-
The client SSRC value.
- $seq : int
-
The packet sequence.
- $timestamp : float
-
The packet timestamp.
- $encryption : bool = false
-
(Deprecated) Whether the packet should be encrypted.
- $key : string|null = null
-
(Deprecated) The encryption key.
__toString()
Handles to string casting of object.
public
__toString() : string
Return values
stringgetData()
Returns the data.
public
getData() : string
Return values
string —The packet data.
getHeader()
Returns the header.
public
getHeader() : string
Return values
string —The packet header.
getSequence()
Returns the sequence.
public
getSequence() : int
Return values
int —The packet sequence.
getSSRC()
Returns the SSRC.
public
getSSRC() : int
Return values
int —The packet SSRC.
getTimestamp()
Returns the timestamp.
public
getTimestamp() : float
Return values
float —The packet timestamp.
make()
Creates a voice packet from data sent from Discord.
public
static make(string $data) : VoicePacket
Parameters
- $data : string
-
Data from Discord.
Return values
VoicePacket —A voice packet.
setBuffer()
Sets the buffer.
public
setBuffer(Buffer $buffer) : $this
Parameters
- $buffer : Buffer
-
The buffer to set.
Return values
$thisvalidatePacket()
Validates a VoicePacket for sending.
public
static validatePacket(VoicePacket $packet) : bool
Parameters
- $packet : VoicePacket
-
The packet to validate.
Return values
bool —Whether the packet is valid.
buildHeader()
Builds the header.
protected
buildHeader() : Buffer
Tags
Return values
Buffer —The header.
initBufferEncryption()
Initilizes the buffer with encryption.
protected
initBufferEncryption(string $data, string $key) : void
Use VoiceGroupCrypto::encryptRTPPacket()
Parameters
- $data : string
-
The Opus data to encode.
- $key : string
-
The encryption key.
initBufferNoEncryption()
Initilizes the buffer with no encryption.
protected
initBufferNoEncryption(string $data) : void
Parameters
- $data : string
-
The Opus data to encode.