DiscordPHP-Voice Documentation

UDP extends Socket
in package

Handles the UDP connection & events for Discord voice.

This class manages the UDP socket for sending and receiving audio data, handling heartbeats, and managing the voice connection state.

Tags
since
10.19.0

Table of Contents

Constants

SILENCE_FRAME  : string = "\xf8\xff\xfe"
The Opus Silence Frame.

Properties

$hbInterval  : int|null
Heartbeat interval in milliseconds.
$heartbeat  : TimerInterface|null
Current heartbeat timer.
$ip  : string
The IP address of the UDP server.
$port  : int
The port of the UDP server.
$silenceRemaining  : int
Silence Frame Remain Count.
$ssrc  : null|string|int
The SSRC identifier.
$streamTime  : int
The stream time of the last packet.
$ws  : WS
The Parent Voice WebSocket Client.
$hbSequence  : int
Heartbeat sequence number.

Methods

__construct()  : mixed
close()  : void
Closes the UDP client and cancels the heartbeat timer.
decodeOnce()  : self
Decodes the first UDP message received from the server.
handleErrors()  : self
Handles errors that occur during UDP communication.
handleHeartbeat()  : self
Handles the heartbeat for the UDP client.
handleMessages()  : self
Handles incoming messages from the UDP server.
handleSsrcSending()  : self
Handles the sending of the SSRC to the server.
insertSilence()  : void
Insert 5 frames of silence.
isClosed()  : bool
Whether the socket is already closed.
refreshSilenceFrames()  : void
Refreshes the silence frames.
sendBuffer()  : void
Sends a buffer to the UDP socket.
getLogger()  : LoggerInterface
Gets the logger instance.
getLoop()  : LoopInterface
Gets the event loop instance.

Constants

SILENCE_FRAME

The Opus Silence Frame.

public string SILENCE_FRAME = "\xf8\xff\xfe"

Properties

$hbInterval

Heartbeat interval in milliseconds.

public int|null $hbInterval = null

The interval at which the heartbeat is sent.

$heartbeat

Current heartbeat timer.

public TimerInterface|null $heartbeat = null

$ip

The IP address of the UDP server.

public string $ip

$port

The port of the UDP server.

public int $port

$silenceRemaining

Silence Frame Remain Count.

public int $silenceRemaining = 5

$ssrc

The SSRC identifier.

public null|string|int $ssrc

This is used to identify the source of the audio stream.

$streamTime

The stream time of the last packet.

public int $streamTime = 0

$ws

The Parent Voice WebSocket Client.

public WS $ws

$hbSequence

Heartbeat sequence number.

protected int $hbSequence = 0

This is used to keep track of the heartbeat messages sent.

Methods

__construct()

public __construct(LoopInterface $loop, resource $socket[, null|Buffer $buffer = null ][, null|WS $ws = null ]) : mixed
Parameters
$loop : LoopInterface
$socket : resource
$buffer : null|Buffer = null
$ws : null|WS = null

close()

Closes the UDP client and cancels the heartbeat timer.

public close() : void

handleErrors()

Handles errors that occur during UDP communication.

public handleErrors() : self
Return values
self

handleHeartbeat()

Handles the heartbeat for the UDP client.

public handleHeartbeat() : self

To keep the connection open and responsive.

Return values
self

handleMessages()

Handles incoming messages from the UDP server.

public handleMessages(string $secret) : self

This is where we handle the audio data received from the server.

Parameters
$secret : string
Return values
self

handleSsrcSending()

Handles the sending of the SSRC to the server.

public handleSsrcSending() : self

This is necessary for the server to know which SSRC we are using.

Return values
self

isClosed()

Whether the socket is already closed.

public isClosed() : bool
Return values
bool

refreshSilenceFrames()

Refreshes the silence frames.

public refreshSilenceFrames() : void

sendBuffer()

Sends a buffer to the UDP socket.

public sendBuffer(string $data) : void
Parameters
$data : string

getLogger()

Gets the logger instance.

private getLogger() : LoggerInterface
Return values
LoggerInterface

getLoop()

Gets the event loop instance.

private getLoop() : LoopInterface
Return values
LoopInterface
On this page

Search results