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
This commit is contained in:
Bruce Marriner 2016-04-25 22:00:30 -05:00
parent 77d4767481
commit 4cac19c3f9
2 changed files with 11 additions and 5 deletions

View file

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

View file

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