|
@@ -40,9 +40,6 @@ type VoiceConnection struct {
|
|
|
OpusSend chan []byte
|
|
|
OpusRecv chan *Packet
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
wsConn *websocket.Conn
|
|
|
udpConn *net.UDPConn
|
|
|
session *Session
|
|
@@ -50,8 +47,6 @@ type VoiceConnection struct {
|
|
|
sessionID string
|
|
|
token string
|
|
|
endpoint string
|
|
|
- op4 voiceOP4
|
|
|
- op2 voiceOP2
|
|
|
|
|
|
|
|
|
close chan struct{}
|
|
@@ -61,81 +56,43 @@ type VoiceConnection struct {
|
|
|
|
|
|
|
|
|
sessionRecv chan string
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-type voiceOP4 struct {
|
|
|
- SecretKey [32]byte `json:"secret_key"`
|
|
|
- Mode string `json:"mode"`
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-type voiceOP2 struct {
|
|
|
- SSRC uint32 `json:"ssrc"`
|
|
|
- Port int `json:"port"`
|
|
|
- Modes []string `json:"modes"`
|
|
|
- HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
|
|
-}
|
|
|
|
|
|
-type voiceHandshakeData struct {
|
|
|
- ServerID string `json:"server_id"`
|
|
|
- UserID string `json:"user_id"`
|
|
|
- SessionID string `json:"session_id"`
|
|
|
- Token string `json:"token"`
|
|
|
+ op4 voiceOP4
|
|
|
+ op2 voiceOP2
|
|
|
}
|
|
|
|
|
|
-type voiceHandshakeOp struct {
|
|
|
- Op int `json:"op"`
|
|
|
- Data voiceHandshakeData `json:"d"`
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-func (v *VoiceConnection) Open() (err error) {
|
|
|
-
|
|
|
- v.Lock()
|
|
|
- defer v.Unlock()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (v *VoiceConnection) Speaking(b bool) (err error) {
|
|
|
|
|
|
-
|
|
|
- if v.wsConn != nil {
|
|
|
- return
|
|
|
+ type voiceSpeakingData struct {
|
|
|
+ Speaking bool `json:"speaking"`
|
|
|
+ Delay int `json:"delay"`
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- vg := fmt.Sprintf("wss://%s", strings.TrimSuffix(v.endpoint, ":80"))
|
|
|
- v.wsConn, _, err = websocket.DefaultDialer.Dial(vg, nil)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("VOICE error opening websocket:", err)
|
|
|
- return
|
|
|
+ type voiceSpeakingOp struct {
|
|
|
+ Op int `json:"op"`
|
|
|
+ Data voiceSpeakingData `json:"d"`
|
|
|
}
|
|
|
|
|
|
- data := voiceHandshakeOp{0, voiceHandshakeData{v.GuildID, v.UserID, v.sessionID, v.token}}
|
|
|
+ if v.wsConn == nil {
|
|
|
+ return fmt.Errorf("No VoiceConnection websocket.")
|
|
|
+ }
|
|
|
|
|
|
+ data := voiceSpeakingOp{5, voiceSpeakingData{b, 0}}
|
|
|
err = v.wsConn.WriteJSON(data)
|
|
|
if err != nil {
|
|
|
- fmt.Println("VOICE error sending init packet:", err)
|
|
|
+ fmt.Println("Speaking() write json error:", err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- v.close = make(chan struct{})
|
|
|
- go v.wsListen(v.wsConn, v.close)
|
|
|
-
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
func (v *VoiceConnection) WaitUntilConnected() error {
|
|
|
|
|
|
i := 0
|
|
@@ -155,36 +112,6 @@ func (v *VoiceConnection) WaitUntilConnected() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-type voiceSpeakingData struct {
|
|
|
- Speaking bool `json:"speaking"`
|
|
|
- Delay int `json:"delay"`
|
|
|
-}
|
|
|
-
|
|
|
-type voiceSpeakingOp struct {
|
|
|
- Op int `json:"op"`
|
|
|
- Data voiceSpeakingData `json:"d"`
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-func (v *VoiceConnection) Speaking(b bool) (err error) {
|
|
|
-
|
|
|
- if v.wsConn == nil {
|
|
|
- return fmt.Errorf("No VoiceConnection websocket.")
|
|
|
- }
|
|
|
-
|
|
|
- data := voiceSpeakingOp{5, voiceSpeakingData{b, 0}}
|
|
|
- err = v.wsConn.WriteJSON(data)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Speaking() write json error:", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
|
|
|
func (v *VoiceConnection) ChangeChannel(channelID string, mute, deaf bool) (err error) {
|
|
@@ -249,6 +176,70 @@ func (v *VoiceConnection) Close() {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+type voiceOP4 struct {
|
|
|
+ SecretKey [32]byte `json:"secret_key"`
|
|
|
+ Mode string `json:"mode"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type voiceOP2 struct {
|
|
|
+ SSRC uint32 `json:"ssrc"`
|
|
|
+ Port int `json:"port"`
|
|
|
+ Modes []string `json:"modes"`
|
|
|
+ HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (v *VoiceConnection) open() (err error) {
|
|
|
+
|
|
|
+ v.Lock()
|
|
|
+ defer v.Unlock()
|
|
|
+
|
|
|
+
|
|
|
+ if v.wsConn != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ vg := fmt.Sprintf("wss://%s", strings.TrimSuffix(v.endpoint, ":80"))
|
|
|
+ v.wsConn, _, err = websocket.DefaultDialer.Dial(vg, nil)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("VOICE error opening websocket:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ type voiceHandshakeData struct {
|
|
|
+ ServerID string `json:"server_id"`
|
|
|
+ UserID string `json:"user_id"`
|
|
|
+ SessionID string `json:"session_id"`
|
|
|
+ Token string `json:"token"`
|
|
|
+ }
|
|
|
+ type voiceHandshakeOp struct {
|
|
|
+ Op int `json:"op"`
|
|
|
+ Data voiceHandshakeData `json:"d"`
|
|
|
+ }
|
|
|
+ data := voiceHandshakeOp{0, voiceHandshakeData{v.GuildID, v.UserID, v.sessionID, v.token}}
|
|
|
+
|
|
|
+ err = v.wsConn.WriteJSON(data)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("VOICE error sending init packet:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ v.close = make(chan struct{})
|
|
|
+ go v.wsListen(v.wsConn, v.close)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{}) {
|