radiomanifest.js 712 B

1234567891011121314151617181920212223242526272829303132
  1. import radiomanifest from "@radiomanifest/radiomanifest";
  2. const knownRadios = [
  3. "https://www.ondarossa.info",
  4. "https://radiospore.oziosi.org",
  5. ];
  6. class Controller {
  7. constructor() {
  8. this.cache = {};
  9. this.currentRadio = null;
  10. for (let r in knownRadios) {
  11. this.get(r);
  12. }
  13. }
  14. async get(url) {
  15. if (this.cache[url]) {
  16. this.currentRadio = this.cache[url];
  17. return this.cache[url];
  18. }
  19. this.cache[url] = knownRadios[url];
  20. // fetch more data in background
  21. this.cache[url] = await radiomanifest.get(url);
  22. return this.cache[url];
  23. }
  24. }
  25. const ControllerSingleton = new Controller();
  26. // console.log(ControllerSingleton);
  27. export default ControllerSingleton;