Skip to Content
Documentation

Build an extension

What an extension is, the two places its code runs, and the ideas the rest of this section builds on.

An extension adds to Songstress: a source to search, lyrics, a scrobbler, a theme, a page of its own. It is a package: a folder with a manifest, songstress.json, at its root, and beside it whatever the manifest names. A theme is a manifest and its colours. A scrobbler is a manifest and one JavaScript file.

You write extensions against the songstress package on npm, the SDK. It holds the API's types, the manifest's schema and validator, a mock Songstress for your tests, and the songstress command that checks, builds, packs and runs an extension on your own server. Start with Your first extension.

Six ideas

The manifest declares, code attaches. Everything an extension adds is listed in the manifest: its commands, menu items, settings, pages, providers and the rest. Code gives each one its behaviour, by id. So an app can show an extension's menus and settings, and a listing can say what it does, without running a line of it.

Two entries, both optional. An extension's code is one JavaScript bundle for each side it runs on.

EntryRunsGood for
entry.serverOn the user's own server, in a sandbox, for every member and every appAnything that must work for a phone, or while no app is open: hearing plays, providers, jobs, routes, pages every app can draw
entry.clientInside one app, in a sandbox, while that app is openFollowing this device's player live, and interface that reacts at once

An app may not run client code at all, so what must work everywhere belongs in the server entry.

Code starts when it is needed. There is no "on start-up". Songstress starts an entry when something it declared is called for: a hook fires, a command runs, a provider is asked, a page is drawn, a job is due, a route is called. It may stop the entry again when it is idle. So an entry registers everything at its top level each time it starts, and keeps what must last in songstress.storage, never in a variable.

Hooks observe. A hook tells an extension what happened. Nothing waits for a listener, and no hook can refuse or delay anything: no extension can stall the music.

An extension adds, and never replaces. A provider answers beside Songstress's own sources, in the order the admin sets. An extension draws inside the places given to it, never over Songstress's own interface.

Nothing is allowed until a person allows it. The manifest asks for each permission with a reason in plain words. The server's admin grants them, and each member grants what concerns their own listening.

The sandbox

Your code runs with the JavaScript language and the songstress API, and nothing else.

  • There: ECMAScript 2023 (promises, async functions, iterators), timers, and console.log, which writes to the extension's log.
  • Not there: fetch (use songstress.net.fetch), the DOM, every Node.js API, the file system, eval, new Function and WebAssembly. On the server, don't count on URL, TextEncoder, crypto or Intl either, and dates are in UTC. Bundle what you need.
  • One file an entry. An entry is one classic script with everything bundled into it and no import or export left: a bundler's IIFE output. songstress build makes it for you.
  • Limits on the server: 64 MiB of memory and 30 seconds for one call (a hook, a command, a provider's answer). A timer doesn't keep a call alive past the promise it returned.
  • Limits in an app: client code that stops answering, or floods the app with messages, is stopped. An extension stopped again and again is switched off.
  • JSON at the border: everything that crosses between your code and Songstress is JSON. No functions, dates or binary values.

Where each part works

"Phone" means the iPhone, iPad and Android apps. A phone build made for an app store leaves out three things: the web views that run client code, free-form views, and the in-app catalogue of extensions. Everything an extension does on the server, its declared interface, its settings, and installing by link work in every build.

PartServerWeb and desktopPhonePhone build for a store
Server entry: hooks, providers, jobs, routesRuns hereReaches themReaches themReaches them
Client entry and its hooksRuns while the app is open; not yet on Windows and LinuxRuns while the app is open and in frontNot available
Commands with run: serverRuns hereYesYesYes
Commands with run: clientYes; not yet on Windows and LinuxYesNot available
MenusEvery locationEvery location but sidebar, in one "Extensions" submenuAs a phone
SettingsKept hereDrawnDrawnDrawn
Pages, panels and status items rendered by the serverRendered hereDrawnDrawnDrawn
Pages, panels and status items rendered by the clientDrawn; not yet on Windows and LinuxDrawnNot available
ViewsServes the filesA browser tab (web), the system's browser (desktop)The in-app browserNot available
ThemesAppliedAppliedApplied
ProvidersRuns hereShows the resultsShows the resultsShows the results
JobsRuns hereShown in ActivityShown in ActivityShown in Activity
Sign-inRuns here, and keeps the account's nameFrom the extension's pageAs the webAs the web

Nothing of an extension appears on a watch, in a car or in a widget.

Your code doesn't have to guess which app it is drawing for. Every render, and every command a person runs, is told the app in its context (client), and songstress.host.info() tells client code about its own app: its platform, the version of the components it draws (ui), and its capabilities (clientCode, views).

In this section

On this page