voicegateway

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: ISC Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "4"

Version represents the current version of the Discord Gateway Gateway this package uses.

Variables

View Source
var (
	ErrNoSessionID = errors.New("no sessionID was received")
	ErrNoEndpoint  = errors.New("no endpoint was received")
)
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 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.

View Source
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

Op implements Event. It always returns Op 12.

type ClientDisconnectEvent

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

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

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 New

func New(state State) *Gateway

New creates a new voice gateway.

func (*Gateway) Connect

func (g *Gateway) Connect(ctx context.Context) <-chan ws.Op

func (*Gateway) LastError

func (g *Gateway) LastError() error

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.

func (*Gateway) Ready

func (g *Gateway) Ready() *ReadyEvent

Ready returns the ready event.

func (*Gateway) Send

func (g *Gateway) Send(ctx context.Context, data ws.Event) error

Send is a function to send an Op payload to the Gateway.

func (*Gateway) Speaking

func (g *Gateway) Speaking(ctx context.Context, flag SpeakingFlag) error

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

type HeartbeatAckEvent

type HeartbeatAckEvent uint64

HeartbeatAckEvent is an event for Op 6.

https://discord.com/developers/docs/topics/voice-connections#heartbeating-example-heartbeat-ack-payload

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.

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

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.

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

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.

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

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.

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

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.

https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-example-select-protocol-payload

func (*SelectProtocolCommand) EventType

func (*SelectProtocolCommand) EventType() ws.EventType

EventType implements Event.

func (*SelectProtocolCommand) Op

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.

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

func (*SessionDescriptionEvent) EventType

func (*SessionDescriptionEvent) EventType() ws.EventType

EventType implements Event.

func (*SessionDescriptionEvent) Op

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 (
	NotSpeaking SpeakingFlag = 0
	Microphone  SpeakingFlag = 1 << iota
	Soundshare
	Priority
)

type State

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

	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