mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
Fix voice speed issues, fixes #672
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -27,6 +27,7 @@ class StreamDispatcher extends EventEmitter {
|
|||||||
count: 0,
|
count: 0,
|
||||||
sequence: sd.sequence,
|
sequence: sd.sequence,
|
||||||
timestamp: sd.timestamp,
|
timestamp: sd.timestamp,
|
||||||
|
pausedTime: 0,
|
||||||
};
|
};
|
||||||
this._startStreaming();
|
this._startStreaming();
|
||||||
this._triggered = false;
|
this._triggered = false;
|
||||||
@@ -95,17 +96,23 @@ class StreamDispatcher extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.paused) {
|
if (this.paused) {
|
||||||
data.timestamp = data.timestamp + 4294967295 ? data.timestamp + 960 : 0;
|
// data.timestamp = data.timestamp + 4294967295 ? data.timestamp + 960 : 0;
|
||||||
|
data.pausedTime += data.length * 10;
|
||||||
this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setSpeaking(true);
|
this._setSpeaking(true);
|
||||||
|
|
||||||
|
if (!data.startTime) {
|
||||||
|
data.startTime = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
const bufferLength = 1920 * data.channels;
|
const bufferLength = 1920 * data.channels;
|
||||||
let buffer = this.stream.read(bufferLength);
|
let buffer = this.stream.read(bufferLength);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
data.missed++;
|
data.missed++;
|
||||||
|
data.pausedTime += data.length * 10;
|
||||||
this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -126,8 +133,8 @@ class StreamDispatcher extends EventEmitter {
|
|||||||
|
|
||||||
this._sendBuffer(buffer, data.sequence, data.timestamp);
|
this._sendBuffer(buffer, data.sequence, data.timestamp);
|
||||||
|
|
||||||
const nextTime = data.startTime + (data.count * data.length);
|
const nextTime = data.length + (data.startTime + data.pausedTime + (data.count * data.length) - Date.now());
|
||||||
this.player.connection.manager.client.setTimeout(() => this._send(), data.length + (nextTime - Date.now()));
|
this.player.connection.manager.client.setTimeout(() => this._send(), nextTime);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._triggerTerminalState('error', e);
|
this._triggerTerminalState('error', e);
|
||||||
}
|
}
|
||||||
@@ -187,7 +194,6 @@ class StreamDispatcher extends EventEmitter {
|
|||||||
const data = this.streamingData;
|
const data = this.streamingData;
|
||||||
data.length = 20;
|
data.length = 20;
|
||||||
data.missed = 0;
|
data.missed = 0;
|
||||||
data.startTime = Date.now();
|
|
||||||
|
|
||||||
this.stream.once('readable', () => this._send());
|
this.stream.once('readable', () => this._send());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user