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

Finish event doesn't get fired when the dispatcher gets ended while the stream is paused #4062

Closed
1 task done
DontBreakAlex opened this issue Apr 9, 2020 · 2 comments
Closed
1 task done

Comments

@DontBreakAlex
Copy link

Please describe the problem you are having in as much detail as possible:

Basicaly the same as issue #2648. Calling dispatcher.end() or .destroy() while the stream is paused does not emit the finish event.
Calling .destroy() willing cause the dispatcher to emit close, but no finish

Include a reproducible code sample here, if possible:

const Discord = require('discord.js');
const bot = new Discord.Client();

bot.on('message', async message => {
	if (!message.cleanContent.startsWith('ldt')) return;
	let connection = await message.member.voice.channel.join()
	let disp = connection.play('./file.mp3')
	disp.on('finish', () => {
		console.log('finish')
		connection.disconnect();
	})
	disp.on('close', () => console.log('close'))
	disp.on('warn', warn => console.log(warn))
	disp.on('error', err => console.log(err))
	setTimeout(() => disp.pause(), 5000);
	setTimeout(() => disp.end(), 8000);
})

Further details:

  • discord.js version: 12.1.1, 828640c
  • Node.js version: 12.14.1, 13.6.0
  • Operating system: Ubuntu 18.04, Debian 10
  • Priority this issue should have – please be realistic and elaborate if possible: Moderate
  • I have also tested the issue on latest master, commit hash: 828640c
@DontBreakAlex
Copy link
Author

This because the callback of _write is never called:

A fix is to call disp._writeCallback, bound here:

_step(done) {
this._writeCallback = () => {
this._writeCallback = null;
done();
};

Manually with the end() call:

setTimeout(() => { disp.end(); disp._writeCallback(); }, 8000);

Or in StreamDispatcher.pause(), but it has been removed in e0f5216, maybe for a reason.

@amishshah
Copy link
Member

Hi there,

We're working on a new implementation of Discord's Voice API that has better playback quality and is more reliable than what we currently support in Discord.js v12 - check it out at https://github.com/discordjs/voice!

The new library solves many of the issues that users are facing, and as part of this, we're dropping built-in support for voice in our next major release. We have a PR (#5402) that adds native support for our new voice library - once this PR is merged, this issue will be closed.

You can still use our new voice library before that PR lands - just take a look at our music bot example to see how to get started upgrading your voice code. By using the boilerplate music player in the example, you can make it even easier to upgrade your code.

Note that the PR above only reduces some of the boilerplate code you'd otherwise have to write - you do not have to wait for the PR to be merged to start using the new voice library.


If you have any questions about this, feel free to:

  • Make an issue if you have found a bug in the new voice library
  • Use GitHub Discussions or join our Discord server (we have a new channel, #djs-new-voice, specifically for this!) to ask general questions about the library, give feedback on the library, and get support with upgrading to it

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants