|
@@ -67,7 +67,7 @@ func (s *Session) VoiceOpenWS() {
|
|
|
}
|
|
|
|
|
|
|
|
|
- go s.VListen()
|
|
|
+ go s.VoiceListen()
|
|
|
}
|
|
|
|
|
|
|
|
@@ -75,9 +75,9 @@ func (s *Session) VoiceCloseWS() {
|
|
|
s.VwsConn.Close()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-func (s *Session) VListen() (err error) {
|
|
|
+func (s *Session) VoiceListen() (err error) {
|
|
|
|
|
|
for {
|
|
|
messageType, message, err := s.VwsConn.ReadMessage()
|
|
@@ -129,6 +129,8 @@ func (s *Session) VoiceEvent(messageType int, message []byte) (err error) {
|
|
|
case 3:
|
|
|
|
|
|
return
|
|
|
+ case 4:
|
|
|
+ s.VoiceSpeaking()
|
|
|
default:
|
|
|
fmt.Println("UNKNOWN VOICE OP: ", e.Operation)
|
|
|
printJSON(e.RawData)
|
|
@@ -180,7 +182,7 @@ func (s *Session) VoiceOpenUDP() {
|
|
|
|
|
|
|
|
|
|
|
|
- json := fmt.Sprintf(`{"op":1,"d":{"protocol":"udp","data":{"address":"%s","port":"%d","mode":"plain"}}}`, ip, p)
|
|
|
+ json := fmt.Sprintf(`{"op":1,"d":{"protocol":"udp","data":{"address":"%s","port":%d,"mode":"plain"}}}`, ip, p)
|
|
|
jsonb := []byte(json)
|
|
|
|
|
|
err = s.VwsConn.WriteMessage(websocket.TextMessage, jsonb)
|
|
@@ -190,7 +192,7 @@ func (s *Session) VoiceOpenUDP() {
|
|
|
}
|
|
|
|
|
|
|
|
|
- go s.VoiceListenUDP()
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -198,18 +200,75 @@ func (s *Session) VoiceCloseUDP() {
|
|
|
s.UDPConn.Close()
|
|
|
}
|
|
|
|
|
|
+func (s *Session) VoiceSpeaking() {
|
|
|
+
|
|
|
+ jsonb := []byte(`{"op":5,"d":{"speaking":true,"delay":0}}`)
|
|
|
+ err := s.VwsConn.WriteMessage(websocket.TextMessage, jsonb)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("error:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func (s *Session) VoiceListenUDP() {
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
for {
|
|
|
- fmt.Println("READ FROM UDP LOOP:")
|
|
|
b := make([]byte, 1024)
|
|
|
- s.UDPConn.ReadFromUDP(b)
|
|
|
+ rlen, _, err := s.UDPConn.ReadFromUDP(b)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error reading from UDP:", err)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if rlen < 1 {
|
|
|
+ fmt.Println("Empty UDP packet received")
|
|
|
+ continue
|
|
|
+
|
|
|
+ }
|
|
|
fmt.Println("READ FROM UDP: ", b)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (s *Session) VoiceUDPKeepalive(i time.Duration) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ticker := time.NewTicker(i * time.Millisecond)
|
|
|
+ for range ticker.C {
|
|
|
+ sb := make([]byte, 8)
|
|
|
+ sb[0] = 0x80
|
|
|
+ sb[1] = 0xc9
|
|
|
+ sb[2] = 0x00
|
|
|
+ sb[3] = 0x01
|
|
|
+
|
|
|
+ ssrcBE := make([]byte, 4)
|
|
|
+ binary.BigEndian.PutUint32(ssrcBE, s.Vop2.SSRC)
|
|
|
+
|
|
|
+ sb[4] = ssrcBE[0]
|
|
|
+ sb[5] = ssrcBE[1]
|
|
|
+ sb[6] = ssrcBE[2]
|
|
|
+ sb[7] = ssrcBE[3]
|
|
|
+
|
|
|
+ s.UDPConn.Write(ssrcBE)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
|