有奖捉虫:办公协同&微信生态&物联网文档专题 HOT

TUICallKit API 简介

TUICallKit API 是音视频通话组件的含 UI 接口,使用TUICallKit API,您可以通过简单接口快速实现一个类微信的音视频通话场景,更详细的接入步骤,详情请参见 快速接入 TUICallKit

API 概览

API
描述
login
登录。
logout
登出。
设置用户的昵称、头像。
call
发起 1v1 通话。
groupCall
发起群组通话。
主动加入当前的群组通话中。
设置自定义来电铃音。
开启/关闭静音模式。
开启/关闭悬浮窗功能。

API 详情

login

登录
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
const options = {
SDKAppID: 0,
userID: 'mike',
userSig: '',
};
TUICallKit.login(options, (res) => {
if (res.code === 0) {
console.log('login success');
} else {
console.log(`login failed, error message = ${res.msg}`);
}
});
参数
类型
含义
options
Object
初始化参数。
options.SDKAppID
Number
用户 SDKAppID。
options.userID
String
用户 ID。
options.userSig
String
用户签名 userSig。
callback
Function
回调函数,code = 0 表示调用成功;code != 0 表示调用失败,失败原因见 msg。

logout

登出
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
TUICallKit.logout((res) => {
if (res.code === 0) {
console.log('logout success');
} else {
console.log(`logout failed, error message = ${res.msg}`);
}
});
参数
类型
含义
callback
Function
回调函数,code = 0 表示调用成功;code != 0 表示调用失败,失败原因见 msg。

setSelfInfo

设置用户昵称、头像。用户昵称不能超过500字节,用户头像必须是URL格式。
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
const options = {
nickName: 'jack',
avatar: 'https:/****/user_avatar.png'
}
TUICallKit.setSelfInfo(options, (res) => {
if (res.code === 0) {
console.log('setSelfInfo success');
} else {
console.log(`setSelfInfo failed, error message = ${res.msg}`);
}
});
参数
类型
含义
options
Object
初始化参数。
options.nickName
String
目标用户的昵称,非必填。
options.avatar
String
目标用户的头像,非必填。
callback
Function
回调函数,code = 0 表示调用成功;code != 0 表示调用失败,失败原因见 msg。
注意:
通话中使用 setSelfInfo 接口修改用户信息,UI 不会立即更新,需要等到下次通话才能看到变化。

call

拨打电话(1v1通话)
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
const options = {
userID: 'mike',
callMediaType: 1, // 语音通话(callMediaType = 1)、视频通话(callMediaType = 2)
};
TUICallKit.call(options, (res) => {
if (res.code === 0) {
console.log('call success');
} else {
console.log(`call failed, error message = ${res.msg}`);
}
});
参数如下表所示:
参数
类型
含义
options
Object
初始化参数。
options.userID
String
目标用户的 userID。
options.callMediaType
Number
通话的媒体类型,例如:语音通话(callMediaType = 1)、视频通话(callMediaType = 2)。
callback
Function
回调函数,code = 0 表示调用成功;code != 0 表示调用失败,失败原因见 msg。

groupCall

发起群组通话,注意:使用群组通话前需要创建IM 群组,如果已经创建,请忽略。
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
const options = {
groupID: 'myGroup',
userIDList: ['mike', 'tom'],
callMediaType: 1, // 语音通话(callMediaType = 1)、视频通话(callMediaType = 2)
};
TUICallKit.groupCall(options, (res) => {
if (res.code === 0) {
console.log('call success');
} else {
console.log(`call failed, error message = ${res.msg}`);
}
});
参数
类型
含义
options
Object
初始化参数。
options.groupID
String
此次群组通话的群 ID。
options.userIDList
List
目标用户的userId 列表。
options.callMediaType
Number
通话的媒体类型,例如:语音通话(callMediaType = 1)、视频通话(callMediaType = 2)。
callback
Function
回调函数,code = 0 表示调用成功;code != 0 表示调用失败,失败原因见 msg。

joinInGroupCall

加入群组中已有的音视频通话。
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
const options = {
roomID: 9898,
groupID: 'myGroup',
callMediaType: 1, // 语音通话(callMediaType = 1)、视频通话(callMediaType = 2)
};
TUICallKit.joinInGroupCall(options, (res) => {
if (res.code === 0) {
console.log('joinInGroupCall success');
} else {
console.log(`joinInGroupCall failed, error message = ${res.msg}`);
}
});
参数
类型
含义
options
Object
初始化参数。
options.roomID
Number
此次通话的音视频房间 ID,目前仅支持数字房间号,后续版本会支持字符串房间号。
options.groupID
String
此次群组通话的群 ID。
options.callMediaType
Number
通话的媒体类型,例如:语音通话(callMediaType = 1)、视频通话(callMediaType = 2)。
callback
Function
回调函数,code = 0 表示调用成功;code != 0 表示调用失败,失败原因见 msg。

setCallingBell

设置自定义来电铃音,这里仅限传入本地文件地址需要确保该文件目录是应用可以访问的
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');

// 【1】通过 uni.saveFile 保存音频文件到本地,具体参考 saveFile 接口: https://zh.uniapp.dcloud.io/api/file/file.html#savefile
const tempFilePath = './static/rain.mp3'; // 本地存放的音频文件
let musicFilePath = '';
uni.saveFile({
tempFilePath: tempFilePath,
success: (res) => {
console.warn('保存文件成功 = ', JSON.stringify(res)); // 获取的是相对路径
musicFilePath = res.savedFilePath;
// 【2】相对路径转绝对路径,否则访问不到
musicFilePath = plus.io.convertLocalFileSystemURL(musicFilePath); // 转绝对路径
// 【3】设置铃声
TUICallKit.setCallingBell(musicFilePath, (res) => {
if (res.code === 0) {
console.log('setCallingBell success');
} else {
console.log(`setCallingBell failed, error message = ${res.msg}`);
}
});
},
fail: (err) => {
console.error('保存文件失败');
},
});
参数
类型
含义
filePath
String
来电铃音本地文件地址。
callback
Function
回调函数,code = 0 表示调用成功;code != 0 表示调用失败,失败原因见 msg。

enableMuteMode

开启/关闭静音模式。
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
const enable = true;
TUICallKit.enableMuteMode(enable);
参数
类型
含义
enable
Boolean
开启、关闭静音;true 表示开启静音。

enableFloatWindow

开启/关闭悬浮窗功能,设置为false后,通话界面左上角的悬浮窗按钮会隐藏。
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
const enable = true;
TUICallKit.enableFloatWindow(enable);
参数
类型
含义
enable
Boolean
开启、关闭悬浮窗功能;true 表示开启浮窗。