Skip to content

Commit

Permalink
Disconnect old audio session before creating new
Browse files Browse the repository at this point in the history
  • Loading branch information
fakelag committed Mar 23, 2024
1 parent 751879c commit 9ca484e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions discordplayer/discordplayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ var _ = Describe("Discord Player", func() {
gomock.InOrder(
playerContext.mockVoiceConnection.EXPECT().Speaking(false),
playerContext.mockVoiceConnection.EXPECT().IsReady().Return(false),
playerContext.mockVoiceConnection.EXPECT().Disconnect(),
playerContext.mockDiscordSession.EXPECT().
ChannelVoiceJoin(playerContext.guildID, playerContext.channelID, false, false).
Return(playerContext.mockVoiceConnection, nil),
Expand Down Expand Up @@ -1066,6 +1067,7 @@ var _ = Describe("Discord Player", func() {
playerContext.mockVoiceConnection.EXPECT().Speaking(false),
mockDcaStreamingSession.EXPECT().PlaybackPosition().Return(10*time.Second).MinTimes(1),
playerContext.mockVoiceConnection.EXPECT().IsReady().Return(false),
playerContext.mockVoiceConnection.EXPECT().Disconnect(),
playerContext.mockDiscordSession.EXPECT().
ChannelVoiceJoin(playerContext.guildID, playerContext.channelID, false, false).
Return(playerContext.mockVoiceConnection, nil),
Expand Down
4 changes: 4 additions & 0 deletions discordplayer/voiceworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func (dms *DiscordMusicSession) checkDiscordVoiceConnection() error {
return nil
}

if dms.voiceConnection != nil {
_ = dms.voiceConnection.Disconnect()
}

dms.mutex.RLock()
voiceChannelID := dms.voiceChannelID
dms.mutex.RUnlock()
Expand Down

0 comments on commit 9ca484e

Please sign in to comment.