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