Clean up failed voice connections
This commit is contained in:
@@ -89,7 +89,14 @@ export default class AudioManager {
|
||||
});
|
||||
this.connection.subscribe(this.audioPlayer);
|
||||
|
||||
try {
|
||||
await entersState(this.connection, VoiceConnectionStatus.Ready, this.options.connectTimeoutMs);
|
||||
} catch (error) {
|
||||
this.connection.destroy();
|
||||
this.connection = undefined;
|
||||
this.playbackState = 'stopped';
|
||||
throw error;
|
||||
}
|
||||
this.playbackState = 'ready';
|
||||
this.scheduleRenewal();
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ describe('AudioManager', () => {
|
||||
expect(mockAudioPlayer.play).toHaveBeenCalledWith(mockAudioResource);
|
||||
});
|
||||
|
||||
it('keeps failed connection startup observable', async () => {
|
||||
it('cleans up when connection startup fails', async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const manager = new AudioManager({
|
||||
@@ -112,10 +112,10 @@ describe('AudioManager', () => {
|
||||
|
||||
await expect(manager.connect()).rejects.toThrow('voice connection timeout');
|
||||
|
||||
expect(manager.state).toBe('connecting');
|
||||
expect(manager.isConnected).toBe(true);
|
||||
expect(manager.state).toBe('stopped');
|
||||
expect(manager.isConnected).toBe(false);
|
||||
expect(mockConnection.subscribe).toHaveBeenCalledWith(mockAudioPlayer);
|
||||
expect(mockConnection.destroy).not.toHaveBeenCalled();
|
||||
expect(mockConnection.destroy).toHaveBeenCalledTimes(1);
|
||||
expect(jest.getTimerCount()).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user