Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanMicai committed Feb 9, 2025
1 parent 6de5782 commit e385fa3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/services/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,23 @@ export default class {
}
}

private async createReadStream(options: {url: string; cacheKey: string; ffmpegInputOptions?: string[]; cache?: boolean; volumeAdjustment?: string}): Promise<Readable> {
private async createReadStream(options: {
url: string;
cacheKey: string;
ffmpegInputOptions?: string[];
cache?: boolean;
volumeAdjustment?: string;
}): Promise<Readable> {
return new Promise((resolve, reject) => {
const capacitor = new WriteStream();
let hasReturnedStreamClosed = false;

if (options?.cache) {
const cacheStream = this.fileCache.createWriteStream(this.getHashForCache(options.cacheKey));
capacitor.createReadStream().pipe(cacheStream);
capacitor.createReadStream()?.pipe(cacheStream);
}

const returnedStream = capacitor.createReadStream();
let hasReturnedStreamClosed = false;

const stream = ffmpeg(options.url)
.inputOptions(options?.ffmpegInputOptions ?? ['-re'])
Expand All @@ -689,13 +695,13 @@ export default class {
}
})
.on('start', command => {
debug(`Spawned ffmpeg with ${command as string}`);
debug(`Spawned ffmpeg with ${command}`);
});

stream.pipe(capacitor);

returnedStream.on('close', () => {
if (!options.cache) {
if (!options?.cache) {
stream.kill('SIGKILL');
}

Expand Down

0 comments on commit e385fa3

Please sign in to comment.