PanoRtc 参考
Installing
有两种方式引用PanoRtc
:
npm install @pano.video/panortc
到Pano下载中心下载SDK打包文件,解压后把js文件引入到网页中,
PanoRtc
会自动挂载到window
对象上,可以通过window.PanoRtc
访问
注意:通过html文件直接引用SDK文件时,需要把引用的
<script>
标签添加到<body>
中,不可以添加到<head>
中
RtcEngine 连接步骤
连接步骤可以参考 音频基础版sample,或 视频基础版sample
连接步骤:
- 新建
PanoRtc
实例:const panoRtc = new PanoRtc.RtcEngine(appid)
- 获取 PanoToken
- 调用
panoRtc.joinChannel
, 使用上一步获取的panoToken
和会议channelId
等参数加入会议,可以设置 joinChannelType 类型控制只加入音视频频道、白板频道或者二者都加入 - 监听到
joinChannelConfirm
事件后即可开始通信
示例代码:
import PanoRtc from '@pano.video/panortc'
const rtcEngine = new PanoRtc.RtcEngine('your_app_id')
rtcEngine.on(PanoRtc.RtcEngine.Events.joinChannelConfirm, data => console.log(`join channel ${data.result}`))
rtcEngine.joinChannel({
token: 'xxxx', // fill with you panoToken
channelId: 'xxxx', // channel id
channelMode: PanoRtc.Constants.ChannelMode.TYPE_MEETING, // meeting or 1_v_1
userId: 'xxxx',
userName: 'xxxx'
}, {
joinChannelType: PanoRtc.Constants.JoinChannelType.mediaAndWhiteboard // 可选参数,默认加入音视频和白板channel
})
RtcWhiteboard
在加入channel 后,可以通过 panoRtc.getWhiteboard
获取白板控制接口,可以打开和关闭白板。
示例代码:
const whiteboard = rtcEngine.getWhiteboard()
const whiteboardWrapper = document.getElementById('#eleId')
whiteboard.open(whiteboardWrapper) // 打开白板
// whiteboard.close() //关闭白板