fix: cleanup streams on disconnection
This commit is contained in:
@@ -3,7 +3,8 @@ import {
|
||||
createAudioPlayer,
|
||||
createAudioResource,
|
||||
StreamType,
|
||||
VoiceConnection
|
||||
VoiceConnection,
|
||||
VoiceConnectionStatus
|
||||
} from '@discordjs/voice';
|
||||
import { AudioMixer } from 'node-audio-mixer';
|
||||
import { PassThrough, Readable } from 'stream';
|
||||
@@ -171,6 +172,16 @@ export class AudioStreamManager {
|
||||
stream = new MixedStream();
|
||||
this.streams.set(conn, stream);
|
||||
conn.subscribe(stream.player);
|
||||
|
||||
conn.on('stateChange', (_, newState) => {
|
||||
if (
|
||||
newState.status === VoiceConnectionStatus.Disconnected ||
|
||||
newState.status === VoiceConnectionStatus.Destroyed
|
||||
) {
|
||||
this.destroyStream(conn);
|
||||
}
|
||||
});
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user