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

playOpusStream() broken #2079

Closed
1 of 2 tasks
TheBITLINK opened this issue Oct 30, 2017 · 6 comments
Closed
1 of 2 tasks

playOpusStream() broken #2079

TheBITLINK opened this issue Oct 30, 2017 · 6 comments

Comments

@TheBITLINK
Copy link

TheBITLINK commented Oct 30, 2017

Please describe the problem you are having in as much detail as possible:
After updating to discord.js 11.2.1, the play playOpusStream() function stopped working properly.

This is the traceback given by the error handler:

TypeError: Cannot read property 'encode' of undefined
    at StreamDispatcher.sendBuffer (/home/thebitlink/Documents/nodeproj/djsbug/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:133:55)
    at StreamDispatcher.process (/home/thebitlink/Documents/nodeproj/djsbug/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:243:14)
    at player.voiceConnection.voiceManager.client.setTimeout (/home/thebitlink/Documents/nodeproj/djsbug/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:232:79)
    at Timeout.setTimeout [as _onTimeout] (/home/thebitlink/Documents/nodeproj/djsbug/node_modules/discord.js/src/client/Client.js:422:7)
    at ontimeout (timers.js:469:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:264:5)

Include a reproducible code sample here, if possible:

const { spawn } = require('child_process')
const Discord = require('discord.js')
const client = new Discord.Client()

client.on('message', async (m) => {
  if (m.content !== '-opustest') return

  const vc = await m.member.voiceChannel.join()
  const ffmpeg = spawn('ffmpeg', [
    '-i', 'test.mp3',
    '-f', 'data',
    '-map', '0:a',
    '-ar', '48k',
    '-acodec', 'libopus',
    '-sample_fmt', 's16',
    '-vbr', 'off',
    '-b:a', '64000',
    'pipe:1'
  ])
  const stream = vc.playOpusStream(ffmpeg.stdout)

  stream.on('end', () => vc.disconnect())
  stream.on('error', (e) => console.error(e))
})

client.login(process.env.BOT_TOKEN)

(The code above works perfectly fine on d.js 11.1.0, which is the version i was using before)

Further details:

  • discord.js version: 11.2.1
  • node.js version: 8.6.0
  • Operating system: Tested on both Linux and Windows
  • Priority this issue should have – please be realistic and elaborate if possible: High, while this has a very specific use and is not used by many people, i discovered this because a user was having issues installing my bot. The broken package is already live on npm, and doing npm install with discord.js@^11.0.0 as a dependency will automatically install the latest version.
  • I found this issue while running code on a user account
  • I have also tested the issue on latest master, commit hash:29a81ea
@amishshah
Copy link
Member

If you're able to, can you test to see if this is fixed in the voice rewrite branch?

@TheBITLINK
Copy link
Author

I get an entirely different issue in the voice-rewrite branch.

The function does indeed work, but large chunks of the stream are just ignored and skipped.

Here's a video. It's supposed to be a 4 minute long track.

I'm using the exact same code sample.

@amishshah
Copy link
Member

Ok, I can reproduce this and am looking for a fix.

@amishshah
Copy link
Member

amishshah commented Nov 3, 2017

I've looked into it and the way the new voice rewrite works, I don't think it'll be possible to get this to work. Because now, StreamDispatcher is a writable stream and we pipe your input into it, so once the high watermark of the dispatcher is reached, the output from ffmpeg will get "squashed" together and all the packets will be sent as a single packet, which ends up with a lot of data being lost.

We'll probably introduce a nicer way for discord.js to handle this for you in the voice rewrite, but for now you can use prism-media (it comes installed with the voice rewrite!) to handle this. All you have to do is make sure your ffmpeg output is in an ogg container (switch -f data to -f opus) and then do this:

const prism = require('prism-media'); // use indev branch

connection.playOpusStream(ffmpegStream.pipe(new prism.OggOpusDemuxer()));

@kashalls
Copy link

kashalls commented Dec 3, 2017

Can confirm that the rewrite fixes the issue in 11.1 and up.

SpaceEEC added a commit that referenced this issue Feb 5, 2018
This fixes #2079 (VoiceConnection#playOpusStream being broken)
@SpaceEEC
Copy link
Member

SpaceEEC commented Feb 5, 2018

Should be fixed with the referenced commit.

@SpaceEEC SpaceEEC closed this as completed Feb 5, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 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

5 participants