Appearance
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:
| Path | Needed | What |
|---|---|---|
module.json | yes | The manifest, first in the zip. |
signature | no | Base64 ed25519 signature of the exact module.json bytes. |
backend/<os>-<arch>/<file> | no | The backend executable, one per platform. |
ui/index.js | no | The 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
| Field | Type | Rule |
|---|---|---|
id | string | ^[a-z][a-z0-9_]{1,31}$. Unique. Used in URLs and storage. |
name | string | 1 to 60 characters. |
version | string | x.y.z. Installing a higher version upgrades. A lower one is refused. |
bitstream | string | Supported Bitstream versions: >=1.0.0 <2.0.0, ^1.0.0, ~1.2.0 or *. |
author, description, license | string | Shown on the review screen. Description up to 500 characters. |
permissions | string[] | Admin API scopes the module may use, plus client_routes. |
backend.exec | object | "linux/amd64": "backend/linux-amd64/hello". Keys are Go GOOS/GOARCH. |
ui.entry | string | Path of the ES module in the zip. |
hooks.filters | object[] | {name, fail_closed, timeout_ms}. See Filters. |
hooks.events | string[] | Event types to receive. See Events. |
jobs | object[] | {name, cron} with a 5 field cron. See Jobs. |
settings | object | JSON Schema of the settings form. See Settings. |
i18n | object | Frontend strings per locale: en (required), pt-BR, es. |
data_version | integer | Version of the module's stored data. Default 0. |
files | object | path: sha256 hex of every other file. |
Permissions
| Permission | Lets 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_routes | Answer 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 control | Deadline |
|---|---|
init | 10 s |
filter | timeout_ms, default 200 ms, at most 2000 |
event | 5 s |
http | 10 s |
job | 60 s |
| From module | Does |
|---|---|
api | Admin API call as the module's key. Path relative to /api/v1. |
kv.get, kv.set, kv.delete, kv.list | The 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.
| Hook | Runs on | Data | Return |
|---|---|---|---|
playlist | get.php | line, type, entries[] (kind, id, name, tvg_id, logo, group, url) | {"data": {...}} with the entries to write |
player_api | player_api.php | line, action (login or the get_* action), body | {"data": {...}} with the new body |
play.authorize | stream URLs, before a connection slot is taken | line, 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": truethe request fails instead, andplay.authorizedenies. 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.
| Type | When | Data |
|---|---|---|
line.created | A line was created | line_id, username, owner_id, package_id, exp_date, max_connections |
stream.failed | A node reports a stream in error | stream_id, node_id, state, reason, error |
stream.failover | A stream moved to a backup source | stream_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
| URL | Who can call | Sent to the module as |
|---|---|---|
/api/v1/modules/<id>/api/<path> | signed in admins and API keys with modules:read | http with user set, client: false |
/m/<id>/<path> (client port) | anyone, if the module has client_routes | http 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)
| Limit | Value |
|---|---|
| Key | up to 200 characters |
| Value | any JSON, up to 64 KiB |
| Keys per module | 10 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.uicomponents. - A frontend module runs with the signed in admin's power. The scoped
sdk.apiis a guardrail, not a security boundary.
js
window.bitstream.register('hello', (sdk) => {
sdk.page({ id: 'index', label: 'nav', component: HelloPage })
})The sdk object:
| Member | What |
|---|---|
id, sdkVersion | Module id, SDK version (1). |
vue | The panel's Vue. |
settings | Current 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. |
ui | A few panel components (Button, Input). |
Slots. Labels and titles are keys of your i18n strings, or plain text:
| Call | Shows |
|---|---|
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 keygenprints 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.keywritessignature. It coversmodule.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=1and 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.