Documentation ¶
Index ¶
- Constants
- Variables
- type ClientConnectEvent
- type ClientDisconnectEvent
- type Event
- type Gateway
- func (g *Gateway) Close() error
- func (c *Gateway) HandleOP(op *wsutil.OP) error
- func (c *Gateway) Heartbeat() error
- func (c *Gateway) HeartbeatCtx(ctx context.Context) error
- func (c *Gateway) Identify() error
- func (c *Gateway) IdentifyCtx(ctx context.Context) error
- func (c *Gateway) OpenCtx(ctx context.Context) error
- func (c *Gateway) Ready() ReadyEvent
- func (c *Gateway) Reconnect() error
- func (c *Gateway) ReconnectCtx(ctx context.Context) error
- func (c *Gateway) Resume() error
- func (c *Gateway) ResumeCtx(ctx context.Context) error
- func (c *Gateway) SelectProtocol(data SelectProtocol) error
- func (c *Gateway) SelectProtocolCtx(ctx context.Context, data SelectProtocol) error
- func (c *Gateway) Send(code OPCode, v interface{}) error
- func (c *Gateway) SendCtx(ctx context.Context, code OPCode, v interface{}) error
- func (c *Gateway) SessionDescriptionCtx(ctx context.Context, sp SelectProtocol) (*SessionDescriptionEvent, error)
- func (c *Gateway) Speaking(flag SpeakingFlag) error
- func (c *Gateway) SpeakingCtx(ctx context.Context, flag SpeakingFlag) error
- type HeartbeatACKEvent
- type HelloEvent
- type IdentifyData
- type OPCode
- type ReadyEvent
- type ResumeData
- type ResumedEvent
- type SelectProtocol
- type SelectProtocolData
- type SessionDescriptionEvent
- type SpeakingData
- type SpeakingEvent
- type SpeakingFlag
- type State
Constants ¶
const (
// Version represents the current version of the Discord Gateway Gateway this package uses.
Version = "4"
)
Variables ¶
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") )
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 ¶
OPCode 13 Undocumented, existence mentioned in below issue https://github.com/discord/discord-api-docs/issues/510
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 (*Gateway) Heartbeat ¶
Heartbeat sends a Heartbeat operation (opcode 3) to the Gateway Gateway.
func (*Gateway) HeartbeatCtx ¶
HeartbeatCtx sends a Heartbeat operation (opcode 3) to the Gateway Gateway.
func (*Gateway) IdentifyCtx ¶
IdentifyCtx sends an Identify operation (opcode 0) 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) 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 HeartbeatACKEvent ¶
type HeartbeatACKEvent uint64
type HelloEvent ¶
type HelloEvent struct {
HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`
}
type IdentifyData ¶
type 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"` }
func (ReadyEvent) Addr ¶
func (r ReadyEvent) Addr() string
type ResumeData ¶
type ResumedEvent ¶
type ResumedEvent struct{}
type SelectProtocol ¶
type SelectProtocol struct { Protocol string `json:"protocol"` Data SelectProtocolData `json:"data"` }
type SelectProtocolData ¶
type SessionDescriptionEvent ¶
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 SpeakingFlag ¶
type SpeakingFlag uint64
https://discord.com/developers/docs/topics/voice-connections#speaking
const ( NotSpeaking SpeakingFlag = 0 Microphone SpeakingFlag = 1 << iota Priority )