2020-04-25 02:36:33 +00:00
|
|
|
package voicegateway
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
2021-09-28 20:19:04 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/utils/ws"
|
2020-04-25 02:36:33 +00:00
|
|
|
)
|
2020-04-20 01:21:10 +00:00
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
//go:generate go run ../../utils/cmd/genevent -p voicegateway -o event_methods.go
|
|
|
|
|
|
|
|
// OpUnmarshalers contains the Op unmarshalers for the voice gateway events.
|
|
|
|
var OpUnmarshalers = ws.NewOpUnmarshalers()
|
|
|
|
|
|
|
|
// IdentifyCommand is a command for Op 0.
|
|
|
|
//
|
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-identify-payload
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectProtocolCommand is a command for Op 1.
|
|
|
|
//
|
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-example-select-protocol-payload
|
|
|
|
type SelectProtocolCommand struct {
|
|
|
|
Protocol string `json:"protocol"`
|
|
|
|
Data SelectProtocolData `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectProtocolData is the data inside a SelectProtocolCommand.
|
|
|
|
type SelectProtocolData struct {
|
|
|
|
Address string `json:"address"`
|
|
|
|
Port uint16 `json:"port"`
|
|
|
|
Mode string `json:"mode"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadyEvent is an event for Op 2.
|
|
|
|
//
|
2020-11-03 17:16:42 +00:00
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-ready-payload
|
2020-04-20 01:21:10 +00:00
|
|
|
type ReadyEvent struct {
|
|
|
|
SSRC uint32 `json:"ssrc"`
|
|
|
|
IP string `json:"ip"`
|
|
|
|
Port int `json:"port"`
|
|
|
|
Modes []string `json:"modes"`
|
|
|
|
Experiments []string `json:"experiments"`
|
|
|
|
|
|
|
|
// From Discord's API Docs:
|
|
|
|
//
|
|
|
|
// `heartbeat_interval` here is an erroneous field and should be ignored.
|
|
|
|
// The correct `heartbeat_interval` value comes from the Hello payload.
|
|
|
|
|
|
|
|
// HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`
|
|
|
|
}
|
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// Addr formats the URL inside Ready to be of format "host:port".
|
2020-04-25 02:36:33 +00:00
|
|
|
func (r ReadyEvent) Addr() string {
|
|
|
|
return r.IP + ":" + strconv.Itoa(r.Port)
|
|
|
|
}
|
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// HeartbeatCommand is a command for Op 3.
|
|
|
|
//
|
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#heartbeating-example-heartbeat-payload
|
|
|
|
type HeartbeatCommand uint64
|
|
|
|
|
|
|
|
// SessionDescriptionEvent is an event for Op 4.
|
|
|
|
//
|
2020-11-03 17:16:42 +00:00
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection-example-session-description-payload
|
2020-04-20 01:21:10 +00:00
|
|
|
type SessionDescriptionEvent struct {
|
|
|
|
Mode string `json:"mode"`
|
|
|
|
SecretKey [32]byte `json:"secret_key"`
|
|
|
|
}
|
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#speaking
|
|
|
|
type SpeakingFlag uint64
|
|
|
|
|
|
|
|
const (
|
|
|
|
NotSpeaking SpeakingFlag = 0
|
|
|
|
Microphone SpeakingFlag = 1 << iota
|
|
|
|
Soundshare
|
|
|
|
Priority
|
|
|
|
)
|
2020-04-20 01:21:10 +00:00
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// SpeakingEvent is an event for Op 5. It is also a command.
|
|
|
|
//
|
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#speaking-example-speaking-payload
|
|
|
|
type SpeakingEvent struct {
|
|
|
|
Speaking SpeakingFlag `json:"speaking"`
|
|
|
|
Delay int `json:"delay"`
|
|
|
|
SSRC uint32 `json:"ssrc"`
|
|
|
|
UserID discord.UserID `json:"user_id,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// HeartbeatAckEvent is an event for Op 6.
|
|
|
|
//
|
2020-11-03 17:16:42 +00:00
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#heartbeating-example-heartbeat-ack-payload
|
2021-09-28 20:19:04 +00:00
|
|
|
type HeartbeatAckEvent uint64
|
|
|
|
|
|
|
|
// ResumeCommand is a command for Op 7.
|
|
|
|
//
|
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection-example-resume-connection-payload
|
|
|
|
type ResumeCommand struct {
|
|
|
|
GuildID discord.GuildID `json:"server_id"` // yes, this should be "server_id"
|
|
|
|
SessionID string `json:"session_id"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
}
|
2020-04-20 01:21:10 +00:00
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// HelloEvent is an event for Op 8.
|
|
|
|
//
|
2020-11-03 17:16:42 +00:00
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#heartbeating-example-hello-payload-since-v3
|
2020-04-20 01:21:10 +00:00
|
|
|
type HelloEvent struct {
|
2020-04-25 02:36:33 +00:00
|
|
|
HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`
|
2020-04-20 01:21:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// ResumedEvent is an event for Op 9.
|
2020-11-03 17:16:42 +00:00
|
|
|
// https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection-example-resumed-payload
|
2020-04-20 01:21:10 +00:00
|
|
|
type ResumedEvent struct{}
|
2020-11-15 19:45:47 +00:00
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// ClientConnectEvent is an event for Op 12. It is undocumented.
|
2020-11-15 19:45:47 +00:00
|
|
|
type ClientConnectEvent struct {
|
|
|
|
UserID discord.UserID `json:"user_id"`
|
|
|
|
AudioSSRC uint32 `json:"audio_ssrc"`
|
|
|
|
VideoSSRC uint32 `json:"video_ssrc"`
|
|
|
|
}
|
|
|
|
|
2021-09-28 20:19:04 +00:00
|
|
|
// 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.
|
2020-11-15 19:45:47 +00:00
|
|
|
type ClientDisconnectEvent struct {
|
|
|
|
UserID discord.UserID `json:"user_id"`
|
|
|
|
}
|