Events
Every event the video editor emits.
Every callback the video editor calls, and the DOM event that goes with it. The custom element sends each DOM event from the element itself. Each DOM event bubbles and crosses a shadow DOM boundary. Its detail holds the callback's argument, or an array of the arguments when there are several.
For how to use them, see Events.
Callbacks
| Callback | Arguments | DOM event | When |
|---|---|---|---|
onClose | none | close | The user closes the editor, and after Save & Exit. |
onExport | file, extras | export | The exported video file is ready. |
onExportProgress | event | exportprogress | A Save & Exit export makes progress after the editor has closed, or an export is refused. |
onThumbnails | delivery | none | The thumbnails of an export are ready. |
onSaveTemplate | { template } | templatesave, after the save | The user saves a design or a draft. The editor waits for the returned Promise. |
onGetTemplates | none | none | The Templates panel opens. Return the designs. |
onUploadAsset | file, ctx | none | A media file must be stored. Return { url }. |
resolveAssetUrl | storedUrl, ctx | none | A stored reference must be loaded. Return an address. |
onCustomAction | event: CustomActionEvent | A custom action starts or ends. | |
onBrandChange | brandId | customaction | CustomActionEvent |
brandchange | The editor opens with a brand kit, and the user switches the kit. The detail is the id. See Brand kits. | ||
onPreferenceChange | key, value, all | preferencechange | The user changes a preference. |
onLicenseState | report | none | The state of the license check changes. |
onChatEvent | event | chatevent | Something happens in an AI assistant conversation. |
onGetChatSession | sessionId | none | The editor opens a conversation. Return it, or null. |
onSaveChatSession | session | none | A conversation changes. Store it. |
A callback that returns a value to the editor has no DOM event, because an event listener cannot return a value. Pass it as a prop.
The custom element sends one export event for each export. Its event.detail is the exported File. The extras object is not in the event: read it from the second argument of onExport.
Export extras
The second argument of onExport. Every field is optional, and the whole object can be missing.
| Field | Type | Description |
|---|---|---|
email | { to, name } | The address and name the user entered to share the video by email. |
chat | { sessionId, lastTurnId } | The conversation the video came from. lastTurnId is the last turn the editor's own chat panel ran, or null. |
srt | { text, file } | The captions of the video as an SRT file: the text, and a File of type application/x-subrip named after the video. Present only when the video has captions. |
Export progress
The argument of onExportProgress, and the detail of exportprogress.
| Field | Type | Description |
|---|---|---|
jobId | string | The same on every event of one export. |
jobType | 'video' | 'thumbnails' | Which job the event belongs to. |
percent | number | 0 to 100. It never goes backwards within one job. |
stage | 'video' | 'audio' | 'mux' | What the export is doing: video up to 98 percent, audio at 99, and mux, which joins the picture and the sound, at 99.5. Missing on the last event. |
done | boolean | true on the last event of the job. |
error | string | On the last event only, when no file could be made. |
Thumbnails
The argument of onThumbnails. It arrives after onExport, even when no thumbnail could be made.
| Field | Type | Description |
|---|---|---|
jobId | string | The export these thumbnails belong to. |
thumbnails | array | At most two: the still picture first, then the short clip. |
thumbnails[].type | 'still' | 'clip' | A picture or a short silent video. |
thumbnails[].file | File | The file. |
thumbnails[].mimeType, width, height | string, number, number | The file's type and size. |
thumbnails[].pieces | array | For a clip: the moments it holds, in the order they play, with startSec and endSec. |
notes | array | One entry per moment that produced nothing. Always present, often empty. |
notes[].reason | string | A sentence you can show a person. |
notes[].reasonCode | string | The same reason as a short code. |
Template save
The detail of templatesave. It is sent once for each save, when the save ends.
| Field | Type | Description |
|---|---|---|
template | object | The design that was offered to onSaveTemplate. |
saved | boolean | true only when the Promise from onSaveTemplate resolved. A save that takes too long reports false. |
License state
The argument of onLicenseState. Every field is safe to log. It does not contain the license key.
| Field | Type | Description |
|---|---|---|
state.status | 'checking' | 'pending-online' | 'running' | 'blocked' | The state of the check. pending-online is no longer produced, and stays in the type for compatibility. |
state.expiringAt | number | With running: the key expires within 30 days, at this time in milliseconds. |
state.insecureContext | boolean | With running: the page is not served over HTTPS. |
state.reason, state.message | string | With blocked: the code and the sentence. See Error codes. |
keyHashPrefix | string | The first 8 characters of the key's SHA-256 hash. |
kid | string | The name of the signing key that made the license. |
sdkVersion | string | The version of the editor. |
hostname | string | The page's host name. |
insecureContext | boolean | true when the page is not served over HTTPS, away from localhost. |
at | number | When the report was made, in milliseconds. |
stopIat | number | Only for a block the license server signed. |
reference | string | All of the above on one line, for a support request. |
Chat events
The argument of onChatEvent, and the detail of chatevent. Every event has type and sessionId. Every event except ready has turnId, which is the same for everything that happens after one message from the user.
type | Other fields | When |
|---|---|---|
ready | api | The editor can be edited through api. Once per mount, and again when chatSessionId changes. |
message | message, messages | The conversation changed. messages is the whole conversation to store. |
toolCall | toolName, args | An action is about to run. |
receipt | toolName, result | An action finished. result can be large. |
done | messages, error, errorCode, topUpUrl | The turn is over. It comes once per turn, last. error is 'stopped' when the user stopped the turn, or the sentence of the error when the turn failed. errorCode is the AI error code of a refused turn, and topUpUrl is the top-up address when the server sent one. |
Preference change
onPreferenceChange receives three arguments: the name of the preference, its new value, and all preferences. The detail of preferencechange is an array of those three.
AI generation
Pass generation observers inside ai, rather than as editor event props.
import type { EditorAIConfig } from '@layermetry/media-editor';
export const ai: EditorAIConfig = {
endpointUrl: '/api/ai', image: true,
onGenerationError: (error, context) => {
console.warn(error.code, error.providerError?.requestId, context.attemptId);
},
onGenerationEvent: (event) => {
if (event.type === 'progress') console.info(event.percent, event.stage);
},
};| Hook | Arguments | Contract |
|---|---|---|
onGenerationError | SDK error, AIGenerationErrorContext | Observes each failed attempt once. |
onGenerationEvent | AIGenerationEvent | Observes start, progress and one terminal event. |
Hooks observe only. Returning a value does not recover a generation. Throwing does not change its outcome.
Error context
The error context identifies the attempt without copying request content.
| Field | Type | Description |
|---|---|---|
operation | AIInputOperation | The requested operation. |
attemptId | string | The identifier for one logical attempt. |
catalogId, modelId, revision | Optional string | The submitted model identity and schema revision. |
phase | configure, validate, submit, poll, download, read or apply | The stage reported for the failure. |
outcome | not-accepted, accepted or unknown | Whether work acceptance is known. |
requestId | Optional string | The server request identifier. |
fieldPath | Optional string | The outgoing field key that caused refusal. |
The context contains no prompt, source, body, header values or license key. The accompanying error can contain providerError; see Provider errors.
Lifecycle events
Every event contains type, attemptId and operation.
| Type | Other fields | When |
|---|---|---|
start | Optional catalogId, modelId, revision | A logical attempt starts. |
progress | percent, stage | A long-running job reports progress. |
success | Optional catalogId, modelId, requestId | Generation returns a usable result. |
failure | code, phase, optional requestId | Generation fails. |
cancel | phase | Generation is cancelled. |
One attempt emits one start and one terminal success, failure or cancel. A success event confirms generation, not a later user choice to place a candidate.
Generated file receipt
The context of onUploadAsset includes producedBy for generated media.
| Field | Type | Description |
|---|---|---|
capability | string | The operation that created the file. |
catalogId | Optional string | Your model entry’s id on the models route. |
modelId | Optional string | The reported model name, or the requested model when no name was reported. |
providerId | Optional string | The classic provider object’s identifier. |
An omitted identity field stays absent. These fields record identity; they do not prove that a provider applied each requested setting.
CustomActionEvent
| Field | Type | Description |
|---|---|---|
actionId | string | The action id. |
status | started, done, failed, aborted | The run state. |
error | Optional string | The message for a failed run. |
durationMs | Optional number | The elapsed time on every final event. |