mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
Fix voice losing count
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -9,12 +9,15 @@ nonce.fill(0);
|
||||
* @extends {EventEmitter}
|
||||
*/
|
||||
class StreamDispatcher extends EventEmitter {
|
||||
constructor(player, stream) {
|
||||
constructor(player, stream, sd) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.stream = stream;
|
||||
this.streamingData = {
|
||||
channels: 2,
|
||||
count: sd.count,
|
||||
sequence: sd.sequence,
|
||||
timestamp: sd.timestamp,
|
||||
};
|
||||
this._startStreaming();
|
||||
this._triggered = false;
|
||||
@@ -151,9 +154,6 @@ class StreamDispatcher extends EventEmitter {
|
||||
this.stream.on('end', e => this._triggerTerminalState('end', e));
|
||||
this.stream.on('error', e => this._triggerTerminalState('error', e));
|
||||
const data = this.streamingData;
|
||||
data.count = 0;
|
||||
data.sequence = 0;
|
||||
data.timestamp = 0;
|
||||
data.length = 20;
|
||||
data.missed = 0;
|
||||
data.startTime = Date.now();
|
||||
|
||||
@@ -18,6 +18,12 @@ class VoiceConnectionPlayer extends EventEmitter {
|
||||
});
|
||||
this.speaking = false;
|
||||
this.processMap = new Map();
|
||||
this.dispatcher = null;
|
||||
this._streamingData = {
|
||||
count: 0,
|
||||
sequence: 0,
|
||||
timestamp: 0,
|
||||
};
|
||||
}
|
||||
|
||||
convertStream(stream) {
|
||||
@@ -31,6 +37,7 @@ class VoiceConnectionPlayer extends EventEmitter {
|
||||
}
|
||||
|
||||
_shutdown() {
|
||||
this.speaking = false;
|
||||
for (const stream of this.processMap.keys()) {
|
||||
this.killStream(stream);
|
||||
}
|
||||
@@ -38,6 +45,7 @@ class VoiceConnectionPlayer extends EventEmitter {
|
||||
|
||||
killStream(stream) {
|
||||
const streams = this.processMap.get(stream);
|
||||
this._streamingData = this.dispatcher.streamingData;
|
||||
this.emit('debug', 'cleaning up streams after end/error');
|
||||
if (streams) {
|
||||
if (streams.inputStream && streams.pcmConverter) {
|
||||
@@ -77,17 +85,18 @@ class VoiceConnectionPlayer extends EventEmitter {
|
||||
this.connection.websocket.send({
|
||||
op: Constants.VoiceOPCodes.SPEAKING,
|
||||
d: {
|
||||
speaking: value,
|
||||
speaking: true,
|
||||
delay: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
playPCMStream(pcmStream) {
|
||||
const dispatcher = new StreamDispatcher(this, pcmStream);
|
||||
const dispatcher = new StreamDispatcher(this, pcmStream, this._streamingData);
|
||||
dispatcher.on('speaking', value => this.setSpeaking(value));
|
||||
dispatcher.on('end', () => this.killStream(pcmStream));
|
||||
dispatcher.on('error', () => this.killStream(pcmStream));
|
||||
this.dispatcher = dispatcher;
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ const fs = require('fs');
|
||||
class DefaultPlayer extends BasePlayer {
|
||||
|
||||
playFile(file) {
|
||||
this._shutdown();
|
||||
return this.playStream(fs.createReadStream(file));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user