Browse Source

Added VoiceReady support to voice

Bruce Marriner 9 years ago
parent
commit
106c69f28a
1 changed files with 5 additions and 1 deletions
  1. 5 1
      voice.go

+ 5 - 1
voice.go

@@ -198,6 +198,7 @@ func (s *Session) VoiceOpenUDP() {
 		fmt.Println("error:", err)
 		return
 	}
+	s.UDPReady = true
 
 	// continue to listen for future packets
 	// go s.VoiceListenUDP()
@@ -289,15 +290,18 @@ func (s *Session) VoiceUDPKeepalive(i time.Duration) {
 func (s *Session) VoiceHeartbeat(i time.Duration) {
 
 	ticker := time.NewTicker(i * time.Millisecond)
-	for range ticker.C {
+	for {
 		timestamp := int(time.Now().Unix())
 		err := s.VwsConn.WriteJSON(map[string]int{
 			"op": 3,
 			"d":  timestamp,
 		})
 		if err != nil {
+			s.VoiceReady = false
 			fmt.Println(err)
 			return // log error?
 		}
+		s.VoiceReady = true
+		<-ticker.C
 	}
 }