forked from pothtonswer/discordmuffin
Fix the problem of reconnecting when moved to another VC (#1271)
* Fix disconnection when moved to another VC * Update voice.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * Update voice.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * Update voice.go Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com> * feat: add VoiceServerUpdate todo Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
parent
b8188269f9
commit
9effc92908
1 changed files with 19 additions and 0 deletions
19
voice.go
19
voice.go
|
@ -360,6 +360,25 @@ func (v *VoiceConnection) wsListen(wsConn *websocket.Conn, close <-chan struct{}
|
|||
v.wsConn = nil
|
||||
v.Unlock()
|
||||
|
||||
// Wait for VOICE_SERVER_UPDATE.
|
||||
// When the bot is moved by the user to another voice channel,
|
||||
// VOICE_SERVER_UPDATE is received after the code 4014.
|
||||
for i := 0; i < 5; i++ { // TODO: temp, wait for VoiceServerUpdate.
|
||||
<-time.After(1 * time.Second)
|
||||
|
||||
v.RLock()
|
||||
reconnected := v.wsConn != nil
|
||||
v.RUnlock()
|
||||
if !reconnected {
|
||||
continue
|
||||
}
|
||||
v.log(LogInformational, "successfully reconnected after 4014 manual disconnection")
|
||||
return
|
||||
}
|
||||
|
||||
// When VOICE_SERVER_UPDATE is not received, disconnect as usual.
|
||||
v.log(LogInformational, "disconnect due to 4014 manual disconnection")
|
||||
|
||||
v.session.Lock()
|
||||
delete(v.session.VoiceConnections, v.GuildID)
|
||||
v.session.Unlock()
|
||||
|
|
Loading…
Reference in a new issue