mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
Receiver#createStream should take options
This commit is contained in:
@@ -10,12 +10,12 @@ class VoiceReceiver extends EventEmitter {
|
|||||||
this.connection.sockets.udp.socket.on('message', buffer => this.packets.push(buffer));
|
this.connection.sockets.udp.socket.on('message', buffer => this.packets.push(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
createStream(user, pcm=false) {
|
createStream(user, { mode = 'opus' } = {}) {
|
||||||
user = this.connection.client.users.resolve(user);
|
user = this.connection.client.users.resolve(user);
|
||||||
if (!user) throw new Error('VOICE_USER_MISSING');
|
if (!user) throw new Error('VOICE_USER_MISSING');
|
||||||
console.log('making stream for', user.tag);
|
console.log('making stream for', user.tag);
|
||||||
const stream = this.packets.makeStream(user.id);
|
const stream = this.packets.makeStream(user.id);
|
||||||
if (pcm) {
|
if (mode === 'pcm') {
|
||||||
const decoder = new prism.opus.Decoder({ channels: 2, rate: 48000, frameSize: 1920 });
|
const decoder = new prism.opus.Decoder({ channels: 2, rate: 48000, frameSize: 1920 });
|
||||||
stream.pipe(decoder);
|
stream.pipe(decoder);
|
||||||
return decoder;
|
return decoder;
|
||||||
|
|||||||
@@ -3,15 +3,9 @@ const { Readable } = require('stream');
|
|||||||
class VoiceReadable extends Readable {
|
class VoiceReadable extends Readable {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this._packets = [];
|
|
||||||
this.open = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_read() {} // eslint-disable-line no-empty-function
|
_read() {} // eslint-disable-line no-empty-function
|
||||||
|
|
||||||
_push(d) {
|
|
||||||
if (this.open) this.push(d);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = VoiceReadable;
|
module.exports = VoiceReadable;
|
||||||
|
|||||||
Reference in New Issue
Block a user