Documentation ¶
Index ¶
- Constants
- Variables
- type AudioReceiver
- type AudioReceiverCreateFunc
- type AudioSender
- type AudioSenderCreateFunc
- type CloseHandlerFunc
- type Conn
- type ConnConfig
- type ConnConfigOpt
- func WithConnAudioReceiverCreateFunc(audioReceiverCreateFunc AudioReceiverCreateFunc) ConnConfigOpt
- func WithConnAudioSenderCreateFunc(audioSenderCreateFunc AudioSenderCreateFunc) ConnConfigOpt
- func WithConnEventHandlerFunc(eventHandlerFunc EventHandlerFunc) ConnConfigOpt
- func WithConnGatewayConfigOpts(opts ...GatewayConfigOpt) ConnConfigOpt
- func WithConnGatewayCreateFunc(gatewayCreateFunc GatewayCreateFunc) ConnConfigOpt
- func WithConnLogger(logger log.Logger) ConnConfigOpt
- func WithUDPConnConfigOpts(opts ...UDPConnConfigOpt) ConnConfigOpt
- func WithUDPConnCreateFunc(udpConnCreateFunc UDPConnCreateFunc) ConnConfigOpt
- type ConnCreateFunc
- type EncryptionMode
- type EventHandlerFunc
- type Gateway
- type GatewayCloseEventCode
- type GatewayConfig
- type GatewayConfigOpt
- type GatewayCreateFunc
- type GatewayMessage
- type GatewayMessageData
- type GatewayMessageDataClientConnect
- type GatewayMessageDataClientDisconnect
- type GatewayMessageDataHeartbeat
- type GatewayMessageDataHeartbeatACK
- type GatewayMessageDataHello
- type GatewayMessageDataIdentify
- type GatewayMessageDataReady
- type GatewayMessageDataResume
- type GatewayMessageDataSelectProtocol
- type GatewayMessageDataSelectProtocolData
- type GatewayMessageDataSessionDescription
- type GatewayMessageDataSpeaking
- type GatewayMessageDataUnknown
- type Manager
- type ManagerConfig
- type ManagerConfigOpt
- type Opcode
- type OpusFrameProvider
- type OpusFrameReceiver
- type Packet
- type SpeakingFlags
- type State
- type StateProviderFunc
- type StateUpdateFunc
- type Status
- type UDPConn
- type UDPConnConfig
- type UDPConnConfigOpt
- type UDPConnCreateFunc
- type UserFilterFunc
- type VoiceProtocol
Constants ¶
const GatewayVersion = 4
GatewayVersion is the version of the voice gateway we are using.
const OpusPacketHeaderSize = 12
OpusPacketHeaderSize is the size of the opus packet header.
Variables ¶
var ( // SilenceAudioFrame is a 20ms opus frame of silence. SilenceAudioFrame = []byte{0xF8, 0xFF, 0xFE} // OpusFrameSize is the size of an opus frame in milliseconds. OpusFrameSize int64 = 20 // OpusStreamBuffSize is the size of the buffer for receiving one opus frame. OpusStreamBuffSize int64 = 4000 )
var ( // ErrGatewayNotConnected is returned when the gateway is not connected and a message is attempted to be sent. ErrGatewayNotConnected = fmt.Errorf("voice gateway not connected") // ErrGatewayAlreadyConnected is returned when the gateway is already connected and a connection is attempted to be opened. ErrGatewayAlreadyConnected = fmt.Errorf("voice gateway already connected") )
var ( GatewayCloseEventCodeHeartbeatTimeout = GatewayCloseEventCode{ Code: 1000, Description: "Heartbeat timeout", Explanation: "We did not heartbeat in time.", Reconnect: true, } GatewayCloseEventCodeUnknownError = GatewayCloseEventCode{ Code: 4000, Description: "Unknown error", Explanation: "We're not sure what went wrong. Try reconnecting?", Reconnect: true, } GatewayCloseEventCodeUnknownOpcode = GatewayCloseEventCode{ Code: 4001, Description: "Unknown opcode", Explanation: "You sent an invalid opcode.", Reconnect: true, } GatewayCloseEventCodeFailedDecode = GatewayCloseEventCode{ Code: 4002, Description: "Failed to decode payload", Explanation: "You sent a invalid payload in your identifying to the Gateway.", Reconnect: true, } GatewayCloseEventCodeNotAuthenticated = GatewayCloseEventCode{ Code: 4003, Description: "Not authenticated", Explanation: "You sent a payload before identifying with the Gateway.", Reconnect: false, } GatewayCloseEventCodeAuthenticationFailed = GatewayCloseEventCode{ Code: 4004, Description: "Authentication failed", Explanation: "The token you sent in your identify payload is incorrect.", Reconnect: false, } GatewayCloseEventCodeAlreadyAuthenticated = GatewayCloseEventCode{ Code: 4005, Description: "Already authenticated", Explanation: "You sent more than one identify payload. Stahp.", Reconnect: true, } GatewayCloseEventCodeSessionNoLongerValid = GatewayCloseEventCode{ Code: 4006, Description: "Session no longer valid", Explanation: "Your session is no longer valid.", Reconnect: false, } GatewayCloseEventCodeSessionTimeout = GatewayCloseEventCode{ Code: 4009, Description: "Session timeout", Explanation: "Your session has timed out.", Reconnect: false, } GatewayCloseEventCodeServerNotFound = GatewayCloseEventCode{ Code: 4011, Description: "Server not found", Explanation: "We can't find the server you're trying to connect to.", Reconnect: false, } GatewayCloseEventCodeUnknownProtocol = GatewayCloseEventCode{ Code: 4012, Description: "Unknown protocol", Explanation: "We didn't recognize the protocol you sent.", Reconnect: false, } GatewayCloseEventCodeDisconnected = GatewayCloseEventCode{ Code: 4014, Description: "Disconnected", Explanation: "Channel was deleted, you were kicked, voice server changed, or the main voicegateway session was dropped. Don't reconnect.", Reconnect: false, } GatewayCloseEventCodeVoiceServerCrash = GatewayCloseEventCode{ Code: 4015, Description: "Voice server crashed", Explanation: "The server crashed. Our bad! Try resuming.", Reconnect: true, } GatewayCloseEventCodeUnknownEncryptionMode = GatewayCloseEventCode{ Code: 4016, Description: "Unknown encryption mode", Explanation: "We didn't recognize your encryption.", Reconnect: false, } GatewayCloseEventCodeUnknown = GatewayCloseEventCode{ Code: 0, Description: "Unknown", Explanation: "Unknown Voice Close Event Code", Reconnect: true, } GatewayCloseEventCodes = map[int]GatewayCloseEventCode{ GatewayCloseEventCodeHeartbeatTimeout.Code: GatewayCloseEventCodeHeartbeatTimeout, GatewayCloseEventCodeUnknownError.Code: GatewayCloseEventCodeUnknownError, GatewayCloseEventCodeUnknownOpcode.Code: GatewayCloseEventCodeUnknownOpcode, GatewayCloseEventCodeFailedDecode.Code: GatewayCloseEventCodeFailedDecode, GatewayCloseEventCodeNotAuthenticated.Code: GatewayCloseEventCodeNotAuthenticated, GatewayCloseEventCodeAuthenticationFailed.Code: GatewayCloseEventCodeAuthenticationFailed, GatewayCloseEventCodeAlreadyAuthenticated.Code: GatewayCloseEventCodeAlreadyAuthenticated, GatewayCloseEventCodeSessionNoLongerValid.Code: GatewayCloseEventCodeSessionNoLongerValid, GatewayCloseEventCodeSessionTimeout.Code: GatewayCloseEventCodeSessionTimeout, GatewayCloseEventCodeServerNotFound.Code: GatewayCloseEventCodeServerNotFound, GatewayCloseEventCodeUnknownProtocol.Code: GatewayCloseEventCodeUnknownProtocol, GatewayCloseEventCodeDisconnected.Code: GatewayCloseEventCodeDisconnected, GatewayCloseEventCodeVoiceServerCrash.Code: GatewayCloseEventCodeVoiceServerCrash, GatewayCloseEventCodeUnknownEncryptionMode.Code: GatewayCloseEventCodeUnknownEncryptionMode, } )
var ErrDecryptionFailed = errors.New("decryption failed")
ErrDecryptionFailed is returned when the packet decryption fails.
Functions ¶
This section is empty.
Types ¶
type AudioReceiver ¶
type AudioReceiver interface { // Open starts receiving audio from the voice connection. Open() // CleanupUser cleans up any audio resources for the given user. CleanupUser(userID snowflake.ID) // Close stops receiving audio from the voice connection. Close() }
AudioReceiver is used to receive audio from a voice connection and pass it to an OpusFrameReceiver.
func NewAudioReceiver ¶
func NewAudioReceiver(logger log.Logger, opusReceiver OpusFrameReceiver, conn Conn) AudioReceiver
NewAudioReceiver creates a new AudioReceiver reading audio to the given OpusFrameReceiver from the given Conn.
type AudioReceiverCreateFunc ¶
type AudioReceiverCreateFunc func(logger log.Logger, receiver OpusFrameReceiver, connection Conn) AudioReceiver
AudioReceiverCreateFunc is used to create a new AudioReceiver reading audio from the given Conn.
type AudioSender ¶
type AudioSender interface { Open() Close() }
AudioSender is used to send audio to a Conn.
func NewAudioSender ¶
func NewAudioSender(logger log.Logger, opusProvider OpusFrameProvider, conn Conn) AudioSender
NewAudioSender creates a new AudioSender sending audio from the given OpusFrameProvider to the given Conn.
type AudioSenderCreateFunc ¶
type AudioSenderCreateFunc func(logger log.Logger, provider OpusFrameProvider, conn Conn) AudioSender
AudioSenderCreateFunc is used to create a new AudioSender sending audio to the given Conn.
type CloseHandlerFunc ¶
CloseHandlerFunc is a function that handles a voice gateway close.
type Conn ¶
type Conn interface { // Gateway returns the voice Gateway used by the voice Conn. Gateway() Gateway // UDP returns the voice UDPConn conn used by the voice Conn. UDP() UDPConn // ChannelID returns the ID of the voice channel the voice Conn is openedChan to. ChannelID() *snowflake.ID // GuildID returns the ID of the guild the voice Conn is openedChan to. GuildID() snowflake.ID // UserIDBySSRC returns the ID of the user for the given SSRC. UserIDBySSRC(ssrc uint32) snowflake.ID // SetSpeaking sends a speaking packet to the Conn socket discord. SetSpeaking(ctx context.Context, flags SpeakingFlags) error // SetOpusFrameProvider lets you inject your own OpusFrameProvider. SetOpusFrameProvider(handler OpusFrameProvider) // SetOpusFrameReceiver lets you inject your own OpusFrameReceiver. SetOpusFrameReceiver(handler OpusFrameReceiver) // SetEventHandlerFunc lets listen for voice gateway events. SetEventHandlerFunc(eventHandlerFunc EventHandlerFunc) // Open opens the voice conn. It will connect to the voice gateway and start the Conn conn after it receives the Gateway events. Open(ctx context.Context, channelID snowflake.ID, selfMute bool, selfDeaf bool) error // Close closes the voice conn. It will close the Conn conn and disconnect from the voice gateway. Close(ctx context.Context) // HandleVoiceStateUpdate provides the gateway.EventVoiceStateUpdate to the voice conn. Which is needed to connect to the voice Gateway. HandleVoiceStateUpdate(update botgateway.EventVoiceStateUpdate) // HandleVoiceServerUpdate provides the gateway.EventVoiceServerUpdate to the voice conn. Which is needed to connect to the voice Gateway. HandleVoiceServerUpdate(update botgateway.EventVoiceServerUpdate) }
Conn is a complete voice conn to discord. It holds the Gateway and voiceudp.UDPConn conn and combines them.
func NewConn ¶
func NewConn(guildID snowflake.ID, userID snowflake.ID, voiceStateUpdateFunc StateUpdateFunc, removeConnFunc func(), opts ...ConnConfigOpt) Conn
NewConn returns a new default voice conn.
type ConnConfig ¶
type ConnConfig struct { Logger log.Logger GatewayCreateFunc GatewayCreateFunc GatewayConfigOpts []GatewayConfigOpt UDPConnCreateFunc UDPConnCreateFunc UDPConnConfigOpts []UDPConnConfigOpt AudioSenderCreateFunc AudioSenderCreateFunc AudioReceiverCreateFunc AudioReceiverCreateFunc EventHandlerFunc EventHandlerFunc }
ConnConfig is used to configure a Conn.
func DefaultConnConfig ¶
func DefaultConnConfig() *ConnConfig
DefaultConnConfig returns a ConnConfig with sensible defaults.
func (*ConnConfig) Apply ¶
func (c *ConnConfig) Apply(opts []ConnConfigOpt)
Apply applies the ConnConfigOpt(s) to the ConnConfig.
type ConnConfigOpt ¶
type ConnConfigOpt func(connConfig *ConnConfig)
ConnConfigOpt is used to functionally configure a ConnConfig.
func WithConnAudioReceiverCreateFunc ¶
func WithConnAudioReceiverCreateFunc(audioReceiverCreateFunc AudioReceiverCreateFunc) ConnConfigOpt
WithConnAudioReceiverCreateFunc sets the Conn(s) used AudioReceiverCreateFunc.
func WithConnAudioSenderCreateFunc ¶
func WithConnAudioSenderCreateFunc(audioSenderCreateFunc AudioSenderCreateFunc) ConnConfigOpt
WithConnAudioSenderCreateFunc sets the Conn(s) used AudioSenderCreateFunc.
func WithConnEventHandlerFunc ¶
func WithConnEventHandlerFunc(eventHandlerFunc EventHandlerFunc) ConnConfigOpt
WithConnEventHandlerFunc sets the Conn(s) used EventHandlerFunc.
func WithConnGatewayConfigOpts ¶
func WithConnGatewayConfigOpts(opts ...GatewayConfigOpt) ConnConfigOpt
WithConnGatewayConfigOpts sets the Conn(s) used GatewayConfigOpt(s).
func WithConnGatewayCreateFunc ¶
func WithConnGatewayCreateFunc(gatewayCreateFunc GatewayCreateFunc) ConnConfigOpt
WithConnGatewayCreateFunc sets the Conn(s) used GatewayCreateFunc.
func WithConnLogger ¶
func WithConnLogger(logger log.Logger) ConnConfigOpt
WithConnLogger sets the Conn(s) used Logger.
func WithUDPConnConfigOpts ¶
func WithUDPConnConfigOpts(opts ...UDPConnConfigOpt) ConnConfigOpt
WithUDPConnConfigOpts sets the Conn(s) used UDPConnConfigOpt(s).
func WithUDPConnCreateFunc ¶
func WithUDPConnCreateFunc(udpConnCreateFunc UDPConnCreateFunc) ConnConfigOpt
WithUDPConnCreateFunc sets the Conn(s) used UDPConnCreateFunc.
type ConnCreateFunc ¶
type ConnCreateFunc func(guildID snowflake.ID, userID snowflake.ID, voiceStateUpdateFunc StateUpdateFunc, removeConnFunc func(), opts ...ConnConfigOpt) Conn
ConnCreateFunc is a type alias for a function that creates a new Conn.
type EncryptionMode ¶
type EncryptionMode string
EncryptionMode is the encryption mode used for voice data.
const ( EncryptionModeNormal EncryptionMode = "xsalsa20_poly1305" EncryptionModeSuffix EncryptionMode = "xsalsa20_poly1305_suffix" EncryptionModeLite EncryptionMode = "xsalsa20_poly1305_lite" )
All possible EncryptionMode(s) https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-encryption-modes.
type EventHandlerFunc ¶
type EventHandlerFunc func(opCode Opcode, data GatewayMessageData)
EventHandlerFunc is a function that handles a voice gateway event.
type Gateway ¶
type Gateway interface { // SSRC returns the SSRC of the current voice connection. SSRC() uint32 // Latency returns the current latency of the voice gateway connection. Latency() time.Duration // Open opens a new websocket connection to the voice gateway. Open(ctx context.Context, state State) error // Close closes the websocket connection to the voice gateway. Close() // CloseWithCode closes the websocket connection to the voice gateway with a specific close code. CloseWithCode(code int, message string) // Send sends a message to the voice gateway. Send(ctx context.Context, opCode Opcode, data GatewayMessageData) error }
Gateway is a websocket connection to the Discord voice gateway.
func NewGateway ¶
func NewGateway(eventHandlerFunc EventHandlerFunc, closeHandlerFunc CloseHandlerFunc, opts ...GatewayConfigOpt) Gateway
NewGateway creates a new voice Gateway.
type GatewayCloseEventCode ¶
func GatewayCloseEventCodeByCode ¶
func GatewayCloseEventCodeByCode(code int) GatewayCloseEventCode
type GatewayConfig ¶
GatewayConfig is used to configure a Gateway.
func DefaultGatewayConfig ¶
func DefaultGatewayConfig() *GatewayConfig
DefaultGatewayConfig returns a GatewayConfig with sensible defaults.
func (*GatewayConfig) Apply ¶
func (c *GatewayConfig) Apply(opts []GatewayConfigOpt)
Apply applies the GatewayConfigOpt(s) to the GatewayConfig.
type GatewayConfigOpt ¶
type GatewayConfigOpt func(config *GatewayConfig)
GatewayConfigOpt is used to functionally configure a GatewayConfig.
func WithGatewayAutoReconnect ¶
func WithGatewayAutoReconnect(autoReconnect bool) GatewayConfigOpt
WithGatewayAutoReconnect sets the Gateway(s) used AutoReconnect.
func WithGatewayDialer ¶
func WithGatewayDialer(dialer *websocket.Dialer) GatewayConfigOpt
WithGatewayDialer sets the Gateway(s) used websocket.Dialer.
func WithGatewayLogger ¶
func WithGatewayLogger(logger log.Logger) GatewayConfigOpt
WithGatewayLogger sets the Gateway(s) used Logger.
type GatewayCreateFunc ¶
type GatewayCreateFunc func(eventHandlerFunc EventHandlerFunc, closeHandlerFunc CloseHandlerFunc, opts ...GatewayConfigOpt) Gateway
GatewayCreateFunc is a function that creates a new voice gateway.
type GatewayMessage ¶
type GatewayMessage struct { Op Opcode `json:"op"` D GatewayMessageData `json:"d,omitempty"` }
GatewayMessage represents a voice gateway message
func (*GatewayMessage) UnmarshalJSON ¶
func (m *GatewayMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshalls the GatewayMessage from json
type GatewayMessageData ¶
type GatewayMessageData interface {
// contains filtered or unexported methods
}
GatewayMessageData represents a voice gateway message data.
type GatewayMessageDataClientDisconnect ¶
type GatewayMessageDataClientDisconnect struct {
UserID snowflake.ID `json:"user_id"`
}
type GatewayMessageDataHeartbeat ¶
type GatewayMessageDataHeartbeat int64
type GatewayMessageDataHeartbeatACK ¶
type GatewayMessageDataHeartbeatACK int64
type GatewayMessageDataHello ¶
type GatewayMessageDataHello struct {
HeartbeatInterval float64 `json:"heartbeat_interval"`
}
type GatewayMessageDataReady ¶
type GatewayMessageDataSelectProtocol ¶
type GatewayMessageDataSelectProtocol struct { Protocol VoiceProtocol `json:"protocol"` Data GatewayMessageDataSelectProtocolData `json:"data"` }
type GatewayMessageDataSelectProtocolData ¶
type GatewayMessageDataSelectProtocolData struct { Address string `json:"address"` Port int `json:"port"` Mode EncryptionMode `json:"mode"` }
type GatewayMessageDataSpeaking ¶
type GatewayMessageDataSpeaking struct { Speaking SpeakingFlags `json:"speaking"` Delay int `json:"delay"` SSRC uint32 `json:"ssrc"` UserID snowflake.ID `json:"user_id,omitempty"` }
type GatewayMessageDataUnknown ¶
type GatewayMessageDataUnknown json.RawMessage
type Manager ¶
type Manager interface { // HandleVoiceStateUpdate handles a gateway.EventVoiceStateUpdate HandleVoiceStateUpdate(update gateway.EventVoiceStateUpdate) // HandleVoiceServerUpdate handles a gateway.EventVoiceServerUpdate HandleVoiceServerUpdate(update gateway.EventVoiceServerUpdate) // CreateConn creates a new voice connection for the given guild. CreateConn(guildID snowflake.ID) Conn // GetConn returns the voice connection for the given guild. GetConn(guildID snowflake.ID) Conn // ForEachCon runs the given function for each voice connection. This is thread-safe. ForEachCon(f func(connection Conn)) // RemoveConn removes the voice connection for the given guild. RemoveConn(guildID snowflake.ID) // Close closes all voice connections. Close(ctx context.Context) }
Manager manages all voice connections.
func NewManager ¶
func NewManager(voiceStateUpdateFunc StateUpdateFunc, userID snowflake.ID, opts ...ManagerConfigOpt) Manager
NewManager creates a new Manager.
type ManagerConfig ¶
type ManagerConfig struct { Logger log.Logger ConnCreateFunc ConnCreateFunc ConnOpts []ConnConfigOpt }
ManagerConfig is a function that configures a Manager.
func DefaultManagerConfig ¶
func DefaultManagerConfig() *ManagerConfig
DefaultManagerConfig returns the default ManagerConfig with sensible defaults.
func (*ManagerConfig) Apply ¶
func (c *ManagerConfig) Apply(opts []ManagerConfigOpt)
Apply applies the given ManagerConfigOpts to the ManagerConfig.
type ManagerConfigOpt ¶
type ManagerConfigOpt func(ManagerConfig *ManagerConfig)
ManagerConfigOpt is used to functionally configure a ManagerConfig.
func WithConnConfigOpts ¶
func WithConnConfigOpts(opts ...ConnConfigOpt) ManagerConfigOpt
WithConnConfigOpts sets the ConnConfigOpt(s) for the Manager
func WithConnCreateFunc ¶
func WithConnCreateFunc(connectionCreateFunc ConnCreateFunc) ManagerConfigOpt
WithConnCreateFunc sets the ConnCreateFunc for the Manager
func WithLogger ¶
func WithLogger(logger log.Logger) ManagerConfigOpt
WithLogger sets the logger for the webhook client
type OpusFrameProvider ¶
type OpusFrameProvider interface { // ProvideOpusFrame provides an opus frame to the AudioSender. ProvideOpusFrame() ([]byte, error) // Close closes the OpusFrameProvider. Close() }
OpusFrameProvider is used to provide opus frames to an AudioSender.
func NewOpusReader ¶
func NewOpusReader(r io.Reader) OpusFrameProvider
NewOpusReader returns a new OpusFrameProvider that reads opus frames from the given io.Reader.
type OpusFrameReceiver ¶
type OpusFrameReceiver interface { // ReceiveOpusFrame receives an opus frame. ReceiveOpusFrame(userID snowflake.ID, packet *Packet) error // CleanupUser cleans up any audio resources for the given user. CleanupUser(userID snowflake.ID) // Close stops receiving audio from the voice connection. Close() }
OpusFrameReceiver is an interface used to receive opus frames from an AudioReceiver.
func NewOpusWriter ¶
func NewOpusWriter(w io.Writer, userFilter UserFilterFunc) OpusFrameReceiver
NewOpusWriter returns a new OpusFrameReceiver that writes opus frames to the given io.Writer.
type Packet ¶
type Packet struct { // Sequence is the sequence number of the packet. Sequence uint16 // Timestamp is the timestamp of the packet. Timestamp uint32 // SSRC is the users SSRC of the packet. SSRC uint32 // Opus is the actual opus data of the packet. Opus []byte }
Packet is a voice packet received from discord.
type SpeakingFlags ¶
type SpeakingFlags int
const ( SpeakingFlagMicrophone SpeakingFlags = 1 << iota SpeakingFlagPriority SpeakingFlagNone SpeakingFlags = 0 )
type State ¶
type State struct { GuildID snowflake.ID UserID snowflake.ID ChannelID *snowflake.ID SessionID string Token string Endpoint string }
State is the current state of the voice conn.
type StateProviderFunc ¶
type StateProviderFunc func() State
StateProviderFunc is a function that provides the current conn state of the voice gateway.
type StateUpdateFunc ¶
type StateUpdateFunc func(ctx context.Context, guildID snowflake.ID, channelID *snowflake.ID, selfMute bool, selfDeaf bool) error
StateUpdateFunc is used to update the voice state of the bot from the Manager.
type UDPConn ¶
type UDPConn interface { // LocalAddr returns the local network address, if known. LocalAddr() net.Addr // RemoteAddr returns the remote network address, if known. RemoteAddr() net.Addr // SetSecretKey sets the secret key used to encrypt packets. SetSecretKey(secretKey [32]byte) SetDeadline(t time.Time) error // SetReadDeadline sets the read deadline for the UDPConn connection. SetReadDeadline(t time.Time) error // SetWriteDeadline sets the write deadline for the UDPConn connection. SetWriteDeadline(t time.Time) error // Open opens the UDPConn connection. Open(ctx context.Context, ip string, port int, ssrc uint32) (string, int, error) // Close closes the UDPConn connection. Close() error // Read reads a packet from the UDPConn connection. This implements the io.Reader interface. Read(p []byte) (int, error) // ReadPacket reads a packet from the UDPConn connection. ReadPacket() (*Packet, error) // Write writes a packet to the UDPConn connection. This implements the io.Writer interface. Write(p []byte) (int, error) }
UDPConn represents a UDP connection to discord voice servers. It is used to send/receive voice packets to/from discord. It implements the io.Reader, io.Writer and io.Closer interface.
func NewUDPConn ¶
func NewUDPConn(opts ...UDPConnConfigOpt) UDPConn
NewUDPConn creates a new voice UDPConn with the given configuration.
type UDPConnConfig ¶
func DefaultUDPConnConfig ¶
func DefaultUDPConnConfig() UDPConnConfig
func (*UDPConnConfig) Apply ¶
func (c *UDPConnConfig) Apply(opts []UDPConnConfigOpt)
type UDPConnConfigOpt ¶
type UDPConnConfigOpt func(config *UDPConnConfig)
func WithUDPConnDialer ¶
func WithUDPConnDialer(dialer *net.Dialer) UDPConnConfigOpt
func WithUDPConnLogger ¶
func WithUDPConnLogger(logger log.Logger) UDPConnConfigOpt
type UDPConnCreateFunc ¶
type UDPConnCreateFunc func(opts ...UDPConnConfigOpt) UDPConn
UDPConnCreateFunc is a function that creates a UDPConn.
type UserFilterFunc ¶
type UserFilterFunc func(userID snowflake.ID) bool
UserFilterFunc is used as a filter for which users to receive audio from.