iframe 事件
本页描述宿主页面在 iframe DOM 上可监听的事件。
监听方式
js
iframe.addEventListener('事件名', (event) => {
console.log(event.detail);
});除浏览器原生 load/error 外,插件事件都以 CustomEvent 形式派发,业务数据从 event.detail 读取。
事件总表
| 事件名 | 场景 | 合辑 | 说明 |
|---|---|---|---|
load | 支持 | 支持 | iframe 页面资源加载完成 |
error | 支持 | 支持 | 加载错误或权限失败等 |
incompatibility | 支持 | 支持 | 兼容性前置检测失败 |
ready | 支持 | 支持 | 场景或合辑基础信息就绪 |
downloadAssetStart | 支持 | 支持 | 开始下载素材 |
downloadAssetProgress | 支持 | 支持 | 素材下载进度变化 |
downloadAssetEnd | 支持 | 支持 | 素材下载完成 |
loadSceneStart | 支持 | 支持 | 开始装载场景内容 |
loadSceneEnd | 支持 | 支持 | 场景内容装载完成 |
sceneStart | 支持 | 支持 | 场景开始,用户可体验 |
tracked | 支持 | 支持 | 成功追踪目标 |
lostTrack | 支持 | 支持 | 丢失追踪目标 |
openUrl | 支持 | 支持 | 触发网页跳转 |
sceneReady | 不支持 | 支持 | 合辑内部某个场景就绪 |
sceneDestroy | 不支持 | 支持 | 合辑切场景前销毁上一场景 |
load
ts
type LoadEvent = Event表示 iframe 页面资源加载完成,不代表素材下载完毕。
error
ts
interface PluginErrorDetail {
message: string;
code?: number;
isCameraNotFound?: boolean;
isUserDeniedCamera?: boolean;
isUserDeniedGyroscope?: boolean;
}也可能直接是字符串。
如果是浏览器原生error事件触发,则是浏览器的Error事件对象。
incompatibility
ts
type IncompatibilityDetail = Record<string, any>当前载荷结构暂不完全固定,常见于:
- 当前浏览器不适合打开摄像头
- 当前模式在该客户端不可用
ready
场景
ts
interface SceneInfo {
sceneId: string;
name: string;
description: string;
thumbnailUrl: string;
type: string;
collectionId: string;
collectionName: string;
firstPage: {
backgroundImageUrl?: string;
logoUrl?: string;
buttonUrl?: string;
hideLogoAndName?: boolean;
hideLogoAndSceneName?: boolean;
};
metadata: {
htmlTitle?: string;
share?: {
title?: string;
description?: string;
picture?: string;
pictureUrl?: string;
};
};
setting: {
skipScanMarker?: boolean;
scanImage?: string;
scanText?: string;
hideScanImage?: boolean;
userMarker?: string;
};
objects: Array<{
id: number;
name: string;
type: string;
}>;
}
interface SceneReadyDetail {
sceneInfo: SceneInfo;
api: SceneApi;
}合辑
ts
interface CollectionInfo {
collectionId: string;
name: string;
description: string;
thumbnailUrl: string;
functionType: string;
firstPage: {
backgroundImageUrl?: string;
buttonUrl?: string;
hideLogoAndName?: boolean;
};
sceneList: string[];
setting: {
continue_scan?: number;
};
}
interface CollectionReadyDetail {
collectionInfo: CollectionInfo;
api: object;
}downloadAssetStart
ts
type DownloadAssetStartDetail = undefineddownloadAssetProgress
ts
type DownloadAssetProgressDetail = number取值范围 0.0 - 1.0。
downloadAssetEnd
ts
type DownloadAssetEndDetail = undefinedloadSceneStart
ts
type LoadSceneStartDetail = undefinedloadSceneEnd
ts
type LoadSceneEndDetail = undefinedsceneStart
ts
type SceneStartDetail = undefinedtracked
ts
type TrackedDetail = undefinedlostTrack
ts
type LostTrackDetail = undefinedopenUrl
ts
type OpenUrlDetail = stringdetail 为即将打开的 URL。
sceneReady
仅合辑支持。
ts
interface SceneReadyDetailInCollection {
sceneInfo: SceneInfo;
api: SceneApi;
}sceneDestroy
仅合辑支持。
ts
interface SceneDestroyDetail {
sceneId: string;
}事件时序
场景
text
load
-> ready
-> downloadAssetStart
-> downloadAssetProgress
-> downloadAssetEnd
-> loadSceneStart
-> loadSceneEnd
-> sceneStart合辑
text
load
-> ready
-> sceneReady
-> downloadAssetStart
-> downloadAssetProgress
-> downloadAssetEnd
-> loadSceneStart
-> loadSceneEnd
-> sceneStart