index ↓

asset

client.asset

Binary assets such as cover art, addressed by an opaque id. get returns bytes, preload fetches ahead of time, and onReady and onCleared track which ids are available.

requests

you ask, the daemon answers. await the tagged result and check .ok

get(AssetGet): Promise<TypedRequestResult<AssetGot, AssetNotFound>>

push form: onGot (subscribe instead of awaiting)

Returns the bytes for an asset id.

const res = await client.asset.get({ id: '...', requestId: '...' });
if (res.ok) {
  console.log(res.response.requestId);
} else {
  console.warn(res.kind, res.error);
}

commands

fire-and-forget. the promise resolves once the daemon has taken the message

preload(AssetPreload): Promise<void>

await client.asset.preload({ ids: [] });

events

the daemon pushes these unprompted. subscribing returns an unsubscribe function

onReady(handler: (AssetReady) => void): () => void

const off = client.asset.onReady((assetReady) => {
  console.log(assetReady.id);
});
// call off() to unsubscribe

onCleared(handler: (AssetCleared) => void): () => void

const off = client.asset.onCleared((assetCleared) => {
  console.log(assetCleared.id);
});
// call off() to unsubscribe

types

shapes referenced above, as the sdk types them

type AssetReady = {
  id: string;
};
type AssetCleared = {
  id: string;
};

Returns the bytes for an asset id.

type AssetGet = {
  id: string;
  requestId: string; // Any uuid you choose.
};
type AssetGot = {
  requestId: string;
  id: string;
  bytes: Uint8Array;
  mime?: string; // Null when the source gives none.
};
type AssetNotFound = {
  requestId: string;
  id: string;
};
type AssetPreload = {
  ids: string[]; // Only the first 64 are used.
};