websocket

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2019 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const SaveIncomingPackets = false

Variables

This section is empty.

Functions

This section is empty.

Types

type A added in v0.9.0

type A chan B

type B added in v0.9.0

type B chan *K

type Conn added in v0.8.0

type Conn interface {
	Close() error
	Open(endpoint string, requestHeader http.Header) error
	WriteJSON(v interface{}) error
	Read() (packet []byte, err error)

	Disconnected() bool
}

type DiscordPacket added in v0.9.0

type DiscordPacket struct {
	Op             uint            `json:"op"`
	Data           json.RawMessage `json:"d"`
	SequenceNumber uint            `json:"s,omitempty"`
	EventName      string          `json:"t,omitempty"`
}

DiscordPacket is packets sent by Discord over the socket connection

type ErrorUnexpectedClose added in v0.8.0

type ErrorUnexpectedClose struct {
	// contains filtered or unexported fields
}

func (*ErrorUnexpectedClose) Error added in v0.8.0

func (e *ErrorUnexpectedClose) Error() string

type Event

type Event struct {
	Name    string
	Data    []byte
	ShardID uint
}

Event is dispatched by the socket layer after parsing and extracting Discord data from a incoming packet. This is the data structure used by Disgord for triggering handlers and channels with an event.

type EvtClient added in v0.9.0

type EvtClient struct {
	ReadyCounter uint

	// synchronization and rate limiting
	K *K
	// contains filtered or unexported fields
}

func NewEventClient added in v0.9.0

func NewEventClient(conf *EvtConfig, shardID uint) (client *EvtClient, err error)

NewManager creates a new socket client manager for handling behavior and Discord events. Note that this function initiates a go routine.

func (EvtClient) AllowedToStartPulsating added in v0.9.0

func (c EvtClient) AllowedToStartPulsating(serviceID uint8) bool

AllowedToStartPulsating you must notify when you are done pulsating!

func (EvtClient) Connect added in v0.9.0

func (c EvtClient) Connect() (err error)

Connect establishes a socket connection with the Discord API

func (EvtClient) Debug added in v0.9.0

func (c EvtClient) Debug(v ...interface{})

func (EvtClient) Disconnect added in v0.9.0

func (c EvtClient) Disconnect() (err error)

Disconnect disconnects the socket connection

func (*EvtClient) Emit added in v0.9.0

func (c *EvtClient) Emit(command string, data interface{}) (err error)

func (EvtClient) Error added in v0.9.0

func (c EvtClient) Error(v ...interface{})

func (EvtClient) HeartbeatLatency added in v0.9.0

func (c EvtClient) HeartbeatLatency() (duration time.Duration, err error)

HeartbeatLatency get the time diff between sending a heartbeat and Discord replying with a heartbeat ack

func (EvtClient) Info added in v0.9.0

func (c EvtClient) Info(v ...interface{})

func (EvtClient) Receive added in v0.9.0

func (c EvtClient) Receive() <-chan *DiscordPacket

Receive returns the channel for receiving Discord packets

func (*EvtClient) RegisterEvent added in v0.9.0

func (c *EvtClient) RegisterEvent(event string)

RegisterEvent tells the socket layer which event types are of interest. Any event that are not registered will be discarded once the socket info is extracted from the event.

func (*EvtClient) RemoveEvent added in v0.9.0

func (c *EvtClient) RemoveEvent(event string)

RemoveEvent removes an event type from the registry. This will cause the event type to be discarded by the socket layer.

func (*EvtClient) SetPresence added in v0.9.3

func (c *EvtClient) SetPresence(data interface{}) (err error)

func (EvtClient) StopPulsating added in v0.9.0

func (c EvtClient) StopPulsating(serviceID uint8)

StopPulsating stops sending heartbeats to Discord

type EvtConfig added in v0.9.0

type EvtConfig struct {
	// BotToken Discord bot token
	BotToken string
	Proxy    proxy.Dialer

	// ChannelBuffer is used to set the event channel buffer
	ChannelBuffer uint

	// TrackedEvents holds a list of predetermined events that should not be ignored.
	// This is especially useful for creating multiple shards, to reuse the same slice
	TrackedEvents *UniqueStringSlice

	// EventChan can be used to inject a channel instead of letting the ws client construct one
	// useful in sharding to avoid complicated patterns to handle N channels.
	EventChan chan<- *Event

	A A

	Presence interface{}

	// Endpoint for establishing socket connection. Either endpoints, `Gateway` or `Gateway Bot`, is used to retrieve
	// a valid socket endpoint from Discord
	Endpoint string

	// Encoding make sure we support the correct encoding
	Encoding string

	// Version make sure we support the correct Discord version
	Version int

	// for identify packets
	Browser             string
	Device              string
	GuildLargeThreshold uint
	ShardCount          uint

	DiscordPktPool *sync.Pool

	Logger logger.Logger

	SystemShutdown chan interface{}
	// contains filtered or unexported fields
}

