mirror of
https://github.com/danbulant/discord.js
synced 2026-06-08 09:13:22 +00:00
Receiver#createStream should take options
This commit is contained in:
parent
2c1a302eea
commit
4a1b55d145
2 changed files with 2 additions and 8 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue