@vestra-player/sdk - v1.11.3
    Preparing search index...

    Tutorial

    A plugin for Vestra Player is a separate Node.js process that talks to the player over one connection. It is a folder with a manifest.json (who the plugin is), TypeScript modules that the player runs, and optional Slint files for its windows, panels and settings pages.

    In this tutorial you write one: a menu item Tools ▸ Where am I? (also on Ctrl+Alt+W) that shows the playback position on the screen. Then you see the three styles a plugin can be written in, and how to test and publish it.

    You need Node.js 26 or newer, a terminal, an editor, and Vestra Player with a video to play.

    Create the folder and install the SDK:

    mkdir my-plugin && cd my-plugin
    npm init -y
    npm pkg set type=module
    npm i -D @vestra-player/sdk

    The package brings its own TypeScript and the vestra-plugin command line tool. A finished plugin folder looks like this:

    my-plugin/
      manifest.json        identity
      main.ts              the entry module
      ui/*.slint           windows, panels and settings pages
      locales/*.po         translations
      tests/*.test.ts      tests (node:test)
      package.json         dev dependency and scripts
    

    Add the scripts to package.json:

    {
    "type": "module",
    "scripts": {
    "check": "vestra-plugin check",
    "test": "vestra-plugin test",
    "build": "vestra-plugin build",
    "pack": "vestra-plugin pack"
    },
    "devDependencies": { "@vestra-player/sdk": "^1.11.0" }
    }

    Add a tsconfig.json for your editor:

    {
    "compilerOptions": {
    "target": "ES2023",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "noEmit": true,
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "erasableSyntaxOnly": true,
    "skipLibCheck": true,
    "types": ["node"]
    },
    "include": ["*.ts", "tests/*.ts"]
    }

    In VS Code, open a .ts file, run TypeScript: Select TypeScript Version and pick Use Workspace Version. For the Slint files of windows and panels, the @vestra/… imports come from the player; point the Slint language server's libraryPaths at the SDK's copy: { "vestra": "node_modules/@vestra-player/sdk/slint/vestra" }.

    Create manifest.json. Replace me with your GitHub user name:

    {
    "id": "me.hello",
    "version": "0.1.0",
    "apiVersion": "vestra/1",
    "entry": "main.ts"
    }

    Every field is in Manifest. The manifest says who the plugin is, not what it may do.

    Create main.ts:

    // main.ts
    import type { Plugin } from "@vestra-player/sdk";

    export default function activate(plugin: Plugin) {
    plugin.commands.add({
    id: "where",
    path: ["Tools", "Where am I?"],
    bindings: ["Ctrl+Alt+W"],
    enabled: plugin.when.ready, // the player evaluates it
    run: async () => {
    const { position, duration } = await plugin.player.refresh(); // now
    return plugin.osd.show("{} s of {} s", [
    (position ?? 0).toFixed(1),
    (duration ?? 0).toFixed(1),
    ]);
    },
    });
    }
    • The player calls the default export, activate, when it starts the plugin.
    • path is the menu path in English; the player translates it. To put the item into one of the player's own menus, start the path with that menu's id, such as ["@video", "Where am I?"] (Built-in menus).
    • enabled greys the item out while nothing plays. plugin.when.ready is a condition the player evaluates itself, so the plugin need not run to keep the item current and the player can stop it while idle (Keep a command's state without keeping the plugin running). run reads the state at the moment it runs (refresh() asks the player) and shows the message, a template with its arguments. Nothing follows the state in between, so the plugin holds nothing while it is idle: Learn what happens in the player without staying up shows the other ways to learn it.
    • Do not await a click on your own command or a callback of your own window inside activate: the player holds them until activation is done, so activate would wait until the start timeout (60 s) and the plugin would stop with failed.
    • The SDK is imported with import type only; a runtime import fails vestra-plugin build.

    Check it:

    npm run check
    

    Start the player with your folder; no build is needed (repeat --plugin to load several plugins):

    vestra-player --plugin ./my-plugin
    

    Open a video, then choose Tools ▸ Where am I? in the right-click menu, or press Ctrl+Alt+W. The position appears at the top left of the video. After a change to main.ts, reload the plugin from the plugin manager, or start the player again.

    The menu item above lets the player keep its state (plugin.when) and reads the playback state when it runs. For a value that is shown and changes, the SDK can decide when to tell the player. That is one of three styles. Here is the same job in each: a Speed tab in the adjust column (the column of controls for what is playing, opened by the bottom bar's Adjustments and Effects button) shows the playback speed, and S cycles it. The code comes from the example plugin examples/three-ways, where speedText and nextRate are two small helpers in shared.ts. Each style declares its listeners first and then reads the state once with await plugin.player.read(), and follows the speed, which has no event of its own, only while the tab is on screen: whileShown (in shared.ts) starts it when layout.changed says the tab shows and stops it when it goes.

    const panel = plugin.panels.mount("adjust", "ui/speed.slint", {
    title: "Speed",
    });
    // Reads state.rate: runs again when the speed changes, and only then.
    panel.bind(() => ({ rate: speedText(plugin.player.state.rate) }));
    // The speed has no event: while the tab is on screen a stream keeps
    // state.rate following the player.
    whileShown(plugin, panel, () => {
    const feed = plugin.player.stream(() => {});
    return () => feed.stop();
    });
    plugin.commands.add({
    id: "rate.cycle",
    path: ["Playback", "Cycle Speed"],
    bindings: ["S"],
    enabled: plugin.when.can("rate"), // evaluated by the player itself
    run: async () => {
    const s = await plugin.player.refresh(); // the speed now, shown or not
    await plugin.player.setRate(nextRate(s.rate));
    },
    });

    The binding is a function of state. While the stream is open the SDK runs it again when the speed changes, and only then, and sends only what changed. The command's enabled is a condition the player evaluates itself. This is the default style, and the one the guides use: choose it for anything the SDK can see, such as the player's state, a window's state or your own plugin.state.

    const panel = plugin.panels.mount("adjust", "ui/speed.slint", {
    title: "Speed",
    });
    let shown = "1.00×"; // what the panel shows: its Slint default at first
    const show = (value: number) => {
    const rate = speedText(value);
    if (rate === shown) return; // compare, or each event is a write
    shown = rate;
    panel.set({ rate });
    };
    // The speed has no event of its own: while the tab is on screen, read it
    // once, then hear every source.state event (about ten a second while
    // media plays; the payload is typed, SourceState).
    whileShown(plugin, panel, () => {
    void plugin.player.refresh().then(
    (s) => show(s.rate),
    () => {},
    );
    const listener = plugin.player.on("source.state", (s) => show(s.rate));
    return () => void listener.dispose();
    });
    plugin.commands.add({
    id: "rate.cycle",
    path: ["Playback", "Cycle Speed"],
    bindings: ["S"],
    run: async () => {
    const s = await plugin.player.refresh(); // no copy kept: ask
    await plugin.player.setRate(nextRate(s.rate));
    },
    });

    While the tab shows, the listener receives every source.state event with a typed payload (Events), and set sends the value whole each time. Nothing compares for you, so the plugin keeps shown to avoid sending the same text ten times a second. Choose it when the value comes from outside the SDK (a timer, a socket, an emulator's frame) and you know exactly when it changed.

    const panel = plugin.panels.mount("adjust", "ui/speed.slint", {
    title: "Speed",
    });
    const view = plugin.wire.view(panel); // raw writes for this panel
    let shown = "1.00×"; // what the panel shows: its Slint default at first
    const show = (data: unknown) => {
    const s = data as { rate: number }; // the plugin types the payload
    const rate = speedText(s.rate);
    if (rate === shown) return; // about ten events a second while playing
    shown = rate;
    view.write("rate", { value: rate }).catch(() => (shown = "")); // again next time
    };
    // While the tab is on screen: one read of the source now, then every
    // source.state event.
    whileShown(plugin, panel, () => {
    plugin.wire.request("source.state").then(show, dropped);
    const listener = plugin.wire.on("source.state", show);
    return () => void listener.dispose();
    });
    plugin.wire.commands.register({
    id: "rate.cycle",
    declaration: declaration(["Playback", "Cycle Speed"], ["S"]),
    run: async () => {
    // The SDK's control acts on the state the SDK last read: read it now.
    const s = await plugin.player.refresh();
    await plugin.player.setRate(nextRate(s.rate)); // or source.submit
    },
    });

    Events, requests and property writes by the player's own names (Messages), untyped and without the SDK's value checks. This layer changes with player versions. Choose it only to try a player method the SDK does not wrap yet, or to send list row operations you already have.

    The styles mix freely in one plugin, with one rule: a property is either bound or set (A, B) or written directly (C), never both; the SDK refuses the second with invalid.

    Create tests/main.test.ts. startPlugin runs the plugin against an in-memory player that reads your manifest.json:

    // tests/main.test.ts
    import assert from "node:assert/strict";
    import test from "node:test";
    import { startPlugin } from "@vestra-player/sdk/testing";
    import activate from "../main.ts";

    test("shows the position", async () => {
    const { host, stop } = await startPlugin(activate, {
    directory: new URL("..", import.meta.url), // reads manifest.json
    });
    host.setSource({ phase: "ready", position: 12, duration: 60 });
    await host.settle();
    await host.command("where").run(); // as if the user chose the item
    assert.deepEqual(host.osd, ["12.0 s of 60.0 s"]);
    await stop();
    });

    Then run the tests and the checks, and pack:

    npm test                     # tests/*.test.ts against an in-memory player
    npm run check # the manifest, then a strict type check
    npm run pack # dist/, then me.hello-0.1.0.vxp
    • The tests need no player; simulating sources, failures and restarts is in Test a plugin.
    • Install the .vxp in the player to try what users will get.
    • To publish, push the plugin to a public GitHub repository and register it with a pull request to the plugin repository: Publish a plugin.