voice

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SilenceFrame = []byte{0xf8, 0xff, 0xfe}

Five silence frames should be sent when there is a break in the sent data. See https://discord.com/developers/docs/topics/voice-connections#voice-data-interpolation for more information.

Functions

This section is empty.

Types

type AudioPacket

type AudioPacket struct {
	Type      uint8
	Version   uint8
	Sequence  uint16
	Timestamp uint32
	SSRC      uint32
	Opus      []byte
}

AudioPacket is a parsed and decrypted RTP frame containing Opus encoded audio.

type Connection

type Connection struct {
	// Send is used to send Opus encoded audio packets.
	Send chan []byte
	// Recv is used to receive audio packets
	// containing Opus encoded audio data.
	Recv chan *AudioPacket
	// contains filtered or unexported fields
}

Connection represents a Discord voice connection.

func Connect added in v0.16.0

func Connect(ctx context.Context, state *StateUpdate, server *ServerUpdate, opts ...ConnectionOption) (*Connection, error)

Connect establishes a new voice connection with the provided information. It will automatically try to reconnect and resume if network failures occur. Further StateUpdate and ServerUpdate should be forwarded to the returned connection using its SetState and UpdateServer method. Not doing so will likely result in out-of-sync voice connections that can be in incoherent state or that do not handle voice server update events. This connection should be closed by calling its Close method when no longer needed.

func (*Connection) Close

func (vc *Connection) Close()

Disconnect closes the voice connection.

func (*Connection) Logger

func (vc *Connection) Logger() log.Logger

Logger is here to make the logger available to third party packages that need to report errors related to this voice connection.

func (*Connection) SetSpeakingMode added in v0.16.0

func (vc *Connection) SetSpeakingMode(mode SpeakingMode) error

SetSpeakingMode sends an Opcode 5 Speaking payload. This does nothing if the user is already in the given state.

func (*Connection) SetState added in v0.16.0

func (vc *Connection) SetState(s *State)

SetState updates the state for this voice connections.

func (*Connection) State added in v0.16.0

func (vc *Connection) State() *State

State returns the current state of this voice connection.

func (*Connection) UpdateServer added in v0.16.0

func (vc *Connection) UpdateServer(server *ServerUpdate) error

UpdateServer updates the voice server this connection is using. This closes the connection to the old server and establishes a new connection to the updated server.

type ConnectionOption

type ConnectionOption func(*Connection)

ConnectionOption is a function that configures a Connection. It is used in Connect.

func WithLogger

func WithLogger(l log.Logger) ConnectionOption

WithLogger can be used to set the logger used by this connection. Defaults to a standard logger reporting only errors. See the log package for more information about logging with Harmony.

type ServerUpdate

type ServerUpdate struct {
	Token    string `json:"token"`
	GuildID  string `json:"guild_id"`
	Endpoint string `json:"endpoint"`
}

ServerUpdate is the payload describing the update of a voice server.

type SpeakingMode added in v0.16.0

type SpeakingMode uint32

SpeakingMode is the type for modes that can be used as a bitwise mask for SetSpeakingMode.

const (
	// Normal transmission of voice audio.
	SpeakingModeMicrophone SpeakingMode = 1 << 0
	// Transmission of context audio for video, no speaking indicator.
	SpeakingModeSoundshare SpeakingMode = 1 << 1
	// Priority speaker, lowering audio of other speakers.
	SpeakingModePriority SpeakingMode = 1 << 2
	// No audio transmission.
	SpeakingModeOff SpeakingMode = 0
)

type State

type State struct {
	GuildID    string  `json:"guild_id"`
	ChannelID  *string `json:"channel_id"`
	UserID     string  `json:"user_id"`
	SessionID  string  `json:"session_id"`
	Deaf       bool    `json:"deaf"`
	Mute       bool    `json:"mute"`
	SelfDeaf   bool    `json:"self_deaf"`
	SelfMute   bool    `json:"self_mute"`
	SelfStream bool    `json:"self_stream"`
	Suppress   bool    `json:"suppress"` // Whether this user is muted by the current user.
}

State represents the voice state of a user.

func (*State) Clone

func (v *State) Clone() *State

Clone returns a clone of this StateUpdate.

type StateUpdate

type StateUpdate struct {
	State
}

StateUpdate is the payload describing the update of the voice state of a user.

Directories

Path Synopsis
Package voiceutil provides utilities to work with harmony voice connections.
Package voiceutil provides utilities to work with harmony voice connections.

Jump to

Keyboard shortcuts

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