Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@discordjs voice example recorder has memory leaks #3

Open
seanroades opened this issue Oct 1, 2023 · 0 comments
Open

@discordjs voice example recorder has memory leaks #3

seanroades opened this issue Oct 1, 2023 · 0 comments
Labels
bug Something isn't working need repro

Comments

@seanroades
Copy link

Which example is this bug report for?

basic

Issue description

git clone https://github.com/discordjs/voice-examples.git
cd recorder
npm i -D
npm start

Join a voice channel
/join
/record speaker@<your_user>

Talk into the mic, and after a while you'll see

👂 Started recording ./recordings/1696122267181-dimsey8_0.ogg
✅ Recorded ./recordings/1696122267181-dimsey8_0.ogg
👂 Started recording ./recordings/1696122271590-dimsey8_0.ogg
👂 Started recording ./recordings/1696122275391-dimsey8_0.ogg
👂 Started recording ./recordings/1696122278329-dimsey8_0.ogg
(node:64307) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit
(Use node --trace-warnings ... to show where the warning was created)
✅ Recorded ./recordings/1696122278329-dimsey8_0.ogg
✅ Recorded ./recordings/1696122275391-dimsey8_0.ogg
✅ Recorded ./recordings/1696122271590-dimsey8_0.ogg

Code sample

import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream';
import { EndBehaviorType, VoiceReceiver } from '@discordjs/voice';
import type { User } from 'discord.js';
import * as prism from 'prism-media';

function getDisplayName(userId: string, user?: User) {
	return user ? `${user.username}_${user.discriminator}` : userId;
}

export function createListeningStream(receiver: VoiceReceiver, userId: string, user?: User) {
	const opusStream = receiver.subscribe(userId, {
		end: {
			behavior: EndBehaviorType.AfterSilence,
			duration: 1000,
		},
	});

	const oggStream = new prism.opus.OggLogicalBitstream({
		opusHead: new prism.opus.OpusHead({
			channelCount: 2,
			sampleRate: 48000,
		}),
		pageSizeControl: {
			maxPackets: 10,
		},
	});

	const filename = `./recordings/${Date.now()}-${getDisplayName(userId, user)}.ogg`;

	const out = createWriteStream(filename);

	console.log(`👂 Started recording ${filename}`);

	pipeline(opusStream, oggStream, out, (err) => {
		if (err) {
			console.warn(`❌ Error recording file ${filename} - ${err.message}`);
		} else {
			console.log(`✅ Recorded ${filename}`);
		}
	});
}

@discordjs/version version

@discordjs/[email protected]

Node.js version

[email protected]

Operating system

MacOS m1

Priority this issue should have

Medium (should be fixed soon)

I have tested this issue on a development release

No response

@seanroades seanroades added bug Something isn't working need repro labels Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need repro
Projects
None yet
Development

No branches or pull requests

1 participant