A music player that connects to your cloud/distributed storage. diffuse.sh
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import { debounce } from "throttle-debounce";
import * as Output from "~/common/output.js";import foundation from "~/common/foundation.js";import { effect } from "~/common/signal.js";
const KEY = "facets/data/process-tracks/timestamp";const MAX_TIME_DIFF = 10 * 60 * 1000;
////////////////////////////////////////////// ON LOAD////////////////////////////////////////////
const output = await foundation.orchestrator.output();await Output.data(output.tracks);
const lastTimestamp = localStorage.getItem(KEY);const now = Date.now();const diff = lastTimestamp ? now - JSON.parse(lastTimestamp) : MAX_TIME_DIFF;
const orchestrator = await foundation.orchestrator.processTracks({ disableWhenReady: true,});
if (diff >= MAX_TIME_DIFF) { // Wait until we're actually done processing, only then set the timestamp await orchestrator.process(); localStorage.setItem(KEY, JSON.stringify(now));}
////////////////////////////////////////////// WHEN SOURCES CHANGE////////////////////////////////////////////
const { sources } = await foundation.orchestrator.sources();let initialised = false;
const debounced = debounce( 2500, /** @param {import("@specs/components/input/types.d.ts").Source} _sources */ async ( _sources, ) => { if (initialised) orchestrator.process(); else initialised = true; }, { atBegin: false },);
effect(() => { debounced(sources());});