微信小程序 SDK
更新时间:2025-05-14
获取SDK实例
const brtc_agent = require('./agent.js');
var mAgent = brtc_agent.Agent;
实例的各API函数说明如下:
开始通话
Plain Text
1mAgent.Start()
介绍
开始通话时使用。
参数
参数 | 类型 | 描述 |
---|---|---|
server | string | 百度的RTC 服务器, 使用默认值即可 |
appid | string | 百度 派发的数字 ID, 开发者的唯一标识 |
该接口参数数量较多,请参考下面的参数详解进行了解。
返回
无
参数详解
Plain Text
1// 启动Agent例子代码
2var cfg = {
3 llm: 'LLMxxx',
4 llm_url: ''
5};
6mAgent.Start({
7 appid: 'AppIdxxx',
8 cfg: cfg,
9 success: function (pushurl, agentId) {
10 },
11 error: function (error) {
12 },
13 onmessage: function (msg) {
14 console.log('onmessage id: ' + msg.id + ' data: ' + msg.data);
15 },
16 remotevideocoming: function (id, display, attribute, pullurl) {
17 },
18});
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
appid | string | 百度 派发的数字 ID, 开发者的唯一标识 | |
cfg | json | 智能体配置 | cfg配置LLM,TTS等,互动数字人的配置见“互动数字人”一节 |
remotevideocoming | function(id,display,attribute, pullurl) | 远端用户流上线的回调 | pullurl 是拉流的RTMP地址, 可以用liveplayer进行播放 |
remotevideoleaving | function(id) | 远端用户流离开的回调 | |
onmessage | function(msg) | 消息事件回调{msg.id,msg.data} | |
userevent_joinedroom | function(id,display,attribute) | 用户加入房间的事件,此时用户还没有发布流 | |
userevent_leavingroom | function(id,display) | 用户离开房间 | |
success | function(pushurl,agentid) | Start()成功 | pushurl是服务器分配的用于推流的RTMP地址, 可以用livepusher进行推流 |
error | function(error) | Start()失败,或运行过程中出现了错误 | |
destroyed | function(error) | 运行过程中出现错误被销毁的回调 | |
debuglevel | bool/array | 是否打印调试信息 | 默认值为false, 可取值为: true, false, 'all', ['debug','log','error'] |
结束通话
Plain Text
1mAgent.Stop();
介绍
结束通话
参数
无
返回
无
发送文本消息
Plain Text
1mAgent.sendMessageToUser
介绍
本函数用来发送广播消息。 发送用户消息的频率应小于100次/秒,超出的话用户消息可能会被丢弃。
参数
msg, 需要发送的消息内容, 为一个字符串, 比如: '[T]:你好'
返回
无
接收消息回调
onmessage: function (msg) { }
介绍
本函数用来接收消息。发送用户消息的频率应小于100次/秒,超出的话用户消息可能会被丢弃。
参数
msg, 消息值 消息的消息见“客户端和服务端消息” 一节。
返回
无