Documentation ¶
Index ¶
- Variables
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) ReadPacket() (*Packet, error)
- func (c *Connection) ResetFrequency(frameDuration time.Duration, timeIncr uint32)
- func (c *Connection) SetReadDeadline(deadline time.Time)
- func (c *Connection) SetWriteDeadline(deadline time.Time)
- func (c *Connection) UseSecret(secret [32]byte)
- func (c *Connection) Write(b []byte) (int, error)
- type DialFunc
- type Manager
- func (m *Manager) Close() (err error)
- func (m *Manager) Continue() bool
- func (m *Manager) Dial(ctx context.Context, addr string, ssrc uint32) (*Connection, error)
- func (m *Manager) IsClosed() bool
- func (m *Manager) Pause(ctx context.Context) error
- func (m *Manager) ReadPacket() (p *Packet, err error)
- func (m *Manager) ResetFrequency(frameDuration time.Duration, timeIncr uint32)
- func (m *Manager) SetDialer(d DialFunc)
- func (m *Manager) Write(b []byte) (n int, err error)
- type Packet
Constants ¶
This section is empty.
Variables ¶
var ErrDecryptionFailed = errors.New("decryption failed")
ErrDecryptionFailed is returned from ReadPacket if the received packet fails to decrypt.
var ErrDialWhileUnpaused = errors.New("dial is called while manager is not paused")
ErrDialWhileUnpaused is returned if Dial is called on the Manager without pausing it first
var ErrManagerClosed = errors.New("UDP connection manager is closed")
ErrManagerClosed is returned when a Manager that is already closed is dialed, written to or read from.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { GatewayIP string GatewayPort uint16 // contains filtered or unexported fields }
Connection represents a voice connection. It is not thread-safe.
func DialConnection ¶
DialConnection dials the UDP connection using the given address and SSRC number.
func DialConnectionCustom ¶
func DialConnectionCustom( ctx context.Context, dialer *net.Dialer, addr string, ssrc uint32) (*Connection, error)
DialConnectionCustom dials the UDP connection with a custom dialer.
func (*Connection) ReadPacket ¶
func (c *Connection) ReadPacket() (*Packet, error)
ReadPacket reads the UDP connection and returns a packet if successful. The returned packet is invalidated once ReadPacket is called again. To avoid this, manually Copy the packet.
func (*Connection) ResetFrequency ¶
func (c *Connection) ResetFrequency(frameDuration time.Duration, timeIncr uint32)
ResetFrequency resets the internal frequency ticker as well as the timestamp incremental number. For more information, refer to https://tools.ietf.org/html/rfc7587#section-4.2.
frameDuration controls the Opus frame duration used by the UDP connection to control the frequency of packets sent over. 20ms is the default by libopus.
timestampIncr is the timestamp to increment for each Opus packet. This should be consistent with th given frameDuration. For the right combination, refer to the Valid Parameters section below.
Valid Parameters ¶
The following table lists the recommended parameters for these variables.
+---------+-----+-----+------+------+ | Mode | 10 | 20 | 40 | 60 | +---------+-----+-----+------+------+ | ts incr | 480 | 960 | 1920 | 2880 | +---------+-----+-----+------+------+
Note that audio mode is omitted, as it is not recommended. For the full table, refer to the IETF RFC7587 section 4.2 link above.
func (*Connection) SetReadDeadline ¶
func (c *Connection) SetReadDeadline(deadline time.Time)
SetReadDeadline sets the UDP connection's read deadline.
func (*Connection) SetWriteDeadline ¶
func (c *Connection) SetWriteDeadline(deadline time.Time)
SetWriteDeadline sets the UDP connection's write deadline.
func (*Connection) UseSecret ¶
func (c *Connection) UseSecret(secret [32]byte)
UseSecret uses the given secret. This method is not thread-safe, so it should only be used right after initialization.
type DialFunc ¶
DialFunc is the UDP dialer function type. It's the function signature for udp.DialConnection.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages a UDP connection. It allows reconnecting. A Manager instance is thread-safe, meaning it can be used concurrently.
func NewManager ¶
func NewManager() *Manager
NewManager creates a new UDP connection manager with the default dial function DialConnection.
func NewManagerWithDialer ¶
NewManagerWithDialer creates a UDP manager with an existing dial function.
func (*Manager) Close ¶
Close closes the current connection. If the connection is already closed, then nothing is done and ErrManagerClosed is returned. Close does not pause the connection; calls to Close while the user is using the connection will result in the user getting ErrManagerClosed.
func (*Manager) Continue ¶
Continue unpauses and resumes the active user. If the manager has been successfully resumed, then true is returned, otherwise if it's already continued, then false is returned.
func (*Manager) Dial ¶
Dial dials the internal connection to the given address and SSRC number. If the Manager is not Paused, then an error is returned. The caller must call Dial after Pause and before Unpause. If the Manager is already being dialed elsewhere, then ErrAlreadyDialing is returned.
func (*Manager) Pause ¶
Pause explicitly pauses the manager. It blocks until the Manager is paused or the context expires.
func (*Manager) ReadPacket ¶
ReadPacket reads the current packet. It blocks until a packet arrives or the Manager is closed.
func (*Manager) ResetFrequency ¶
ResetFrequency sets the current connection and future connections' write frequency. Note that calling this method while Connection is being used in a different goroutine is not thread-safe.
type Packet ¶
type Packet struct { Opus []byte // contains filtered or unexported fields }
Packet represents a voice packet.
func (*Packet) VersionFlags ¶
VersionFlags returns the version flags of the current packet.