changed some stuff regarding backpressure
This commit is contained in:
parent
2a99927a13
commit
00041f86d6
1 changed files with 12 additions and 1 deletions
|
@ -81,9 +81,20 @@ class AudioServer {
|
||||||
const timestamp = Date.now();
|
const timestamp = Date.now();
|
||||||
const stream = fs.createReadStream(this.buffer.file);
|
const stream = fs.createReadStream(this.buffer.file);
|
||||||
stream.on('data', (data) => {
|
stream.on('data', (data) => {
|
||||||
|
const backpressure = false;
|
||||||
for (let index = 0; index < this.clients.length; index++) {
|
for (let index = 0; index < this.clients.length; index++) {
|
||||||
this.clients[index].audiosocket.write(data);
|
if (!this.clients[index].audiosocket.write(data)) {
|
||||||
|
backpressure = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (backpressure === true) {
|
||||||
|
logger.debug('BACKPRESSURE DETECTED - PAUSING STREAM!');
|
||||||
|
stream.pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
stream.on('drain', () => {
|
||||||
|
logger.debug('STREAM IS DRAINED - RESUMING!');
|
||||||
|
stream.resume();
|
||||||
});
|
});
|
||||||
stream.on('close', () => {
|
stream.on('close', () => {
|
||||||
for (let index = 0; index < this.clients.length; index++) {
|
for (let index = 0; index < this.clients.length; index++) {
|
||||||
|
|
Loading…
Reference in a new issue