Documentation
¶
Index ¶
Constants ¶
const ( // OpusFrameSize is the size of an opus frame in bytes. OpusFrameSize = 960 // OpusFrameSizeBytes is the size of an opus frame in bytes. OpusFrameSizeBytes = OpusFrameSize * 2 * 2 )
Variables ¶
var ErrLiveKitNotConnected = errors.New("livekit not connected")
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface {
LiveKit() LiveKitConn
// 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
// 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) 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 gateway.EventVoiceStateUpdate)
// HandleVoiceServerUpdate provides the gateway.EventVoiceServerUpdate to the voice conn. Which is needed to connect to the voice Gateway.
HandleVoiceServerUpdate(update gateway.EventVoiceServerUpdate)
}
Conn is a complete voice conn to fluxer. It holds the Gateway and voiceudp.UDPConn conn and combines them.
func NewConn ¶
func NewConn(liveKitCon LiveKitConn, guildID snowflake.ID, userID snowflake.ID, voiceStateUpdateFunc StateUpdateFunc, removeConnFunc func(), opts ...ConnConfigOpt) Conn
NewConn returns a new default voice conn.
type ConnConfigOpt ¶
type ConnConfigOpt func(config *connConfig)
ConnConfigOpt is used to functionally configure a connConfig.
func WithConnLogger ¶
func WithConnLogger(logger *slog.Logger) ConnConfigOpt
WithConnLogger sets the Conn(s) used Logger.
type ConnCreateFunc ¶
type ConnCreateFunc func(liveKitCon LiveKitConn, 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 LiveKitConn ¶
type LiveKitConn interface {
Open(state State) error
Close()
Status() Status
AudioWriter(name string, source AudioSource) (io.WriteCloser, error)
VideoWriter(name string, source VideoSource, width int, height int, fps int) (io.WriteCloser, error)
}
type LiveKitConnCreateFunc ¶
type LiveKitConnCreateFunc func() LiveKitConn
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
// Conns returns all voice connections. This function is thread-safe.
Conns() iter.Seq[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 ManagerConfigOpt ¶
type ManagerConfigOpt func(config *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 WithLiveKitConnCreateFunc ¶
func WithLiveKitConnCreateFunc(liveKitConnCreateFunc LiveKitConnCreateFunc) ManagerConfigOpt
func WithLogger ¶
func WithLogger(logger *slog.Logger) ManagerConfigOpt
WithLogger sets the logger for the webhook client.
type OpusReader ¶
type OpusReader struct {
// contains filtered or unexported fields
}
OpusReader is an OpusFrameProvider that reads opus frames from the given io.Reader. Each opus frame is prefixed with a 4 byte little endian uint32 that represents the length of the frame.
func NewOpusReader ¶
func NewOpusReader(r io.Reader) *OpusReader
NewOpusReader returns a new OpusFrameProvider that reads opus frames from the given io.Reader.
func (*OpusReader) ProvideOpusFrame ¶
func (h *OpusReader) ProvideOpusFrame() ([]byte, error)
ProvideOpusFrame reads the next opus frame from the underlying io.Reader.
type OpusWriter ¶
type OpusWriter struct {
// contains filtered or unexported fields
}
OpusWriter is an OpusFrameReceiver that writes opus frames to the given io.Writer. Each opus frame is prefixed with a 4 byte little endian uint32 that represents the length of the frame.
func NewOpusWriter ¶
func NewOpusWriter(w io.Writer, userFilter UserFilterFunc) *OpusWriter
NewOpusWriter returns a new OpusFrameReceiver that writes opus frames to the given io.Writer.
func (*OpusWriter) CleanupUser ¶
func (*OpusWriter) CleanupUser(_ snowflake.ID)
CleanupUser is a no-op.
func (*OpusWriter) ReceiveOpusFrame ¶
func (r *OpusWriter) ReceiveOpusFrame(userID snowflake.ID, packet *Packet) error
ReceiveOpusFrame writes the given opus frame to the underlying io.Writer.
type Packet ¶
type Packet struct {
Type byte
// 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
HasExtension bool
ExtensionID int
Extension []byte
CSRC []uint32
HeaderSize int
// Opus is the actual opus data of the packet.
Opus []byte
}
type StateUpdateFunc ¶
type StateUpdateFunc func(ctx context.Context, data gateway.MessageDataVoiceStateUpdate) error
StateUpdateFunc is used to update the voice state of the bot from the Manager.
type UserFilterFunc ¶
UserFilterFunc is used as a filter for which users to receive audio from.