The start of the voice rework begins.

This commit is contained in:
Bruce Marriner 2016-01-08 10:53:33 -06:00
parent 6e4f495f6a
commit 59ed5b0b40

View file

@ -18,23 +18,44 @@ import (
"fmt" "fmt"
"net" "net"
"strings" "strings"
"sync"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
// A VEvent is the initial structure for voice websocket events. I think // A Voice struct holds all data and functions related to Discord Voice support.
// I can reuse the data websocket structure here. // NOTE: This is not used right at this moment, but it will be used soon.
type VEvent struct { type voice struct {
Type string `json:"t"` Ready bool
State int `json:"s"` WS *voiceWS
Operation int `json:"op"` UDP *voiceUDP
RawData json.RawMessage `json:"d"`
SessionID string
Token string
Endpoint string
GuildID string
ChannelID string
OP2 *voiceOP2
} }
// A VoiceOP2 stores the data for voice operation 2 websocket events type voiceWS struct {
Ready bool
Chan chan struct{}
Lock sync.Mutex
Conn *websocket.Conn
}
type voiceUDP struct {
Ready bool
Chan chan struct{}
Lock sync.Mutex
Conn *net.UDPConn
}
// A voiceOP2 stores the data for voice operation 2 websocket events
// which is sort of like the voice READY packet // which is sort of like the voice READY packet
type VoiceOP2 struct { type voiceOP2 struct {
SSRC uint32 `json:"ssrc"` SSRC uint32 `json:"ssrc"`
Port int `json:"port"` Port int `json:"port"`
Modes []string `json:"modes"` Modes []string `json:"modes"`
@ -117,7 +138,7 @@ func (s *Session) VoiceEvent(messageType int, message []byte) (err error) {
printJSON(message) printJSON(message)
} }
var e VEvent var e Event
if err := json.Unmarshal(message, &e); err != nil { if err := json.Unmarshal(message, &e); err != nil {
return err return err
} }
@ -125,7 +146,7 @@ func (s *Session) VoiceEvent(messageType int, message []byte) (err error) {
switch e.Operation { switch e.Operation {
case 2: // READY packet case 2: // READY packet
var st VoiceOP2 var st voiceOP2
if err := json.Unmarshal(e.RawData, &st); err != nil { if err := json.Unmarshal(e.RawData, &st); err != nil {
fmt.Println(e.Type, err) fmt.Println(e.Type, err)
printJSON(e.RawData) // TODO: Better error logginEventg printJSON(e.RawData) // TODO: Better error logginEventg