WEB接入 数字人
WEB以iframe方式加载数字人
<iframe src="链接地址从后台获取" frameborder="0" allow="autoplay" id="iframeDom"></iframe>
WEB调用iframe页面的方法
var iframeDom = document.getElementById('iframeDom')
iframeDom.contentWindow.postMessage({ type: 'ChangeCharacter', data: roleName }, '*')
iframeDom.contentWindow.postMessage({ type: 'AudioBroadcast', data: audioUrl] }, '*')
iframeDom.contentWindow.postMessage({ type: 'TextBroadcast', data: boardcastText }, '*')
iframeDom.contentWindow.postMessage({ type: 'TextAnswerMotion', data: qaText }, '*')
iframeDom.contentWindow.postMessage({ type: 'AudioAnswerMotion', data: base64 }, '*')
iframeDom.contentWindow.postMessage({ type: 'BroadcastStop', data: null }, '*')
WEB监听iframe页面的方法
window.addEventListener('message', function(){
if (e.data.type == 'loading') {
console.log(Math.ceil(e.data.data * 100))
}
if (e.data.type == 'loadAb') {
interactiveLoading.value = e.data.data
}
if (e.data.type == 'playStart'){
console.log(e.data.text)
console.log(e.data.answer)
}
if (e.data.type == 'playEnd'){
}
}, false)