EvtConfig ws TODO: remove shardID, such that this struct can be reused for every shard

type K added in v0.9.0

type K struct {
	Release B
	Key     interface{}
}

K is used to get the Connect permission from the shard manager

type Link interface {
	Connect() error
	Disconnect() error
}

Link is used to establish basic commands to create and destroy a link. See client.Disconnect() and client.Connect() for linking to the Discord servers

type UniqueStringSlice added in v0.9.0

type UniqueStringSlice struct {
	// contains filtered or unexported fields
}

UniqueStringSlice a thread safe string slice that does not allow duplicate strings to be stored

func (*UniqueStringSlice) Add added in v0.9.0

func (s *UniqueStringSlice) Add(id string)

func (*UniqueStringSlice) Exists added in v0.9.0

func (s *UniqueStringSlice) Exists(id string) bool

func (*UniqueStringSlice) Len added in v0.9.0

func (s *UniqueStringSlice) Len() int

func (*UniqueStringSlice) Remove added in v0.9.0

func (s *UniqueStringSlice) Remove(id string)

type VoiceClient added in v0.9.0

type VoiceClient struct {
	SystemShutdown chan interface{}
	// contains filtered or unexported fields
}

func NewVoiceClient added in v0.9.0

func NewVoiceClient(conf *VoiceConfig) (client *VoiceClient, err error)

func (VoiceClient) AllowedToStartPulsating added in v0.9.0

func (c VoiceClient) AllowedToStartPulsating(serviceID uint8) bool

AllowedToStartPulsating you must notify when you are done pulsating!

func (*VoiceClient) Connect added in v0.9.0

func (c *VoiceClient) Connect() (rdy *VoiceReady, err error)

Connect establishes a socket connection with the Discord API

func (VoiceClient) Debug added in v0.9.0

func (c VoiceClient) Debug(v ...interface{})

func (VoiceClient) Disconnect added in v0.9.0

func (c VoiceClient) Disconnect() (err error)

Disconnect disconnects the socket connection

func (VoiceClient) Emit added in v0.9.0

func (c VoiceClient) Emit(command string, data interface{}) (err error)

Emit is used by DisGord users for dispatching a socket command to the Discord Gateway.

func (VoiceClient) Error added in v0.9.0

func (c VoiceClient) Error(v ...interface{})

func (VoiceClient) HeartbeatLatency added in v0.9.0

func (c VoiceClient) HeartbeatLatency() (duration time.Duration, err error)

HeartbeatLatency get the time diff between sending a heartbeat and Discord replying with a heartbeat ack

func (VoiceClient) Info added in v0.9.0

func (c VoiceClient) Info(v ...interface{})

func (VoiceClient) Receive added in v0.9.0

func (c VoiceClient) Receive() <-chan *DiscordPacket

Receive returns the channel for receiving Discord packets

func (*VoiceClient) SendUDPInfo added in v0.9.0

func (c *VoiceClient) SendUDPInfo(data *VoiceSelectProtocolParams) (ret *VoiceSessionDescription, err error)

func (VoiceClient) StopPulsating added in v0.9.0

func (c VoiceClient) StopPulsating(serviceID uint8)

StopPulsating stops sending heartbeats to Discord

type VoiceConfig added in v0.9.0

type VoiceConfig struct {
	// Guild ID to connect to
	GuildID snowflake.Snowflake

	// User ID that is connecting
	UserID snowflake.Snowflake

	// Session ID
	SessionID string

	// Token to connect with the voice websocket
	Token string

	// proxy allows for use of a custom proxy
	Proxy proxy.Dialer

	// Endpoint for establishing voice connection
	Endpoint string

	Logger logger.Logger

	SystemShutdown chan interface{}
}

type VoiceReady added in v0.9.0

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

type VoiceSelectProtocolParams added in v0.9.0

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

type VoiceSessionDescription added in v0.9.0

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

type WebsocketErr added in v0.8.0

type WebsocketErr struct {
	ID uint
	// contains filtered or unexported fields
}

WebsocketErr is used internally when the websocket package returns an error. It does not represent a Discord error(!)

func (*WebsocketErr) Error added in v0.8.0

func (e *WebsocketErr) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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