FunctioncreateLive

创建 Live 带看实例

这是一个工厂函数,用于创建 Live 实例。在创建新实例前,会先清理全局的旧实例(如果存在)。

// 定义帧数据类型
interface MyKeyframes {
camera: { position: [number, number, number] }
annotation: { text: string; position: [number, number] }
}

// 创建 Live 实例
const live = createLive<MyKeyframes>({
url: 'wss://example.com/live',
getTicket: async () => {
const response = await fetch('/api/get-ticket')
return response.json().ticket
},
getVoiceSign: async (params) => {
const response = await fetch('/api/get-voice-sign', {
method: 'POST',
body: JSON.stringify(params)
})
return response.json()
},
useBuiltInRTC: true
})

// 连接带看
await live.connect()