Fluxta

Editor API

Everything an editor page can do.

Editors are web pages that Fluxta mounts in a sandboxed iframe. There are two, and they share most of their surface:

  • ActionEditor — the settings form for one placed Action.
  • PluginEditor — the settings page for the plugin as a whole.
import { ActionEditor, PluginEditor } from "@fluxta/sdk/api";

Action Editor

const editor = new ActionEditor();
await editor.connect();

ActionEditor

new ActionEditor()

Throws unless it is running inside the Fluxta editor iframe. Specifically, it throws when:

  • there is no browser window,
  • the URL fragment carries no editor grant, or
  • the query string carries no id for the Action being edited.

Fluxta supplies both; neither is constructed by the plugin. The practical consequence is that an editor cannot run standalone against a dev server — build it and let Fluxta mount it.

connect

connect(): Promise<void>

Opens the connection and resolves once it is established. Reconnects after ordinary network failures; rejects on authorization, policy, and version failures, which are final.

getActionSettings

getActionSettings(): Promise<JsonValue>

The settings currently saved for this placement. Use it to fill in the form when the editor mounts.

const settings = (await editor.getActionSettings()) as Settings;

Returns {} when nothing has been saved yet, when the stored value is null, and when it cannot be parsed. A parse error never needs handling, but the result should be treated as untrusted and its shape validated.

onActionSave

onActionSave(handler: () => unknown): () => void

Registers the function Fluxta calls when the user saves. Whatever it returns is serialized to JSON and stored as this placement's settings. Returns a function that unregisters the handler.

const off = editor.onActionSave(() => ({ scene: selectedScene }));

Only one handler is live at a time

Registering a second handler replaces the first. With React state, re-register on every change — or read from a ref — or the handler keeps saving the value it closed over when it was first registered.

useEffect(() => editor.onActionSave(() => ({ scene })), [scene]);

If the handler throws, or returns something that cannot be serialized — that includes returning nothing at all — the error is logged and the save stores nothing rather than a half-serialized value. The previously stored settings are kept, and Fluxta reports the failed save in the editor dialog instead of closing it.

Template Value Sources

getTemplateSources(): TemplateSourceGroup[] returns the complete source menu available at this Action's position, including preceding Actions' results, Event Fields, Routine Parameters, Global Variables, and plugin Value Sources. Each group has a stable key, a label, items, and subgroups, plus an optional iconUrl. Subgroups have the same recursive shape: open a plugin, then its declared groups, then any producing Action or Event Source. Groups appear before direct items. Display names may repeat; identify groups by their keys. Items carry group, key, optional action, label, scalar valueType, params, and optional disabled. A disabled result cannot be selected. The list is initially empty and stays the same array until updated.

templateSourceItems(groups) returns the leaf values in display order, visiting subgroups before direct items. Use it when you need a flat list of sources.

onTemplateSourcesChange(listener): () => void subscribes to changes and returns an unsubscribe function. The listener announces future updates; read once after subscribing to obtain the current list. React's useSyncExternalStore handles this order:

const subscribe = (onChange: () => void) =>
  editor.onTemplateSourcesChange(onChange);
const getSnapshot = () => editor.getTemplateSources();

export function useTemplateSources() {
  return useSyncExternalStore(subscribe, getSnapshot);
}

Use serializeExpression to build the text to insert into an Action setting. The expression's type: "source" identifies a Value Source reference; the catalog's valueType describes the value it returns. Plugin ids and keys may contain dots. Arguments are literal strings.

import { serializeExpression } from "@fluxta/sdk/api";

const reference = serializeExpression({
  type: "source",
  group: "com.example.obs",
  key: "sourceVisible",
  args: { scene: "Live", source: "Webcam" },
});

Templates use one format: a JSON expression enclosed in {{ and }}. parseTemplate(text) returns lossless parts and diagnostics, with offsets measured in UTF-16 units. Expression parts include expression, raw, start, and end. Invalid or unfinished expressions retain their raw text and report invalid-json, invalid-expression, unsupported-expression, or unclosed-expression. They are preserved at execution. A valid source reference that has no current value resolves to an empty string.

