voicegateway

package
v3.0.0-...-04a954d Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: ISC Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Version represents the current version of the Discord Gateway Gateway this package uses.
	Version = "4"
)

Variables

View Source
var (
	// ErrMissingForIdentify is an error when we are missing information to identify.
	ErrMissingForIdentify = errors.New("missing GuildID, UserID, SessionID, or Token for identify")

	// ErrMissingForResume is an error when we are missing information to resume.
	ErrMissingForResume = errors.New("missing GuildID, SessionID, or Token for resuming")
)
View Source
var (
	ErrNoSessionID = errors.New("no sessionID was received")
	ErrNoEndpoint  = errors.New("no endpoint was received")
)

Functions

This section is empty.

Types

type ClientConnectEvent

type ClientConnectEvent struct {
	UserID    discord.UserID `json:"user_id"`
	AudioSSRC uint32         `json:"audio_ssrc"`
	VideoSSRC uint32         `json:"video_ssrc"`
}

OPCode 12 (undocumented)

type ClientDisconnectEvent

type ClientDisconnectEvent struct {
	UserID discord.UserID `json:"user_id"`
}

OPCode 13 Undocumented, existence mentioned in below issue https://github.com/discord/discord-api-docs/issues/510

type Event

type Event = interface{}

type Gateway

type Gateway struct {
	WS *wsutil.Websocket

	Timeout time.Duration

	EventLoop wsutil.PacemakerLoop
	Events    chan Event

	// ErrorLog will be called when an error occurs (defaults to log.Println)
	ErrorLog func(err error)
	// AfterClose is called after each close. Error can be non-nil, as this is
	// called even when the Gateway is gracefully closed. It's used mainly for
	// reconnections or any type of connection interruptions. (defaults to noop)
	AfterClose func(err error)
	// contains filtered or unexported fields
}

Gateway represents a Discord Gateway Gateway connection.

func New

func New(state State) *Gateway

func (*Gateway) Close

func (g *Gateway) Close() error

Close closes the underlying Websocket connection.

func (*Gateway) HandleOP

func (c *Gateway) HandleOP(op *wsutil.OP) error

func (*Gateway) Heartbeat

func (c *Gateway) Heartbeat() error

Heartbeat sends a Heartbeat operation (opcode 3) to the Gateway Gateway.

func (*Gateway) HeartbeatCtx

func (c *Gateway) HeartbeatCtx(ctx context.Context) error

HeartbeatCtx sends a Heartbeat operation (opcode 3) to the Gateway Gateway.

func (*Gateway) Identify

func (c *Gateway) Identify() error

Identify sends an Identify operation (opcode 0) to the Gateway Gateway.

func (*Gateway) IdentifyCtx

func (c *Gateway) IdentifyCtx(ctx context.Context) error

IdentifyCtx sends an Identify operation (opcode 0) to the Gateway Gateway.

func (*Gateway) OpenCtx

func (c *Gateway) OpenCtx(ctx context.Context) error

OpenCtx shouldn't be used, but JoinServer instead.

func (*Gateway) Ready

func (c *Gateway) Ready() ReadyEvent

TODO: get rid of

func (*Gateway) Reconnect

func (c *Gateway) Reconnect() error

func (*Gateway) ReconnectCtx

func (c *Gateway) ReconnectCtx(ctx context.Context) error

func (*Gateway) Resume

func (c *Gateway) Resume() error

Resume sends a Resume operation (opcode 7) to the Gateway Gateway.

func (*Gateway) ResumeCtx

func (c *Gateway) ResumeCtx(ctx context.Context) error

ResumeCtx sends a Resume operation (opcode 7) to the Gateway Gateway.

func (*Gateway) SelectProtocol

func (c *Gateway) SelectProtocol(data SelectProtocol) error

SelectProtocol sends a Select Protocol operation (opcode 1) to the Gateway Gateway.

func (*Gateway) SelectProtocolCtx

func (c *Gateway) SelectProtocolCtx(ctx context.Context, data SelectProtocol) error

SelectProtocolCtx sends a Select Protocol operation (opcode 1) to the Gateway Gateway.

func (*Gateway) Send

