voice

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

WIP

Documentation

Index

Constants

View Source
const (
	// Discord normal
	SessionNoLongerValid websocket.StatusCode = 4006
	SessionTimeout       websocket.StatusCode = 4009
	Disconnected         websocket.StatusCode = 4014
	ServerCrashed        websocket.StatusCode = 4015

	// Discord abnormal
	UnknownOPCode         websocket.StatusCode = 4001
	FailedToDecodePayload websocket.StatusCode = 4002
	NotAuthenticated      websocket.StatusCode = 4003
	AuthenticationFailed  websocket.StatusCode = 4004
	AlreadyAuthenticated  websocket.StatusCode = 4005
	ServerNotFound        websocket.StatusCode = 4011
	UnknownProtocol       websocket.StatusCode = 4012
	UnknownEncryption     websocket.StatusCode = 4016

	BfcordVoiceReconnect websocket.StatusCode = 4969
)

Variables

View Source
var (
	GatewayMissingValuesError = errors.New("some of the required values required to start connection are missing")
	ConnectionClosedError     = errors.New("connection is closed")
	UDPHolepunchFailed        = errors.New("failed to perform UDP holepunch in 10 tries")
	NotConnected              = errors.New("session is not yet connected, or is reconnecting")
)

Functions

This section is empty.

Types

type ConnectOptions

type ConnectOptions struct {
	VoiceState  *gateway.VoiceStateUpdateEvent
	VoiceServer *gateway.VoiceServerUpdateEvent
	ChannelID   snowflake.ID
	GuildID     snowflake.ID
	Debug       bool
	OnClose     func()
}

type IdentifyPayload

type IdentifyPayload struct {
	SessionID string       `json:"session_id"`
	Token     string       `json:"token"`
	ServerID  snowflake.ID `json:"server_id"`
	UserID    snowflake.ID `json:"user_id"`
}

type OPCode

type OPCode uint8

type Payload

type Payload struct {
	Data json.RawMessage `json:"d"`
	Op   OPCode          `json:"op"`
}

type ReadyPayload

type ReadyPayload struct {
	IP    string   `json:"IP"`
	Modes []string `json:"modes"`
	SSRC  uint32   `json:"ssrc"`
	Port  uint16   `json:"port"`
}

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(ctx context.Context, opts ConnectOptions) (*Session, error)

NewSession function creates new session and issues first connection. Blocks until connection is finished (or until timeout occurs)

func (*Session) Destroy

func (s *Session) Destroy()

Destroy method disconnects session from discord. Using SendOpusFrame after destroying will throw errors.

func (*Session) IsClosed

func (s *Session) IsClosed() bool

IsClosed will return true if session is fully closed.

func (*Session) SendOpusFrame

func (s *Session) SendOpusFrame(frame []byte) error

SendOpusFrame method writes raw audio frame to discord.

Frame MUST be 20ms in length. We may allow changing the value later if needed.

This method should not be used concurrently, as it will cause audio overlapping.

Will throw ConnectionClosedError if connection is closed permanently.

func (*Session) SendSpeaking

func (s *Session) SendSpeaking(flags SpeakingFlag) error

SendSpeaking method sends speaking flags to discord.

It's automatically invoked during (re)connection.

Will throw an error if connection is not yet finished.

type SpeakingFlag

type SpeakingFlag uint64
const (
	NotSpeaking SpeakingFlag = 0
	Microphone  SpeakingFlag = 1 << iota
	SoundShare
	Priority
)

Jump to

Keyboard shortcuts

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