Editor Embedding
Embed the rooomAvatars Editor in an iframe and initialize it via URL parameters.
Are you an LLM? You can read better optimized documentation at /docs/rooom-avatars/editor.md for this page in Markdown format
Embed the rooomAvatars Editor as an iframe and pass the API token and initial settings through URL parameters.
Overview
The embedding flow is:
- Build the iframe
srcwith your API token in the URL hash and optional config in query parameters. - Load the iframe.
- Optionally send
rooom-avatars-configmessages to update settings at runtime. - Listen for
rooom-avatars-completedto receive the avatar ID and model URL.
Prerequisites
- A URL where the editor is hosted.
- An API token for the rooomAvatars REST API.
Steps
- Create an iframe whose
srcpoints to the editor URL. Pass the API token in the URL hash (#token=...) and any display flags as query parameters. - Listen for the
rooom-avatars-completedmessage to receive the result.
Examples
Create an iframe with the API token and a transparent background:
html
<iframe
id="rooom-avatars"
src="https://editor.avatars.rooom.com/?transparent#token=YOUR_API_TOKEN"
allow="camera"
title="rooomAvatars Editor"
></iframe>Pass an initial config and avatar name via query parameters:
html
<iframe
id="rooom-avatars"
src="https://editor.avatars.rooom.com/?transparent&config=%7B%22body%22%3A%7B%22gender%22%3A%22feminine%22%7D%7D&avatarName=My%20Avatar#token=YOUR_API_TOKEN"
allow="camera"
title="rooomAvatars Editor"
></iframe>Listen for rooom-avatars-completed:
js
const iframe = document.getElementById('rooom-avatars');
const iframeOrigin = new URL(iframe.src).origin;
window.addEventListener('message', (event) => {
if (event.origin !== iframeOrigin) return;
if (event.source !== iframe.contentWindow) return;
const { type, source, data } = event.data ?? {};
if (source !== 'rooom-avatars') return;
if (type === 'rooom-avatars-completed') {
console.log('avatarId:', data.avatarId);
console.log('modelUrl:', data.modelUrl);
console.log('previewUrl:', data.previewUrl);
}
});More details: