udp

package
v3.0.0-...-04a954d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2021 License: ISC Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDecryptionFailed = errors.New("decryption failed")
	Dialer              = net.Dialer{
		Timeout: 10 * time.Second,
	}
)

Dialer is the default dialer that this package uses for all its dialing.

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 DialConnectionCtx

func DialConnectionCtx(ctx context.Context, addr string, ssrc uint32) (*Connection, error)

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) ReadPacket

func (c *Connection) ReadPacket() (*Packet, error)

ReadPacket reads the UDP connection and returns a packet if successful. This packet is not thread-safe to use, as it shares recvBuf's buffer. Byte slices inside it must be copied or used before the next call to ReadPacket happens.

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) UseContext

func (c *Connection) UseContext(ctx context.Context) error

UseContext lets the connection use the given context for its Write method. WriteCtx will override this context.

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.

func (*Connection) Write

func (c *Connection) Write(b []byte) (int, error)

Write sends bytes into the voice UDP connection using the preset context.

func (*Connection) WriteCtx

func (c *Connection) WriteCtx(ctx context.Context, b []byte) (int, error)

WriteCtx sends bytes into the voice UDP connection with a timeout using the given context. It ignores the context inside the connection, but will restore the deadline after this call is done.

type Packet

type Packet struct {
	VersionFlags byte
	Type         byte
	SSRC         uint32
	Sequence     uint16
	Timestamp    uint32
	Opus         []byte
}

Packet represents a voice packet. It is not thread-safe.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL