Move file caching logic to new FileCache service

Also: removes the -re ffmpeg option.
If this option is passed, ffmpeg won't write to fs-capacitor (and the cache file) as fast as possible.
In other words, the cache file won't finish writing until the entire stream has been played.
This commit is contained in:
Max Isom 2021-11-19 12:13:45 -05:00
commit f5149dfaba
No known key found for this signature in database
GPG key ID: 25C9B1A7F6798880
12 changed files with 154 additions and 52 deletions
src/managers

View file

@ -2,25 +2,25 @@ import {inject, injectable} from 'inversify';
import {Client} from 'discord.js';
import {TYPES} from '../types.js';
import Player from '../services/player.js';
import Config from '../services/config.js';
import FileCacheProvider from '../services/file-cache.js';
@injectable()
export default class {
private readonly guildPlayers: Map<string, Player>;
private readonly cacheDir: string;
private readonly discordClient: Client;
private readonly fileCache: FileCacheProvider;
constructor(@inject(TYPES.Config) config: Config, @inject(TYPES.Client) client: Client) {
constructor(@inject(TYPES.FileCache) fileCache: FileCacheProvider, @inject(TYPES.Client) client: Client) {
this.guildPlayers = new Map();
this.cacheDir = config.CACHE_DIR;
this.discordClient = client;
this.fileCache = fileCache;
}
get(guildId: string): Player {
let player = this.guildPlayers.get(guildId);
if (!player) {
player = new Player(this.cacheDir, this.discordClient);
player = new Player(this.discordClient, this.fileCache);
this.guildPlayers.set(guildId, player);
}