Skip to content

Modules reference ​

Everything a module can declare and do. For a walkthrough see Build your first module. The machine readable contract is in spec/modules/ (JSON Schemas and README.md).

Package ​

A module is one zip file:

PathNeededWhat
module.jsonyesThe manifest, first in the zip.
signaturenoBase64 ed25519 signature of the exact module.json bytes.
backend/<os>-<arch>/<file>noThe backend executable, one per platform.
ui/index.jsnoThe frontend, one ES module.

Every file other than module.json and signature must be listed in files with its sha256. A missing, extra or changed file stops the install. bspack pack writes files and the signature for you.

Manifest fields ​

FieldTypeRule
idstring^[a-z][a-z0-9_]{1,31}$. Unique. Used in URLs and storage.
namestring1 to 60 characters.
versionstringx.y.z. Installing a higher version upgrades. A lower one is refused.
bitstreamstringSupported Bitstream versions: >=1.0.0 <2.0.0, ^1.0.0, ~1.2.0 or *.
author, description, licensestringShown on the review screen. Description up to 500 characters.
permissionsstring[]Admin API scopes the module may use, plus client_routes.
backend.execobject"linux/amd64": "backend/linux-amd64/hello". Keys are Go GOOS/GOARCH.
ui.entrystringPath of the ES module in the zip.
hooks.filtersobject[]{name, fail_closed, timeout_ms}. See Filters.
hooks.eventsstring[]Event types to receive. See Events.
jobsobject[]{name, cron} with a 5 field cron. See Jobs.
settingsobjectJSON Schema of the settings form. See Settings.
i18nobjectFrontend strings per locale: en (required), pt-BR, es.
data_versionintegerVersion of the module's stored data. Default 0.
filesobjectpath: sha256 hex of every other file.

Permissions ​

PermissionLets the module
Any admin API scope (lines:read, streams:write, ...)Call those admin API endpoints through the api callback. The full list is x-scopes in spec/openapi/admin.yaml.
client_routesAnswer public URLs under /m/<id>/ on the client port.

The api callback runs as the module's own API key, named Module: <id>. It is limited to the granted scopes, to 600 requests per minute, and every change is in the audit log. It can never do what needs a signed in person: 2FA, passwords, API keys or modules.

Hooks need no permission of their own, but the review screen lists every hook so the admin sees what the module can change.

Backend process ​

  • Started by bs-control when the module is enabled. Working folder: <modules dir>/<id>/<version>. Clean environment: PATH, HOME, BS_MODULE_ID. No database or Redis password.
  • JSON-RPC 2.0 on stdin and stdout, one JSON object per line, up to 16 MiB. stderr goes to the module log.
  • Settings changes restart the process. Stopping closes stdin, then kills the process after 5 s.
  • Methods and payloads: spec/modules/README.md.
From controlDeadline
init10 s
filtertimeout_ms, default 200 ms, at most 2000
event5 s
http10 s
job60 s
From moduleDoes
apiAdmin API call as the module's key. Path relative to /api/v1.
kv.get, kv.set, kv.delete, kv.listThe module's own storage.
log (notification)A line in the module log.

Filters ​

Filters run while a viewer waits. Modules run in id order; each one gets the previous one's output.

HookRuns onDataReturn
playlistget.phpline, type, entries[] (kind, id, name, tvg_id, logo, group, url){"data": {...}} with the entries to write
player_apiplayer_api.phpline, action (login or the get_* action), body{"data": {...}} with the new body
play.authorizestream URLs, before a connection slot is takenline, kind, content_id, ip, user_agent, country, asn{"allow": bool, "reason": "..."}
  • Playlist URLs hold {username} and {password} placeholders. Modules never see line passwords. Entries you add can use them too.
  • play.authorize: the first deny wins. The viewer gets 403 with your reason. Keep it short.
  • When a module fails or is too slow it is skipped (fail-open). With "fail_closed": true the request fails instead, and play.authorize denies. Use it only when letting the request through would be worse than an outage.
  • Filtered responses are not served from the pre-gzipped cache, so every filter has a cost on busy panels.

Events ​

Events are sent after the change is saved, at least once. After a crash the same event can arrive twice: dedupe with id.

TypeWhenData
line.createdA line was createdline_id, username, owner_id, package_id, exp_date, max_connections
stream.failedA node reports a stream in errorstream_id, node_id, state, reason, error
stream.failoverA stream moved to a backup sourcestream_id, node_id, state, source_index, reason

Answer {} to acknowledge. An error or no answer means the control sends it again later. Events wait in the Redis stream bs:mod:events (kept 24 h, trimmed to about 10 000 entries).

Routes ​

URLWho can callSent to the module as
/api/v1/modules/<id>/api/<path>signed in admins and API keys with modules:readhttp with user set, client: false
/m/<id>/<path> (client port)anyone, if the module has client_routeshttp with user: null, client: true, ip

The module answers {status, headers, body}. When it is not running the panel answers 503 module_unavailable. Client routes get the client API rate limit. A line named m loses the short /m/<pass>/<id> URL form; its other URLs keep working.

Jobs ​

jobs: [{"name": "tick", "cron": "*/5 * * * *"}]. Cron fields: minute, hour, day, month, weekday, with *, a, a-b, lists and /step. Times use the panel timezone (Settings, General). Each run takes a Redis lock (bs:mod:job:<id>:<name>:<minute>), so a job runs once per matching minute.

Storage (KV) ​

LimitValue
Keyup to 200 characters
Valueany JSON, up to 64 KiB
Keys per module10 000

Data stays on upgrade. On uninstall the admin chooses to keep it or delete it. Modules cannot run SQL: a module with the control's database access could read every table.

On upgrade, init gets data_version_from (the old data_version). Migrate your keys there before you answer. It is null on a fresh install.

Settings ​

settings is a JSON Schema subset. The panel draws a form from it and checks values before saving.

json
{
  "type": "object",
  "properties": {
    "prefix": { "type": "string", "title": "Name prefix", "maxLength": 20, "default": "" },
    "limit": { "type": "integer", "title": "Limit", "minimum": 0, "maximum": 10, "default": 3 },
    "mode": { "type": "string", "enum": ["fast", "safe"], "default": "safe" },
    "on": { "type": "boolean", "title": "Turn on", "default": true }
  }
}

Supported: type (string, number, integer, boolean), title, description, default, enum, minimum, maximum, maxLength. Settings are stored in plain text: do not put passwords or tokens there.

Frontend ​

ui/index.js is one ES module. The panel loads it after an admin signs in, with Subresource Integrity, from /api/v1/modules/<id>/ui/<sha256>.js. The CSP stays strict: no inline scripts, no eval.

  • Do not bundle Vue. Use the panel's copy at window.bitstream.vue (the hello example has a 10 line Vite plugin for this). Templates must be precompiled.
  • The panel's Tailwind only has the classes the panel itself uses. Prefer inline styles or sdk.ui components.
  • A frontend module runs with the signed in admin's power. The scoped sdk.api is a guardrail, not a security boundary.
js
window.bitstream.register('hello', (sdk) => {
  sdk.page({ id: 'index', label: 'nav', component: HelloPage })
})

The sdk object:

MemberWhat
id, sdkVersionModule id, SDK version (1).
vueThe panel's Vue.
settingsCurrent settings values.
t(key, params)Your i18n strings (mod.<id>.<key>).
api.get/post/put/patch/delete(path, ...)Your routes, /api/v1/modules/<id>/api/<path>.
api.admin.get(path, query)Read-only admin API calls allowed by your *:read permissions.
uiA few panel components (Button, Input).

Slots. Labels and titles are keys of your i18n strings, or plain text:

CallShows
sdk.page({id, label, component, icon?})Menu item and page at /ext/<id> (id: 'index') or /ext/<id>-<page id>.
sdk.dashboardWidget({id, title, component})A card on the admin dashboard.
sdk.detailSection('stream', {id, title, component})A section on the channel editor. The component gets entityId.
sdk.tableColumn('lines', {id, header, value(row)})A column in the lines table. value returns text and may read reactive state.
sdk.formField('line', {id, label, description?, component?, load?(id), save(id, value)})A field on the line form. Without component it is a text input. save runs after the line is saved.

Disabling the module removes all of it at once.

Signing ​

  • bspack keygen prints a public and a private key (base64 ed25519).
  • The admin adds the public key to the trusted keys on the Modules page.
  • bspack pack -key private.key writes signature. It covers module.json, which pins every file by hash.
  • Unsigned packages install only in developer mode. A bad signature is always refused.

Health and safety ​

  • The Modules page shows state, restarts, calls, errors, timeouts, p95 latency, the last error and the last 500 log lines (24 h).
  • After 5 failures in a row (crash, timeout or error) the module is turned off and the reason is shown. Fix it, then enable it again.
  • Safe mode loads no module at all: no process, hook, route or frontend. Turn it on from the Modules page, or set BS_MODULES_SAFE_MODE=1 and restart bs-control when the panel does not open.
  • Every install, upgrade, enable, disable, settings change and uninstall is in the audit log.
  • Optional modules.user (Linux) runs modules as another system user, so they cannot read control files.
  • Nodes run nothing. Node events reach modules through the control.

Bitstream documentation