SDK接入

具体参考

1、快速启动

import { Launcher } from 'live-cat'
const appKey = 'xxxxxxxxxxxxxxxxxxx' 
const address = 'https://app.3dcat.live'

const bootstrap = async () => {
  try {
    const launch = new Launcher({
      address,
      appKey,
      onPlay: () => {
        //when RTCDataChannel readyState is open
        //发送消息到应用程序
        //window.connection
        // .emitUIInteraction('test')
        // .then(res => console.log(res))
      }
    })
    const player = document.querySelector('body')
    document.querySelector('body').style.width = '100vw'
    document.querySelector('body').style.height = '100vh'
    await launch.automata(player)
    const connection = launch.getConnection()
    window.launch = launch
    window.connection = connection

    //监听连接状态
    //connection.event.close.on(() => console.log('断开连接'))

  } catch (error) {
    console.error(error)
  }
}

window.addEventListener('DOMContentLoaded', () => {
  if (
    navigator.userAgent.includes('miniProgram') ||
    navigator.userAgent.includes('MicroMessenger')
  ) {
    //微信浏览器/微信小程序环境
    document.addEventListener('WeixinJSBridgeReady', bootstrap, false)
  } else {
    bootstrap()
  }
})

1.1、Launcher

1.1.1 Constructors

属性说明类型
address连接地址string
appKey应用appKeystring
onPlay开始播放回调() => void

1.1.2 Methods

方法名说明参数回调参数
getConnection获取连接实例-连接实例(Connection)
getPlayer获取播放实例-播放实例(LivePlayer)

1.2、Connection

1.2.1 Attributes

属性名说明类型默认值
bitrate获取实时码率number0
dc获取RTCDataChannel实例RTCDataChannel-
eventConnection事件(参考1.2.3Events)object-
fps获取实时帧率number0
packetLossRate获取实时丢包率number0
pc获取RTCPeerConnection实例RTCPeerConnection-

1.2.2 Methods

方法名说明参数回调参数
emitUIInteraction发送消息到应用程序stringPromise<boolean>
getRTT获取实时RTT-Promise<number>
destory关闭所有实时连接-void

1.2.3 Events

事件名说明回调参数
close连接中断回调CloseEvent
disconnect信令断开回调string
interaction接收应用端返回数据unknown
业务咨询:400-8037-298