mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-27 17:23:00 +00:00
voice: Close previous UDP sessions on Continue (#358)
This commit is contained in:
parent
12a84ee999
commit
4db60bca9d
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue