Skip to content

Commit

Permalink
Revert "voice: remove passes (discord will begin dropping duplicated …
Browse files Browse the repository at this point in the history
…audio packets from tomorrow, you should not set passes > 1)"

This reverts commit 8457b88.
  • Loading branch information
samsamson33 committed Feb 27, 2020
1 parent 73c8c77 commit 94bd9f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
5 changes: 4 additions & 1 deletion docs/topics/voice.md
Expand Up @@ -70,10 +70,13 @@ We can also pass in options when we first play the stream:

```js
const dispatcher = connection.play('/home/discord/audio.mp3', {
volume: 0.5
volume: 0.5,
passes: 3
});
```

These are just a subset of the options available (consult documentation for a full list). Most users may be interested in the `passes` option, however. As audio is sent over UDP, there is a chance packets may not arrive. Increasing the number of passes, e.g. to `3` gives you a better chance that your packets reach your recipients, at the cost of triple the bandwidth. We recommend not going over 5 passes.

### What can I play?

Discord.js allows you to play a lot of things:
Expand Down
23 changes: 13 additions & 10 deletions src/client/voice/dispatcher/StreamDispatcher.js
Expand Up @@ -33,9 +33,9 @@ const nonce = Buffer.alloc(24);
class StreamDispatcher extends Writable {
constructor(
player,
{ seek = 0, volume = 1, fec, plp, bitrate = 96, highWaterMark = 12 } = {},
{ seek = 0, volume = 1, passes = 1, fec, plp, bitrate = 96, highWaterMark = 12 } = {},
streams) {
const streamOptions = { seek, volume, fec, plp, bitrate, highWaterMark };
const streamOptions = { seek, volume, passes, fec, plp, bitrate, highWaterMark };
super(streamOptions);
/**
* The Audio Player that controls this dispatcher
Expand Down Expand Up @@ -289,21 +289,24 @@ class StreamDispatcher extends Writable {
}

_sendPacket(packet) {
let repeats = this.streamOptions.passes;
/**
* Emitted whenever the dispatcher has debug information.
* @event StreamDispatcher#debug
* @param {string} info The debug info
*/
this._setSpeaking(1);
if (!this.player.voiceConnection.sockets.udp) {
this.emit('debug', 'Failed to send a packet - no UDP socket');
return;
while (repeats--) {
if (!this.player.voiceConnection.sockets.udp) {
this.emit('debug', 'Failed to send a packet - no UDP socket');
return;
}
this.player.voiceConnection.sockets.udp.send(packet)
.catch(e => {
this._setSpeaking(0);
this.emit('debug', `Failed to send a packet - ${e}`);
});
}
this.player.voiceConnection.sockets.udp.send(packet)
.catch(e => {
this._setSpeaking(0);
this.emit('debug', `Failed to send a packet - ${e}`);
});
}

_setSpeaking(value) {
Expand Down
1 change: 1 addition & 0 deletions src/client/voice/util/PlayInterface.js
Expand Up @@ -11,6 +11,7 @@ const { Error } = require('../../../errors');
* @property {number} [seek=0] The time to seek to, will be ignored when playing `ogg/opus` or `webm/opus` streams
* @property {number|boolean} [volume=1] The volume to play at. Set this to false to disable volume transforms for
* this stream to improve performance.
* @property {number} [passes=1] How many times to send the voice packet to reduce packet loss
* @property {number} [plp] Expected packet loss percentage
* @property {boolean} [fec] Enabled forward error correction
* @property {number|string} [bitrate=96] The bitrate (quality) of the audio in kbps.
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -2514,6 +2514,7 @@ declare module 'discord.js' {
type?: StreamType;
seek?: number;
volume?: number | boolean;
passes?: number;
plp?: number;
fec?: boolean;
bitrate?: number | 'auto';
Expand Down

0 comments on commit 94bd9f6

Please sign in to comment.