mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
fix some stuff
This commit is contained in:
@@ -41,6 +41,7 @@ class VoiceConnection extends EventEmitter {
|
|||||||
|
|
||||||
this.player.on('error', e => {
|
this.player.on('error', e => {
|
||||||
this.emit('warn', e);
|
this.emit('warn', e);
|
||||||
|
console.log('so yeah uh'+e);
|
||||||
this.player.cleanup();
|
this.player.cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ class VoiceWebSocket extends EventEmitter {
|
|||||||
send(data) {
|
send(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.ws.readyState === WebSocket.OPEN) {
|
if (this.ws.readyState === WebSocket.OPEN) {
|
||||||
console.log('sending', data);
|
|
||||||
this.ws.send(data, null, error => {
|
this.ws.send(data, null, error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class StreamDispatcher extends EventEmitter {
|
|||||||
_sendBuffer(buffer, sequence, timestamp) {
|
_sendBuffer(buffer, sequence, timestamp) {
|
||||||
let repeats = this.passes;
|
let repeats = this.passes;
|
||||||
const packet = this._createPacket(sequence, timestamp, this.player.opusEncoder.encode(buffer));
|
const packet = this._createPacket(sequence, timestamp, this.player.opusEncoder.encode(buffer));
|
||||||
while (repeats--) this.player.voiceConnection.sockets.udp.send(packet);
|
while (repeats--) this.player.voiceConnection.sockets.udp.send(packet).catch(e => console.log('so uhhh', e));
|
||||||
}
|
}
|
||||||
|
|
||||||
_createPacket(sequence, timestamp, buffer) {
|
_createPacket(sequence, timestamp, buffer) {
|
||||||
|
|||||||
@@ -7,9 +7,36 @@ class PCMConversionProcess extends EventEmitter {
|
|||||||
constructor(process) {
|
constructor(process) {
|
||||||
super();
|
super();
|
||||||
this.process = process;
|
this.process = process;
|
||||||
|
this.input = null;
|
||||||
this.process.on('error', e => this.emit('error', e));
|
this.process.on('error', e => this.emit('error', e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInput(stream) {
|
||||||
|
this.input = stream;
|
||||||
|
stream.pipe(this.process.stdin, { end: false });
|
||||||
|
this.input.on('error', e => this.emit('error', e));
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.emit('debug', 'destroying a ffmpeg process:');
|
||||||
|
if (this.input && this.input.unpipe && this.process.stdin) {
|
||||||
|
this.input.unpipe(this.process.stdin);
|
||||||
|
this.emit('unpiped the user input stream from the process input stream');
|
||||||
|
}
|
||||||
|
if (this.process.stdin) {
|
||||||
|
this.process.stdin.end();
|
||||||
|
this.emit('ended the process stdin');
|
||||||
|
}
|
||||||
|
if (this.process.stdin.destroy) {
|
||||||
|
this.process.stdin.destroy();
|
||||||
|
this.emit('destroyed the process stdin');
|
||||||
|
}
|
||||||
|
if (this.process.kill) {
|
||||||
|
this.process.kill();
|
||||||
|
this.emit('killed the process');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FfmpegConverterEngine extends ConverterEngine {
|
class FfmpegConverterEngine extends ConverterEngine {
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ class AudioPlayer extends EventEmitter {
|
|||||||
stream.on('end', () => {
|
stream.on('end', () => {
|
||||||
|
|
||||||
console.log(Date.now(), 'real input stream ended');
|
console.log(Date.now(), 'real input stream ended');
|
||||||
})
|
});
|
||||||
|
stream.on('error', e => this.emit('error', e));
|
||||||
const conversionProcess = this.audioToPCM.createConvertStream(0);
|
const conversionProcess = this.audioToPCM.createConvertStream(0);
|
||||||
stream.pipe(conversionProcess.process.stdin, { end: false });
|
conversionProcess.setInput(stream);
|
||||||
return this.playPCMStream(conversionProcess.process.stdout, conversionProcess);
|
return this.playPCMStream(conversionProcess.process.stdout, conversionProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,12 +38,7 @@ class AudioPlayer extends EventEmitter {
|
|||||||
console.log(Date.now(), 'clean up triggered due to', reason);
|
console.log(Date.now(), 'clean up triggered due to', reason);
|
||||||
const filter = checkStream && this.currentDispatcher && this.currentDispatcher.stream === checkStream;
|
const filter = checkStream && this.currentDispatcher && this.currentDispatcher.stream === checkStream;
|
||||||
if (this.currentConverter && (checkStream ? filter : true)) {
|
if (this.currentConverter && (checkStream ? filter : true)) {
|
||||||
if (this.currentConverter.process.stdin.destroy) {
|
this.currentConverter.destroy();
|
||||||
this.currentConverter.process.stdin.destroy();
|
|
||||||
}
|
|
||||||
if (this.currentConverter.process.kill) {
|
|
||||||
this.currentConverter.process.kill();
|
|
||||||
}
|
|
||||||
this.currentConverter = null;
|
this.currentConverter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,6 +61,7 @@ class AudioPlayer extends EventEmitter {
|
|||||||
dispatcher.on('end', () => this.cleanup(dispatcher.stream, 'disp ended'));
|
dispatcher.on('end', () => this.cleanup(dispatcher.stream, 'disp ended'));
|
||||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||||
this.currentDispatcher = dispatcher;
|
this.currentDispatcher = dispatcher;
|
||||||
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ client.on('channelCreate', channel => {
|
|||||||
console.log(`made ${channel.name}`);
|
console.log(`made ${channel.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('debug', m => console.log('debug', m));
|
|
||||||
client.on('error', m => console.log('debug', m));
|
client.on('error', m => console.log('debug', m));
|
||||||
client.on('reconnecting', m => console.log('debug', m));
|
client.on('reconnecting', m => console.log('debug', m));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user