From 7bbcfe7e0ea24b6939c5d1c799366323adb71954 Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Fri, 18 Mar 2016 07:58:01 -0500 Subject: [PATCH] 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 :) --- voice.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/voice.go b/voice.go index ea80dc8..7f56e89 100644 --- a/voice.go +++ b/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)