Skip to main content

Documentation Index

Fetch the complete documentation index at: https://rockboxzig.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

bun add @rockbox-zig/sdk
# or
npm install @rockbox-zig/sdk
rockboxd must be running and reachable. By default the SDK connects to http://localhost:6062/graphql.

Quick start

import { RockboxClient, PlaybackStatus } from '@rockbox-zig/sdk';

const client = new RockboxClient();

client.connect();   // optional — opens the WebSocket

const track = await client.playback.currentTrack();
if (track) console.log(`Now playing: ${track.title}${track.artist}`);

const { albums } = await client.library.search('dark side');
await client.playback.playAlbum(albums[0].id, { shuffle: true });

client.on('track:changed', (t) => console.log(`▶ ${t.title} by ${t.artist}`));

client.disconnect();

Configuration

new RockboxClient();                                       // localhost:6062
new RockboxClient({ host: '192.168.1.42', port: 6062 });
new RockboxClient({                                        // behind a reverse proxy
  httpUrl: 'https://music.home/graphql',
  wsUrl:   'wss://music.home/graphql',
});
OptionDefaultDescription
hostlocalhostHostname or IP of rockboxd
port6062GraphQL port
httpUrlhttp://{host}:{port}/graphqlOverride the full HTTP URL
wsUrlws://{host}:{port}/graphqlOverride the full WebSocket URL

Domains

NamespaceWhat it does
client.playbackTransport, current/next track, play helpers
client.libraryAlbums, artists, tracks, search, likes, scan
client.playlistThe active queue
client.savedPlaylistsPersistent playlists & folders
client.smartPlaylistsRule-based playlists & listening stats
client.soundVolume control
client.settingsGlobal EQ / ReplayGain / crossfade / shuffle / …
client.systemVersion, runtime info
client.browseFilesystem browser
client.devicesCast / source device discovery

Playback shortcuts

await client.playback.playTrack('/Music/Pink Floyd/Wish You Were Here.mp3');
await client.playback.playAlbum('album-id', { shuffle: true });
await client.playback.playAlbum('album-id', { position: 3 });
await client.playback.playArtist('artist-id', { shuffle: true });
await client.playback.playPlaylist('playlist-id', { shuffle: true });
await client.playback.playDirectory('/Music/Jazz', { recurse: true, shuffle: true });
await client.playback.playLikedTracks({ shuffle: true });
await client.playback.playAllTracks({ shuffle: true });

Queue management

import { InsertPosition } from '@rockbox-zig/sdk';

await client.playlist.insertTracks(
  ['/Music/track1.mp3', '/Music/track2.mp3'],
  InsertPosition.Next,
);
await client.playlist.insertTracks(paths, InsertPosition.Last);
await client.playlist.insertTracks(paths, InsertPosition.First);   // replace
await client.playlist.insertDirectory('/Music/Ambient', InsertPosition.Last);
await client.playlist.insertAlbum('album-id', InsertPosition.Next);
await client.playlist.removeTrack(2);
await client.playlist.clear();
await client.playlist.shuffle();
InsertPositionEffect
NextAfter the currently playing track
AfterCurrentAfter the last manually inserted track
LastAt the end of the queue
FirstReplace the entire queue

Real-time events

client.connect();

client.on('track:changed',    (t) => updateNowPlaying(t));
client.on('status:changed',   (s) => setStatusBadge(s));
client.on('playlist:changed', (q) => renderQueue(q.tracks));

client.on('ws:error', (err) => console.error(err.message));
client.once('track:changed', (t) => console.log('first event:', t.title));

client.off('track:changed', handler);

Plugins

Drop-in cross-cutting features. Inspired by Jellyfin’s IPlugin.
import type { RockboxPlugin } from '@rockbox-zig/sdk';

export const Notifications: RockboxPlugin = {
  name: 'desktop-notifications',
  version: '1.0.0',

  install({ events }) {
    if (typeof Notification === 'undefined') return;
    Notification.requestPermission();
    events.on('track:changed', (t) => {
      new Notification(t.title, { body: `${t.artist} · ${t.album}`, icon: t.albumArt ?? undefined });
    });
  },
};

await client.use(Notifications);
client.installedPlugins().forEach((p) => console.log(`${p.name} v${p.version}`));
await client.unuse('desktop-notifications');

Error handling

import { RockboxNetworkError, RockboxGraphQLError, RockboxError } from '@rockbox-zig/sdk';

try {
  await client.playback.play();
} catch (err) {
  if (err instanceof RockboxNetworkError)  showOfflineBanner(err.message);
  else if (err instanceof RockboxGraphQLError) console.error(err.errors);
  else if (err instanceof RockboxError)    console.error('Rockbox error:', err.message);
}

Raw queries

const data = await client.query<{ rockboxVersion: string }>(`query { rockboxVersion }`);
Full reference, more examples and the plugin system deep-dive: see the SDK README on GitHub ↗.