Versions in this module Expand all Collapse all v0 v0.101.0 Sep 8, 2023 v0.5.1 Aug 27, 2023 Changes in this version + type Protocol string + const ProtocolUDP v0.5.0 Aug 5, 2023 v0.4.1 Jul 7, 2023 Changes in this version + const OpusFrameSizeBytes + const OpusFrameSizeMs type GatewayMessageDataUnknown + func (m *GatewayMessageDataUnknown) UnmarshalJSON(data []byte) error + func (m GatewayMessageDataUnknown) MarshalJSON() ([]byte, error) + type OpusReader struct + func (*OpusReader) Close() + func (h *OpusReader) ProvideOpusFrame() ([]byte, error) + type OpusWriter struct + func (*OpusWriter) CleanupUser(_ snowflake.ID) + func (*OpusWriter) Close() + func (r *OpusWriter) ReceiveOpusFrame(userID snowflake.ID, packet *Packet) error v0.4.0 Jun 28, 2023 v0.3.0 Jun 11, 2023 v0.2.2 Jun 10, 2023 v0.2.1 Jun 9, 2023 v0.2.0 Jun 8, 2023 Changes in this version + const GatewayVersion + const OpusPacketHeaderSize + var ErrDecryptionFailed = errors.New("decryption failed") + var ErrGatewayAlreadyConnected = fmt.Errorf("voice gateway already connected") + var ErrGatewayNotConnected = fmt.Errorf("voice gateway not connected") + var GatewayCloseEventCodeAlreadyAuthenticated = GatewayCloseEventCode + var GatewayCloseEventCodeAuthenticationFailed = GatewayCloseEventCode + var GatewayCloseEventCodeDisconnected = GatewayCloseEventCode + var GatewayCloseEventCodeFailedDecode = GatewayCloseEventCode + var GatewayCloseEventCodeHeartbeatTimeout = GatewayCloseEventCode + var GatewayCloseEventCodeNotAuthenticated = GatewayCloseEventCode + var GatewayCloseEventCodeServerNotFound = GatewayCloseEventCode + var GatewayCloseEventCodeSessionNoLongerValid = GatewayCloseEventCode + var GatewayCloseEventCodeSessionTimeout = GatewayCloseEventCode + var GatewayCloseEventCodeUnknown = GatewayCloseEventCode + var GatewayCloseEventCodeUnknownEncryptionMode = GatewayCloseEventCode + var GatewayCloseEventCodeUnknownError = GatewayCloseEventCode + var GatewayCloseEventCodeUnknownOpcode = GatewayCloseEventCode + var GatewayCloseEventCodeUnknownProtocol = GatewayCloseEventCode + var GatewayCloseEventCodeVoiceServerCrash = GatewayCloseEventCode + var GatewayCloseEventCodes = map[int]GatewayCloseEventCode + var OpusFrameSize int64 = 20 + var OpusStreamBuffSize int64 = 4000 + var SilenceAudioFrame = []byte + type AudioReceiver interface + CleanupUser func(userID snowflake.ID) + Close func() + Open func() + func NewAudioReceiver(logger log.Logger, opusReceiver OpusFrameReceiver, conn Conn) AudioReceiver + type AudioReceiverCreateFunc func(logger log.Logger, receiver OpusFrameReceiver, connection Conn) AudioReceiver + type AudioSender interface + Close func() + Open func() + func NewAudioSender(logger log.Logger, opusProvider OpusFrameProvider, conn Conn) AudioSender + type AudioSenderCreateFunc func(logger log.Logger, provider OpusFrameProvider, conn Conn) AudioSender + type CloseHandlerFunc func(gateway Gateway, err error) + type Conn interface + ChannelID func() *snowflake.ID + Close func(ctx context.Context) + Gateway func() Gateway + GuildID func() snowflake.ID + HandleVoiceServerUpdate func(update botgateway.EventVoiceServerUpdate) + HandleVoiceStateUpdate func(update botgateway.EventVoiceStateUpdate) + Open func(ctx context.Context, channelID snowflake.ID, selfMute bool, selfDeaf bool) error + SetEventHandlerFunc func(eventHandlerFunc EventHandlerFunc) + SetOpusFrameProvider func(handler OpusFrameProvider) + SetOpusFrameReceiver func(handler OpusFrameReceiver) + SetSpeaking func(ctx context.Context, flags SpeakingFlags) error + UDP func() UDPConn + UserIDBySSRC func(ssrc uint32) snowflake.ID + func NewConn(guildID snowflake.ID, userID snowflake.ID, ...) Conn + type ConnConfig struct + AudioReceiverCreateFunc AudioReceiverCreateFunc + AudioSenderCreateFunc AudioSenderCreateFunc + EventHandlerFunc EventHandlerFunc + GatewayConfigOpts []GatewayConfigOpt + GatewayCreateFunc GatewayCreateFunc + Logger log.Logger + UDPConnConfigOpts []UDPConnConfigOpt + UDPConnCreateFunc UDPConnCreateFunc + func DefaultConnConfig() *ConnConfig + func (c *ConnConfig) Apply(opts []ConnConfigOpt) + type ConnConfigOpt func(connConfig *ConnConfig) + 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 func(guildID snowflake.ID, userID snowflake.ID, ...) Conn + type EncryptionMode string + const EncryptionModeLite + const EncryptionModeNormal + const EncryptionModeSuffix + type EventHandlerFunc func(opCode Opcode, data GatewayMessageData) + type Gateway interface + Close func() + CloseWithCode func(code int, message string) + Latency func() time.Duration + Open func(ctx context.Context, state State) error + SSRC func() uint32 + Send func(ctx context.Context, opCode Opcode, data GatewayMessageData) error + func NewGateway(eventHandlerFunc EventHandlerFunc, closeHandlerFunc CloseHandlerFunc, ...) Gateway + type GatewayCloseEventCode struct + Code int + Description string + Explanation string + Reconnect bool + func GatewayCloseEventCodeByCode(code int) GatewayCloseEventCode + type GatewayConfig struct + AutoReconnect bool + Dialer *websocket.Dialer + Logger log.Logger + func DefaultGatewayConfig() *GatewayConfig + func (c *GatewayConfig) Apply(opts []GatewayConfigOpt) + type GatewayConfigOpt func(config *GatewayConfig) + func WithGatewayAutoReconnect(autoReconnect bool) GatewayConfigOpt + func WithGatewayDialer(dialer *websocket.Dialer) GatewayConfigOpt + func WithGatewayLogger(logger log.Logger) GatewayConfigOpt + type GatewayCreateFunc func(eventHandlerFunc EventHandlerFunc, closeHandlerFunc CloseHandlerFunc, ...) Gateway + type GatewayMessage struct + D GatewayMessageData + Op Opcode + func (m *GatewayMessage) UnmarshalJSON(data []byte) error + type GatewayMessageData interface + type GatewayMessageDataClientConnect struct + AudioCodec string + UserID snowflake.ID + VideoCodec string + type GatewayMessageDataClientDisconnect struct + UserID snowflake.ID + type GatewayMessageDataHeartbeat int64 + type GatewayMessageDataHeartbeatACK int64 + type GatewayMessageDataHello struct + HeartbeatInterval float64 + type GatewayMessageDataIdentify struct + GuildID snowflake.ID + SessionID string + Token string + UserID snowflake.ID + type GatewayMessageDataReady struct + IP string + Modes []string + Port int + SSRC uint32 + type GatewayMessageDataResume struct + GuildID snowflake.ID + SessionID string + Token string + type GatewayMessageDataSelectProtocol struct + Data GatewayMessageDataSelectProtocolData + Protocol VoiceProtocol + type GatewayMessageDataSelectProtocolData struct + Address string + Mode EncryptionMode + Port int + type GatewayMessageDataSessionDescription struct + Mode string + SecretKey [32]byte + type GatewayMessageDataSpeaking struct + Delay int + SSRC uint32 + Speaking SpeakingFlags + UserID snowflake.ID + type GatewayMessageDataUnknown json.RawMessage + type Manager interface + Close func(ctx context.Context) + CreateConn func(guildID snowflake.ID) Conn + ForEachCon func(f func(connection Conn)) + GetConn func(guildID snowflake.ID) Conn + HandleVoiceServerUpdate func(update gateway.EventVoiceServerUpdate) + HandleVoiceStateUpdate func(update gateway.EventVoiceStateUpdate) + RemoveConn func(guildID snowflake.ID) + func NewManager(voiceStateUpdateFunc StateUpdateFunc, userID snowflake.ID, ...) Manager + type ManagerConfig struct + ConnCreateFunc ConnCreateFunc + ConnOpts []ConnConfigOpt + Logger log.Logger + func DefaultManagerConfig() *ManagerConfig + func (c *ManagerConfig) Apply(opts []ManagerConfigOpt) + type ManagerConfigOpt func(ManagerConfig *ManagerConfig) + func WithConnConfigOpts(opts ...ConnConfigOpt) ManagerConfigOpt + func WithConnCreateFunc(connectionCreateFunc ConnCreateFunc) ManagerConfigOpt + func WithLogger(logger log.Logger) ManagerConfigOpt + type Opcode int + const OpcodeClientDisconnect + const OpcodeGuildSync + const OpcodeHeartbeat + const OpcodeHeartbeatACK + const OpcodeHello + const OpcodeIdentify + const OpcodeReady + const OpcodeResume + const OpcodeResumed + const OpcodeSelectProtocol + const OpcodeSessionDescription + const OpcodeSpeaking + type OpusFrameProvider interface + Close func() + ProvideOpusFrame func() ([]byte, error) + func NewOpusReader(r io.Reader) OpusFrameProvider + type OpusFrameReceiver interface + CleanupUser func(userID snowflake.ID) + Close func() + ReceiveOpusFrame func(userID snowflake.ID, packet *Packet) error + func NewOpusWriter(w io.Writer, userFilter UserFilterFunc) OpusFrameReceiver + type Packet struct + Opus []byte + SSRC uint32 + Sequence uint16 + Timestamp uint32 + type SpeakingFlags int + const SpeakingFlagMicrophone + const SpeakingFlagNone + const SpeakingFlagPriority + const SpeakingFlagSoundshare + type State struct + ChannelID *snowflake.ID + Endpoint string + GuildID snowflake.ID + SessionID string + Token string + UserID snowflake.ID + type StateProviderFunc func() State + type StateUpdateFunc func(ctx context.Context, guildID snowflake.ID, channelID *snowflake.ID, ...) error + type Status int + const StatusConnecting + const StatusDisconnected + const StatusIdentifying + const StatusReady + const StatusResuming + const StatusUnconnected + const StatusWaitingForHello + const StatusWaitingForReady + type UDPConn interface + Close func() error + LocalAddr func() net.Addr + Open func(ctx context.Context, ip string, port int, ssrc uint32) (string, int, error) + Read func(p []byte) (int, error) + ReadPacket func() (*Packet, error) + RemoteAddr func() net.Addr + SetDeadline func(t time.Time) error + SetReadDeadline func(t time.Time) error + SetSecretKey func(secretKey [32]byte) + SetWriteDeadline func(t time.Time) error + Write func(p []byte) (int, error) + func NewUDPConn(opts ...UDPConnConfigOpt) UDPConn + type UDPConnConfig struct + Dialer *net.Dialer + Logger log.Logger + func DefaultUDPConnConfig() UDPConnConfig + func (c *UDPConnConfig) Apply(opts []UDPConnConfigOpt) + type UDPConnConfigOpt func(config *UDPConnConfig) + func WithUDPConnDialer(dialer *net.Dialer) UDPConnConfigOpt + func WithUDPConnLogger(logger log.Logger) UDPConnConfigOpt + type UDPConnCreateFunc func(opts ...UDPConnConfigOpt) UDPConn + type UserFilterFunc func(userID snowflake.ID) bool + type VoiceProtocol string + const VoiceProtocolUDP