From ad91025f59be32ad7ccba09ee3f068550132d41e Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Tue, 5 Jul 2016 20:51:52 -0500 Subject: [PATCH] Don't delete VoiceConnections But, don't add a VoiceConnection either if we don't successfully connect. --- wsapi.go | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/wsapi.go b/wsapi.go index 5e05d2a..2e5ca0d 100644 --- a/wsapi.go +++ b/wsapi.go @@ -440,6 +440,23 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *Voi return } + // Send the request to Discord that we want to join the voice channel + data := voiceChannelJoinOp{4, voiceChannelJoinData{&gID, &cID, mute, deaf}} + s.wsMutex.Lock() + err = s.wsConn.WriteJSON(data) + s.wsMutex.Unlock() + if err != nil { + return + } + + // doesn't exactly work perfect yet.. TODO + err = voice.waitUntilConnected() + if err != nil { + s.log(LogWarning, "error waiting for voice to connect, %s", err) + voice.Close() + return + } + if voice == nil { voice = &VoiceConnection{} s.VoiceConnections[gID] = voice @@ -451,27 +468,6 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *Voi voice.mute = mute voice.session = s - // Send the request to Discord that we want to join the voice channel - data := voiceChannelJoinOp{4, voiceChannelJoinData{&gID, &cID, mute, deaf}} - s.wsMutex.Lock() - err = s.wsConn.WriteJSON(data) - s.wsMutex.Unlock() - if err != nil { - s.log(LogInformational, "Deleting VoiceConnection %s", gID) - delete(s.VoiceConnections, gID) - return - } - - // doesn't exactly work perfect yet.. TODO - err = voice.waitUntilConnected() - if err != nil { - s.log(LogWarning, "error waiting for voice connecting, %s", err) - voice.Close() - s.log(LogInformational, "Deleting VoiceConnection %s", gID) - delete(s.VoiceConnections, gID) - return - } - return } @@ -536,7 +532,7 @@ func (s *Session) onVoiceServerUpdate(se *Session, st *VoiceServerUpdate) { // Open a conenction to the voice server err := voice.open() if err != nil { - s.log(LogError, "onVoiceServerUpdate voice.open, ", err) + s.log(LogError, "onVoiceServerUpdate voice.open, %s", err) } }