import radiomanifest from "@radiomanifest/radiomanifest";

const knownRadios = [
  "https://www.ondarossa.info",
  "https://radiospore.oziosi.org",
];
class Controller {
  constructor() {
    this.cache = {};
    this.currentRadio = null;

    for (let r in knownRadios) {
      this.get(r);
    }
  }

  async get(url) {
    if (this.cache[url]) {
      this.currentRadio = this.cache[url];
      return this.cache[url];
    }
    this.cache[url] = knownRadios[url];
    // fetch more data in background
    this.cache[url] = await radiomanifest.get(url);
    return this.cache[url];
  }
}

const ControllerSingleton = new Controller();
// console.log(ControllerSingleton);

export default ControllerSingleton;
