tencent cloud

文档反馈

TUICallKit

最后更新时间:2024-03-07 18:03:53

    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

    call

    拨打电话(1v1通话)
    const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');
    const options = {
    userID: 'mike',
    callMediaType: 1, // 语音通话(callMediaType = 1)、视频通话(callMediaType = 2)
    roomID: 0,
    strRoomID: '1223', // 使用字符串房间号
    };
    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)
    options.roomID
    Number
    自定义数字房间号。只要有 roomID,就用的是数字房间号,即使 strRoomID 存在
    options.strRoomID
    String
    自定义字符串房间号。如果想使用字符串房间号,设置 strRoomID 后需要将 roomID = 0
    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)
    options.roomID
    Number
    自定义数字房间号。只要有 roomID,就用的是数字房间号,即使 strRoomID 存在
    options.strRoomID
    String
    自定义字符串房间号。如果想使用字符串房间号,设置 strRoomID 后需要将 roomID = 0

    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('save failed');
    },
    });
    参数
    类型
    含义
    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 表示开启浮窗
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持