voice

package
v0.0.0-...-9338f50 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
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

View Source
var ErrLiveKitNotConnected = errors.New("livekit not connected")

Functions

This section is empty.

Types

type AudioSource

type AudioSource int
const (
	AudioSourceMicrophone AudioSource = iota
	AudioSourceScreenShare
)

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

func (*OpusReader) Close()

Close is a no-op.

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

func (*OpusWriter) Close()

Close 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 State

type State struct {
	GuildID   snowflake.ID
	UserID    snowflake.ID
	ChannelID *snowflake.ID

	SessionID    string
	Token        string
	ConnectionID string
	Endpoint     string
}

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 Status

type Status int

Status returns the current status of the gateway.

const (
	StatusDisconnected Status = iota
	StatusConnecting
	StatusConnected
)

type UserFilterFunc

type UserFilterFunc func(userID snowflake.ID) bool

UserFilterFunc is used as a filter for which users to receive audio from.

type VideoSource

type VideoSource int
const (
	VideoSourceCamera VideoSource = iota
	VideoSourceScreenShare
)

Jump to

Keyboard shortcuts

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