Skip to content

Commit

Permalink
Add a timeout loop to voice open to wait for SessionID
Browse files Browse the repository at this point in the history
This doesn't always in the same order I had been told.  It is possible
that it will come slightly after open function is called so we need
to give it a few ms to come in before we open the voice websocket
connection.  How this is done may change later to a channel :)
  • Loading branch information
bwmarrin committed Mar 18, 2016
1 parent 9648705 commit 7bbcfe7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ func (v *VoiceConnection) open() (err error) {
return
}

// TODO temp? loop to wait for the SessionID
i := 0
for {
if v.sessionID != "" {
break
}
if i > 20 { // only loop for up to 1 second total
return fmt.Errorf("Did not receive voice Session ID in time.")
}
time.Sleep(50 * time.Millisecond)
i++
}

// Connect to VoiceConnection Websocket
vg := fmt.Sprintf("wss://%s", strings.TrimSuffix(v.endpoint, ":80"))
v.wsConn, _, err = websocket.DefaultDialer.Dial(vg, nil)
Expand Down

0 comments on commit 7bbcfe7

Please sign in to comment.