From 4db60bca9d41884b2fe275889e1762ce9408d883 Mon Sep 17 00:00:00 2001 From: Jason Chu Date: Sat, 3 Dec 2022 19:39:43 -0800 Subject: [PATCH] voice: Close previous UDP sessions on Continue (#358) --- voice/udp/manager.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/voice/udp/manager.go b/voice/udp/manager.go index dc7e359..15e871a 100644 --- a/voice/udp/manager.go +++ b/voice/udp/manager.go @@ -28,6 +28,7 @@ type Manager struct { // conn state conn *Connection + prevConn *Connection connLock chan struct{} frequency time.Duration @@ -69,6 +70,7 @@ func (m *Manager) Pause(ctx context.Context) error { case <-ctx.Done(): return ctx.Err() case m.connLock <- struct{}{}: + m.prevConn = m.conn return nil } } @@ -113,6 +115,11 @@ func (m *Manager) IsClosed() bool { func (m *Manager) Continue() bool { ws.WSDebug("UDP continued") + if m.prevConn != nil { + m.prevConn.Close() + m.prevConn = nil + } + select { case <-m.connLock: return true