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

CallbackArgumentsDOM eventWhen
onClosenonecloseThe user closes the editor, and after Save & Exit.
onExportfile, extrasexportThe exported video file is ready.
onExportProgresseventexportprogressA Save & Exit export makes progress after the editor has closed, or an export is refused.
onThumbnailsdeliverynoneThe thumbnails of an export are ready.
onSaveTemplate{ template }templatesave, after the saveThe user saves a design or a draft. The editor waits for the returned Promise.
onGetTemplatesnonenoneThe Templates panel opens. Return the designs.
onUploadAssetfile, ctxnoneA media file must be stored. Return { url }.
resolveAssetUrlstoredUrl, ctxnoneA stored reference must be loaded. Return an address.
onCustomActionevent: CustomActionEventA custom action starts or ends.
onBrandChangebrandIdcustomactionCustomActionEvent
brandchangeThe editor opens with a brand kit, and the user switches the kit. The detail is the id. See Brand kits.
onPreferenceChangekey, value, allpreferencechangeThe user changes a preference.
onLicenseStatereportnoneThe state of the license check changes.
onChatEventeventchateventSomething happens in an AI assistant conversation.
onGetChatSessionsessionIdnoneThe editor opens a conversation. Return it, or null.
onSaveChatSessionsessionnoneA 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.

FieldTypeDescription
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.

FieldTypeDescription
jobIdstringThe same on every event of one export.
jobType'video' | 'thumbnails'Which job the event belongs to.
percentnumber0 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.
donebooleantrue on the last event of the job.
errorstringOn 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.

FieldTypeDescription
jobIdstringThe export these thumbnails belong to.
thumbnailsarrayAt most two: the still picture first, then the short clip.
thumbnails[].type'still' | 'clip'A picture or a short silent video.
thumbnails[].fileFileThe file.
thumbnails[].mimeType, width, heightstring, number, numberThe file's type and size.
thumbnails[].piecesarrayFor a clip: the moments it holds, in the order they play, with startSec and endSec.
notesarrayOne entry per moment that produced nothing. Always present, often empty.
notes[].reasonstringA sentence you can show a person.
notes[].reasonCodestringThe same reason as a short code.

Template save

The detail of templatesave. It is sent once for each save, when the save ends.

FieldTypeDescription
templateobjectThe design that was offered to onSaveTemplate.
savedbooleantrue 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.

FieldTypeDescription
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.expiringAtnumberWith running: the key expires within 30 days, at this time in milliseconds.
state.insecureContextbooleanWith running: the page is not served over HTTPS.
state.reason, state.messagestringWith blocked: the code and the sentence. See Error codes.
keyHashPrefixstringThe first 8 characters of the key's SHA-256 hash.
kidstringThe name of the signing key that made the license.
sdkVersionstringThe version of the editor.
hostnamestringThe page's host name.
insecureContextbooleantrue when the page is not served over HTTPS, away from localhost.
atnumberWhen the report was made, in milliseconds.
stopIatnumberOnly for a block the license server signed.
referencestringAll 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.

typeOther fieldsWhen
readyapiThe editor can be edited through api. Once per mount, and again when chatSessionId changes.
messagemessage, messagesThe conversation changed. messages is the whole conversation to store.
toolCalltoolName, argsAn action is about to run.
receipttoolName, resultAn action finished. result can be large.
donemessages, error, errorCode, topUpUrlThe 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);
  },
};
HookArgumentsContract
onGenerationErrorSDK error, AIGenerationErrorContextObserves each failed attempt once.
onGenerationEventAIGenerationEventObserves 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.

FieldTypeDescription
operationAIInputOperationThe requested operation.
attemptIdstringThe identifier for one logical attempt.
catalogId, modelId, revisionOptional stringThe submitted model identity and schema revision.
phaseconfigure, validate, submit, poll, download, read or applyThe stage reported for the failure.
outcomenot-accepted, accepted or unknownWhether work acceptance is known.
requestIdOptional stringThe server request identifier.
fieldPathOptional stringThe 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.

TypeOther fieldsWhen
startOptional catalogId, modelId, revisionA logical attempt starts.
progresspercent, stageA long-running job reports progress.
successOptional catalogId, modelId, requestIdGeneration returns a usable result.
failurecode, phase, optional requestIdGeneration fails.
cancelphaseGeneration 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.

FieldTypeDescription
capabilitystringThe operation that created the file.
catalogIdOptional stringYour model entry’s id on the models route.
modelIdOptional stringThe reported model name, or the requested model when no name was reported.
providerIdOptional stringThe 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

FieldTypeDescription
actionIdstringThe action id.
statusstarted, done, failed, abortedThe run state.
errorOptional stringThe message for a failed run.
durationMsOptional numberThe elapsed time on every final event.

On this page