voicegateway

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: ISC Imports: 11 Imported by: 2

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 Gateway

type Gateway struct {
	Timeout time.Duration

	EventLoop *wsutil.PacemakerLoop

	// 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 (c *Gateway) Close() error

Close .

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

func (c *Gateway) Identify() error

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

func (*Gateway) Open

func (c *Gateway) Open() error

Open 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) Resume

func (c *Gateway) Resume() error

Resume 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) Send

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

Send .

func (*Gateway) SessionDescription

func (c *Gateway) SessionDescription(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.

type HelloEvent

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

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

type IdentifyData

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

OPCode 0 https://discordapp.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

)

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://discordapp.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.Snowflake `json:"server_id"` // yes, this should be "server_id"
	SessionID string            `json:"session_id"`
	Token     string            `json:"token"`
}

OPCode 7 https://discordapp.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 SpeakingData

type SpeakingData struct {
	Speaking SpeakingFlag `json:"speaking"`
	Delay    int          `json:"delay"`
	SSRC     uint32       `json:"ssrc"`
}

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

type SpeakingEvent

type SpeakingEvent SpeakingData

OPCode 5

type SpeakingFlag

type SpeakingFlag uint64

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

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

type State

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

	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