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) UseContext(ctx context.Context) error
- func (c *Connection) UseSecret(secret [32]byte)
- func (c *Connection) Write(b []byte) (int, error)
- func (c *Connection) WriteCtx(ctx context.Context, b []byte) (int, error)
- type Packet
Constants ¶
This section is empty.
Variables ¶
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 (*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.