Add a timeout loop to voice open to wait for SessionID
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 :)
This commit is contained in:
parent
9648705e77
commit
7bbcfe7e0e
1 changed files with 13 additions and 0 deletions
13
voice.go
13
voice.go
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue