voice: Close previous UDP sessions on Continue (#358)

This commit is contained in:
Jason Chu 2022-12-03 19:39:43 -08:00 committed by GitHub
parent 12a84ee999
commit 4db60bca9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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