瀏覽代碼

Do not start udp listener if deaf.

If you call VoiceChannelJoin and set deaf to true
then the library will not start a udp listener
Bruce Marriner 8 年之前
父節點
當前提交
4cac19c3f9
共有 2 個文件被更改,包括 11 次插入5 次删除
  1. 9 5
      voice.go
  2. 2 0
      wsapi.go

+ 9 - 5
voice.go

@@ -34,9 +34,11 @@ type VoiceConnection struct {
 
 	Debug     bool // If true, print extra logging
 	Ready     bool // If true, voice is ready to send/receive audio
+	UserID    string
 	GuildID   string
 	ChannelID string
-	UserID    string
+	deaf      bool
+	mute      bool
 
 	OpusSend chan []byte  // Chan for sending opus audio
 	OpusRecv chan *Packet // Chan for receiving opus audio
@@ -356,11 +358,13 @@ func (v *VoiceConnection) wsEvent(messageType int, message []byte) {
 		go v.opusSender(v.udpConn, v.close, v.OpusSend, 48000, 960)
 
 		// Start the opusReceiver
-		if v.OpusRecv == nil {
-			v.OpusRecv = make(chan *Packet, 2)
-		}
+		if !v.deaf {
+			if v.OpusRecv == nil {
+				v.OpusRecv = make(chan *Packet, 2)
+			}
 
-		go v.opusReceiver(v.udpConn, v.close, v.OpusRecv)
+			go v.opusReceiver(v.udpConn, v.close, v.OpusRecv)
+		}
 
 		// Send the ready event
 		v.connected <- true

+ 2 - 0
wsapi.go

@@ -361,6 +361,8 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *Voi
 	voice = &VoiceConnection{
 		GuildID:     gID,
 		ChannelID:   cID,
+		deaf:        deaf,
+		mute:        mute,
 		session:     s,
 		connected:   make(chan bool),
 		sessionRecv: make(chan string),