Skip to content

Commit

Permalink
ChannelVoiceJoin now waits for the connection.
Browse files Browse the repository at this point in the history
You can return to the previous behaviour just by calling
the function as a goroutine.  However I feel most uses of it
require the connection to be ready before the next step.
  • Loading branch information
bwmarrin committed Mar 15, 2016
1 parent 1cc1d4c commit 7ec5304
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions wsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,23 +336,19 @@ type voiceChannelJoinOp struct {
// cID : Channel ID of the channel to join.
// mute : If true, you will be set to muted upon joining.
// deaf : If true, you will be set to deafened upon joining.
// timeout : If timeout > 0 then func will wait up to timeout for voice
// connection to be ready. If it does not become ready in that
// time frame then it will return an error and close out the voice
// connection entirely.
func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool, timeout int) (voice *VoiceConnection, err error) {
func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *VoiceConnection, err error) {

// If a voice connection alreadyy exists for this guild then
// return that connection. If the channel differs, also change channels.
// TODO: check if the voice connection is really valid or just a shell
// because we might want to allow setting variables prior to getting here
// like debug, and other things.
if voice, ok := s.VoiceConnections[gID]; ok {
var ok bool
if voice, ok = s.VoiceConnections[gID]; ok {
if voice.ChannelID != cID {
err = voice.ChangeChannel(cID)
}
return voice, err
// TODO: ugh, ugly..
return
}

// Create a new voice session
Expand All @@ -366,7 +362,7 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool, timeout int
ChannelID: cID,
}

// Store voice in VoiceConnections map for thils GuildID
// Store voice in VoiceConnections map for this GuildID
s.VoiceConnections[gID] = voice

// Send the request to Discord that we want to join the voice channel
Expand All @@ -377,13 +373,11 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool, timeout int
}

// doesn't exactly work perfect yet.. TODO
if timeout > 0 {
err = voice.WaitUntilConnected()
if err != nil {
voice.Close()
delete(s.VoiceConnections, gID)
return
}
err = voice.WaitUntilConnected()
if err != nil {
voice.Close()
delete(s.VoiceConnections, gID)
return
}

return
Expand Down

0 comments on commit 7ec5304

Please sign in to comment.