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