English
Appearance
English
Appearance
This page describes the advanced runtime API available on collection pages.
iframe.addEventListener('ready', (event) => {
const api = event.detail.api;
const collectionInfo = event.detail.collectionInfo;
});At this point, event.detail.api is a CollectionApi, used to control the overall collection flow.
iframe.addEventListener('sceneReady', (event) => {
const api = event.detail.api;
const sceneInfo = event.detail.sceneInfo;
});Here, event.detail.api is a SceneApi, which is the same advanced API you get when opening a scene directly.
This API is currently intended for collection pages.
It is responsible for:
Basic AR/Gyroscope collectionsIt is not responsible for directly manipulating objects, models, video, lights, or other scene content.
If you need to control the runtime content of a concrete scene inside the collection, wait for sceneReady and then use the SceneApi it provides.
await api.openScene('7A43keFojH0v98xvFP2w52aF8Y67Zbb5');
await api.closeCurrentScene();Even if some methods only trigger a flow change internally, it is still best to await them consistently.
api Type Differs Between ready and sceneReady ready.detail.api: CollectionApisceneReady.detail.api: SceneApiThe most common pattern is:
CollectionApi in readySceneApi in sceneReadyCollectionApi for scene switching, scan state, and cloud-recognition control in Basic AR/Gyroscope collectionsSceneApi for manipulating objects inside the current sceneCapabilities like the following do not belong to CollectionApi:
Those all belong to SceneApi, which you should obtain from sceneReady.
interface CollectionApi {
getStartButtonRect(): Promise<DOMRect | undefined>;
setStartButtonRect(rect: Partial<CSSStyleDeclaration>): Promise<void>;
backToScan(): Promise<void>;
openScene(sceneId: string): Promise<void>;
closeCurrentScene(): Promise<void>;
startCloudar(
collectionId?: string,
sceneList?: string[],
): Promise<string>;
stopCloudar(): Promise<void>;
takePhoto(): Promise<string>;
}getStartButtonRect(): Promise<DOMRect | undefined>
setStartButtonRect(rect: Partial<CSSStyleDeclaration>): Promise<void>Used to read or adjust the style and layout of the collection landing page's Start Now Button.
backToScan(): Promise<void>
openScene(sceneId: string): Promise<void>
closeCurrentScene(): Promise<void>openScene(sceneId) Open a concrete scene inside the collection.
await api.openScene('7A43keFojH0v98xvFP2w52aF8Y67Zbb5');sceneId: the scene ID to open. It should usually come from collectionInfo.sceneList.sceneStart before switching away.sceneReady, download, load, and sceneStart events.closeCurrentScene() Close the currently opened scene inside the collection.
await api.closeCurrentScene();sceneDestroy event.backToScan() Return from the current scene back to the scanning state.
await api.backToScan();Basic AR/Gyroscope collections.Basic AR/Gyroscope collections.startCloudar(collectionId?: string, sceneList?: string[]): Promise<string>
stopCloudar(): Promise<void>startCloudar(collectionId?, sceneList?) Start the cloud-recognition scanning flow.
const sceneId = await api.startCloudar(
collectionInfo.collectionId,
collectionInfo.sceneList,
);collectionId: optional. Defaults to the currently opened collection ID.sceneList: optional. Recognition only returns results from the given scene list. Otherwise recognition continues scanning. By default it uses all scenes in the current collection whose type matches the collection type.Promise<string>Returns the recognized scene ID.
Basic AR/Gyroscope collections.sceneList, recognition results will be limited to those scenes.stopCloudar() Stop the current cloud-recognition scanning flow.
await api.stopCloudar();Basic AR/Gyroscope collections.takePhoto(): Promise<string>Take a photo of the currently opened scene inside the collection.
const photo = await api.takePhoto();
previewImg.src = photo;Promise<string>Returns an image URL in data:image/png;base64,... format.
SceneApi.takePhoto(): the result is usually a composite of the currently visible content.On collection pages, two API types exist at the same time, but their responsibilities differ:
CollectionApi Best for:
SceneApi Best for:
So a typical organization looks like:
let collectionApi = null;
let sceneApi = null;
iframe.addEventListener('ready', (event) => {
collectionApi = event.detail.api;
});
iframe.addEventListener('sceneReady', (event) => {
sceneApi = event.detail.api;
});