Documentation ¶
Index ¶
- Constants
- Variables
- type ClientConnectEvent
- type ClientDisconnectEvent
- type Gateway
- type HeartbeatAckEvent
- type HeartbeatCommand
- type HelloEvent
- type IdentifyCommand
- type ReadyEvent
- type ResumeCommand
- type ResumedEvent
- type SelectProtocolCommand
- type SelectProtocolData
- type SessionDescriptionEvent
- type SpeakingEvent
- type SpeakingFlag
- type State
Constants ¶
const Version = "4"
Version represents the current version of the Discord Gateway Gateway this package uses.
Variables ¶
var ( ErrNoSessionID = errors.New("no sessionID was received") ErrNoEndpoint = errors.New("no endpoint was received") )
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 DefaultGatewayOpts = ws.GatewayOpts{ ReconnectDelay: func(try int) time.Duration { return time.Duration(4+(2*try)) * time.Second }, FatalCloseCodes: []int{ 4003, 4004, 4006, 4009, 4011, 4012, 4014, 4016, }, DialTimeout: 0, ReconnectAttempt: 0, AlwaysCloseGracefully: true, }
DefaultGatewayOpts contains the default options to be used for connecting to the gateway.
var OpUnmarshalers = ws.NewOpUnmarshalers()
OpUnmarshalers contains the Op unmarshalers for the voice gateway events.
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"` }
ClientConnectEvent is an event for Op 12. It is undocumented.
func (*ClientConnectEvent) EventType ¶
func (*ClientConnectEvent) EventType() ws.EventType
EventType implements Event.
func (*ClientConnectEvent) Op ¶
func (*ClientConnectEvent) Op() ws.OpCode
Op implements Event. It always returns Op 12.
type ClientDisconnectEvent ¶
ClientDisconnectEvent is an event for Op 13. It is undocumented, but its existence is mentioned in this issue: https://github.com/discord/discord-api-docs/issues/510.
func (*ClientDisconnectEvent) EventType ¶
func (*ClientDisconnectEvent) EventType() ws.EventType
EventType implements Event.
func (*ClientDisconnectEvent) Op ¶
func (*ClientDisconnectEvent) Op() ws.OpCode
Op implements Event. It always returns Op 13.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway represents a Discord Gateway Gateway connection.
func (*Gateway) LastError ¶
LastError returns the last error that the gateway has received. It only returns a valid error if the gateway's event loop as exited. If the event loop hasn't been started AND stopped, the function will panic.
type HeartbeatAckEvent ¶
type HeartbeatAckEvent uint64
HeartbeatAckEvent is an event for Op 6.
func (*HeartbeatAckEvent) EventType ¶
func (*HeartbeatAckEvent) EventType() ws.EventType
EventType implements Event.
func (*HeartbeatAckEvent) Op ¶
func (*HeartbeatAckEvent) Op() ws.OpCode
Op implements Event. It always returns Op 6.
type HeartbeatCommand ¶
type HeartbeatCommand uint64
HeartbeatCommand is a command for Op 3.
https://discord.com/developers/docs/topics/voice-connections#heartbeating-example-heartbeat-payload
func (*HeartbeatCommand) EventType ¶
func (*HeartbeatCommand) EventType() ws.EventType
EventType implements Event.
func (*HeartbeatCommand) Op ¶
func (*HeartbeatCommand) Op() ws.OpCode
Op implements Event. It always returns Op 3.
type HelloEvent ¶
type HelloEvent struct {
HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`
}
HelloEvent is an event for Op 8.
func (*HelloEvent) EventType ¶
func (*HelloEvent) EventType() ws.EventType
EventType implements Event.
func (*HelloEvent) Op ¶
func (*HelloEvent) Op() ws.OpCode
Op implements Event. It always returns Op 8.
type IdentifyCommand ¶
type IdentifyCommand 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"` }
IdentifyCommand is a command for Op 0.
func (*IdentifyCommand) EventType ¶
func (*IdentifyCommand) EventType() ws.EventType
EventType implements Event.
func (*IdentifyCommand) Op ¶
func (*IdentifyCommand) Op() ws.OpCode
Op implements Event. It always returns Op 0.
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"` }
ReadyEvent is an event for Op 2.
func (ReadyEvent) Addr ¶
func (r ReadyEvent) Addr() string
Addr formats the URL inside Ready to be of format "host:port".
func (*ReadyEvent) EventType ¶
func (*ReadyEvent) EventType() ws.EventType
EventType implements Event.
func (*ReadyEvent) Op ¶
func (*ReadyEvent) Op() ws.OpCode
Op implements Event. It always returns Op 2.
type ResumeCommand ¶
type ResumeCommand struct { GuildID discord.GuildID `json:"server_id"` // yes, this should be "server_id" SessionID string `json:"session_id"` Token string `json:"token"` }
ResumeCommand is a command for Op 7.
func (*ResumeCommand) EventType ¶
func (*ResumeCommand) EventType() ws.EventType
EventType implements Event.
func (*ResumeCommand) Op ¶
func (*ResumeCommand) Op() ws.OpCode
Op implements Event. It always returns Op 7.
type ResumedEvent ¶
type ResumedEvent struct{}
ResumedEvent is an event for Op 9. https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection-example-resumed-payload
func (*ResumedEvent) EventType ¶
func (*ResumedEvent) EventType() ws.EventType
EventType implements Event.
func (*ResumedEvent) Op ¶
func (*ResumedEvent) Op() ws.OpCode
Op implements Event. It always returns Op 9.
type SelectProtocolCommand ¶
type SelectProtocolCommand struct { Protocol string `json:"protocol"` Data SelectProtocolData `json:"data"` }
SelectProtocolCommand is a command for Op 1.
func (*SelectProtocolCommand) EventType ¶
func (*SelectProtocolCommand) EventType() ws.EventType
EventType implements Event.
func (*SelectProtocolCommand) Op ¶
func (*SelectProtocolCommand) Op() ws.OpCode
Op implements Event. It always returns Op 1.
type SelectProtocolData ¶
type SelectProtocolData struct { Address string `json:"address"` Port uint16 `json:"port"` Mode string `json:"mode"` }
SelectProtocolData is the data inside a SelectProtocolCommand.
type SessionDescriptionEvent ¶
type SessionDescriptionEvent struct { Mode string `json:"mode"` SecretKey [32]byte `json:"secret_key"` }
SessionDescriptionEvent is an event for Op 4.
func (*SessionDescriptionEvent) EventType ¶
func (*SessionDescriptionEvent) EventType() ws.EventType
EventType implements Event.
func (*SessionDescriptionEvent) Op ¶
func (*SessionDescriptionEvent) Op() ws.OpCode
Op implements Event. It always returns Op 4.
type SpeakingEvent ¶
type SpeakingEvent struct { Speaking SpeakingFlag `json:"speaking"` Delay int `json:"delay"` SSRC uint32 `json:"ssrc"` UserID discord.UserID `json:"user_id,omitempty"` }
SpeakingEvent is an event for Op 5. It is also a command.
https://discord.com/developers/docs/topics/voice-connections#speaking-example-speaking-payload
func (*SpeakingEvent) EventType ¶
func (*SpeakingEvent) EventType() ws.EventType
EventType implements Event.
func (*SpeakingEvent) Op ¶
func (*SpeakingEvent) Op() ws.OpCode
Op implements Event. It always returns Op 5.
type SpeakingFlag ¶
type SpeakingFlag uint64
https://discord.com/developers/docs/topics/voice-connections#speaking
const ( Microphone SpeakingFlag = 1 << iota Priority )
const NotSpeaking SpeakingFlag = 0