For a custom arguments form, getTemplateSourceOptions(group, key, args) returns { value, label }[] for a parameter's declared options key. Pass all current arguments, including the values used by dependent lists. An unavailable list is empty. Keep an already selected value even if it is missing from that list. pickTemplateSourceFile(currentPath) opens a file picker and returns the selected path, or null if it was cancelled. These asynchronous methods may reject if the editor loses its connection to Fluxta.

TemplateField provides the grouped menu and arguments form without needing to call these methods yourself.

Plugin Editor

const editor = new PluginEditor();
await editor.connect();

PluginEditor is BaseEditor with nothing added. It has no Action settings, no Run Variables, and no id — it is not editing any particular placement.

PluginEditor

new PluginEditor()

Throws unless it is running inside the Fluxta settings iframe: it needs a browser window and an editor grant in the URL fragment.

Which plugin it belongs to comes from that grant, not from anything passed in, so an editor cannot reach another plugin's settings.

Mount it by declaring a top-level editor in the manifest, and use editorPlacement to choose between the settings page and its own navigation item.

Shared surface

Everything below is on both editors.

getPluginSettings

getPluginSettings(): Promise<{ event: string; payload: JsonValue }>

Fetches the plugin-wide settings — the same store the background process reads. The value is on payload.

const settings = await editor.getPluginSettings();
const config = settings.payload;

These are answered by Fluxta itself, so they work even when the background process is not running.

setPluginSettings

setPluginSettings(data: JsonValue): Promise<void>

Replaces the stored plugin settings wholesale.

await editor.setPluginSettings({ host, port });

sendToPlugin

sendToPlugin<T extends JsonValue>(data: T): Promise<void>

Sends a message to the background process, received there via onReceiveFromEditor.

await editor.sendToPlugin({ event: "testConnection" });

If the background process is not running, the message goes nowhere — no error and no queue. Design the editor to work with the plugin offline, and to ask again once it hears from it.

onReceiveFromPlugin

onReceiveFromPlugin<T>(listener): () => void

Receives what the background process sent with sendToEditor. Returns an unsubscribe function.

const off = editor.onReceiveFromPlugin<Status>((data) => setStatus(data));

onTerminal

onTerminal(listener: (error: Error) => void): () => void

Observes a final disconnect after a successful connect. Nothing is retried afterwards; show the user that the editor needs reopening.

openUrl

openUrl(url: string | URL): void

Opens a page in the user's browser. Use it for any link out of the editor: an ordinary <a target="_blank"> does not open there.

editor.openUrl("https://developers.google.com/youtube/v3/getting-started");

Only an https: address without a user name or password opens; anything else throws a TypeError. In a UI Kit editor, ExternalLink does this for you.

A typical Action Editor

import { ActionEditor } from "@fluxta/sdk/api";
import { useEffect, useState } from "react";

const editor = new ActionEditor();
await editor.connect();

export function App() {
  const [scene, setScene] = useState("");
  const [scenes, setScenes] = useState<string[]>([]);

  // 1. Fill the form from what was saved.
  useEffect(() => {
    editor.getActionSettings().then((saved) => {
      setScene((saved as { scene?: string }).scene ?? "");
    });
  }, []);

  // 2. Tell Fluxta what to store. Re-registered whenever `scene` changes.
  useEffect(() => editor.onActionSave(() => ({ scene })), [scene]);

  // 3. Take live data from the background process...
  useEffect(
    () =>
      editor.onReceiveFromPlugin<{ event: string; scenes: string[] }>(
        (data) => {
          if (data.event === "scenes") setScenes(data.scenes);
        },
      ),
    [],
  );

  // 4. ...and ask for it on mount.
  useEffect(() => {
    void editor.sendToPlugin({ event: "getScenes" });
  }, []);

  return <SceneSelect value={scene} options={scenes} onChange={setScene} />;
}

On this page