func (c *Gateway) Send(code OPCode, v interface{}) error

Send sends a payload to the Gateway with the default timeout.

func (*Gateway) SendCtx

func (c *Gateway) SendCtx(ctx context.Context, code OPCode, v interface{}) error

func (*Gateway) SessionDescriptionCtx

func (c *Gateway) SessionDescriptionCtx(
	ctx context.Context, sp SelectProtocol) (*SessionDescriptionEvent, error)

func (*Gateway) Speaking

func (c *Gateway) Speaking(flag SpeakingFlag) error

Speaking sends a Speaking operation (opcode 5) to the Gateway Gateway.

func (*Gateway) SpeakingCtx

func (c *Gateway) SpeakingCtx(ctx context.Context, flag SpeakingFlag) error

SpeakingCtx sends a Speaking operation (opcode 5) to the Gateway Gateway.

type HelloEvent

type HelloEvent struct {
	HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`
}

OPCode 8 https://discord.com/developers/docs/topics/voice-connections#heartbeating-example-hello-payload-since-v3

type IdentifyData

type IdentifyData struct {
	GuildID   discord.GuildID `json:"server_id"` // yes, this should be "server_id"
	UserID    discord.UserID  `json:"user_id"`
	SessionID string          `json:"session_id"`
	Token     string          `json:"token"`
}

OPCode 0 https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-identify-payload

type OPCode

type OPCode = wsutil.OPCode

OPCode represents a Discord Gateway Gateway operation code.

const (
	IdentifyOP           OPCode = 0  // send
	SelectProtocolOP     OPCode = 1  // send
	ReadyOP              OPCode = 2  // receive
	HeartbeatOP          OPCode = 3  // send
	SessionDescriptionOP OPCode = 4  // receive
	SpeakingOP           OPCode = 5  // send/receive
	HeartbeatAckOP       OPCode = 6  // receive
	ResumeOP             OPCode = 7  // send
	HelloOP              OPCode = 8  // receive
	ResumedOP            OPCode = 9  // receive
	ClientConnectOP      OPCode = 12 // receive
	ClientDisconnectOP   OPCode = 13 // receive
)

type ReadyEvent

type ReadyEvent struct {
	SSRC        uint32   `json:"ssrc"`
	IP          string   `json:"ip"`
	Port        int      `json:"port"`
	Modes       []string `json:"modes"`
	Experiments []string `json:"experiments"`
}

OPCode 2 https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-ready-payload

func (ReadyEvent) Addr

func (r ReadyEvent) Addr() string

type ResumeData

type ResumeData struct {
	GuildID   discord.GuildID `json:"server_id"` // yes, this should be "server_id"
	SessionID string          `json:"session_id"`
	Token     string          `json:"token"`
}

OPCode 7 https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection-example-resume-connection-payload

type SelectProtocolData

type SelectProtocolData struct {
	Address string `json:"address"`
	Port    uint16 `json:"port"`
	Mode    string `json:"mode"`
}

type SessionDescriptionEvent

type SessionDescriptionEvent struct {
	Mode      string   `json:"mode"`
	SecretKey [32]byte `json:"secret_key"`
}

OPCode 4 https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-example-session-description-payload

type SpeakingData

type SpeakingData struct {
	Speaking SpeakingFlag   `json:"speaking"`
	Delay    int            `json:"delay"`
	SSRC     uint32         `json:"ssrc"`
	UserID   discord.UserID `json:"user_id,omitempty"`
}

OPCode 5 https://discord.com/developers/docs/topics/voice-connections#speaking-example-speaking-payload

type SpeakingEvent

type SpeakingEvent SpeakingData

OPCode 5

type SpeakingFlag

type SpeakingFlag uint64

https://discord.com/developers/docs/topics/voice-connections#speaking

const (
	NotSpeaking SpeakingFlag = 0
	Microphone  SpeakingFlag = 1 << iota
	Soundshare
	Priority
)

type State

type State struct {
	GuildID   discord.GuildID
	ChannelID discord.ChannelID
	UserID    discord.UserID

	SessionID string
	Token     string
	Endpoint  string
}

State contains state information of a voice gateway.

Jump to

Keyboard shortcuts

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