更新记录

1.7.2(2023-09-17)

修复部分机型ios拉流黑屏问题

1.7.1(2023-08-18)

修复im消息有时候收不到的问题

1.7.0(2023-07-17)

适配ios16

查看更多

平台兼容性

Android Android CPU类型 iOS
适用版本区间:4.4 - 11.0 armeabi-v7a:支持,arm64-v8a:支持,x86:支持 适用版本区间:9 - 16

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


TX-TRTC

简介

TX-TRTC插件致力于让开发者一键实现腾讯的各种功能,需要uni-app的开发者门阅读腾讯文档,然后根据我的文档就可以找到对应的方法,轻松实现trtc的完整功能

tx-trtc-calling 快速实现呼叫挂断的逻辑

引入模块

const trtcall = uni.requireNativePlugin('tx-trtc-calling');

设置监听事件

trtcall.addDelegate(result=>{
                console.log(result);
        });

登录

trtcall.login({"sdkAppId":xxxxx,"sdkAppKey":"xxxxxxx","userId":user1},result=>{
                                            console.log(result);
})
字段 说明
sdkAppId 实时音视频和腾讯Im的appId
sdkAppKey 实时音视频和腾讯Im的appKey
userId 用户id
userSig 用户签名,与sdkAppKey二选其一,一般为了安全测试期间使用sdkAppKey,上线的时候使用userSig

登出

trtcall.logout(result=>{

});

呼叫

trtcall.call({"userId":user,"type"1});
字段 说明
userId 用户id
type 1 //语音邀请 2//视频邀请

接收

trtcall.accept();

拒绝

trtcall.reject();

挂断

trtcall.hangup();

停止远程用户流

trtcall.stopRemoteView(userid)
字段 说明
userId 用户id

停止本地视频采集及预览

trtcall.closeCamara();

切换摄像头

trtcall.switchCamera();

静音

trtcall.setMicMute(true);
字段 说明
bool类型 设置麦克风是否静音

准备

请前往https://cloud.tencent.com/product/trtc申请账号

tx-trtc-voiceroom 快速实现常规的语音聊天室的逻辑

引入模块

const voiceroom = uni.requireNativePlugin('tx-trtc-voiceroom');

设置监听事件

voiceroom.addDelegate(result=>{
                console.log(result);
            });

登录

voiceroom.login({"userId":this.userId,"sdkAppId":xxxxxxxxx,"sdkAppKey":"xxxxxxxxxxxxx"},result=>{
                console.log(result);    
            })
字段 说明
userId 用户id
sdkAppId 实时音视频和腾讯Im的appId
sdkAppKey 实时音视频和腾讯Im的appKey
userSig 用户签名,与sdkAppKey二选其一,一般为了安全测试期间使用sdkAppKey,上线的时候使用userSig

设置用户信息

voiceroom.setSelfProfile({"userName":"test",userAvatar:""},result=>{
                    console.log(result);
    })
字段 说明
userName 用户名称
userAvatar 用户头像

创建房间

voiceroom.createRoom({roomId:that.roomId,roomName:"room",coverUrl:"coverUrl","seatCount":7},result=>{
                            console.log(result);
})
字段 说明
roomId 房间id
roomName 房间名称
coverUrl 房间的头像
seatCount 槽位数量

加入语音槽

voiceroom.enterSeat({"seatIndex":0},result=>{
                                console.log(result);
    })
字段 说明
seatIndex 槽位下标

下麦

    voiceroom.leaveSeat(result=>{
                                        console.log(result);
        });

邀请某个上麦

voiceroom.pickSeat({"userId":obj.userId,"seatIndex":chooseIndex},result=>{
                                            console.log(result);
        })
字段 说明
userId 用户id
seatIndex 槽位下标

关闭槽位

voiceroom.closeSeat({"seatIndex":chooseIndex,"isClose":true},result=>{

    });
字段 说明
seatIndex 槽位下标
isClose 是否关闭

禁麦

    voiceroom.muteSeat({"seatIndex":chooseIndex,"isMute":true},result=>{

    });
字段 说明
seatIndex 槽位下标
isMute 是否禁麦

观众加入房间

voiceroom.enterRoom({"roomId":roomId},result=>{

    });
字段 说明
roomId 房间号

发送房间消息

    voiceroom.sendRoomTextMsg({"msg":msg},result=>{
                    console.log(result);
                });
字段 说明
msg 消息内容

发送房间自定义消息

    voiceroom.sendRoomCustomMsg({"cmd":cmd,"msg":msg},result=>{
                    console.log(result);
                });
字段 说明
cmd 自定义消息类型
msg 消息内容

主播销毁房间

voiceroom.destroyRoom(result=>{
                    console.log(result);
})

观众退出房间

voiceroom.exitRoom();

退出登录

voiceroom.logout(result=>{})

获取用户列表

voiceroom.getUserInfoList({"userIdList":["test1"]},result=>{
                    console.log(result);
})
字段 说明
userIdList 用户id的列表

发送邀请

    voiceroom.sendInvitation({"userId":obj.userId,"cmd":"2",content:"邀请你上麦"},result=>{
                                            console.log(result);                    
        })
字段 说明
userId 用户id
cmd 自定义命令
content 消息内容

接受邀请

voiceroom.acceptInvitation({"inviteId":identifier},result=>{

                            })
字段 说明
inviteId 邀请id

拒绝邀请

voiceroom.rejectInvitation({"inviteId":identifier},result=>{

                            })
字段 说明
inviteId 邀请id

取消邀请

voiceroom.cancelInvitation({"inviteId":identifier},result=>{

                            })
字段 说明
inviteId 邀请id

开始麦克风采集

voiceroom.startMicrophone();

停止麦克风采集

voiceroom.stopMicrophone();

设置声音模式

voiceroom.setAuidoQuality();

禁止本地音频采集

voiceroom.muteLocalAudio(true);
字段 说明
true or false 是否禁止声音采集

设置扬声器模式

voiceroom.setSpeaker(true);
字段 说明
true or false 是否设置扬声器

设置sdk采集音量

voiceroom.setAudioCaptureVolume(100);
字段 说明
整型 100为原始音量,范围是:[0 ~ 150],默认值为100

设置 SDK 播放音量

voiceroom.setAudioPlayoutVolume(100);
字段 说明
整型 100为原始音量,范围是:[0 ~ 150],默认值为100

禁止远程用户音频流

voiceroom.muteRemoteAudio(userid,true);
字段 说明
userid(字符串) 用户id
bool类型 true or false

禁止所有音频流

voiceroom.muteAllRemoteAudio(true);
字段 说明
bool类型 true or false

准备

请前往https://cloud.tencent.com/product/trtc申请账号

tx-trtc-liveroom 快速实现常规的直播聊天室的逻辑

引入模块

const liveroom = uni.requireNativePlugin('tx-trtc-liveroom');

设置监听事件

liveroom.addDelegate(result=>{
                console.log(result);
            });

移除监听事件

liveroom.removeDelegate(result=>{
                console.log(result);
            });

登录

liveRoom.login({"sdkAppId":0,"sdkAppKey":"","userId":"","useCDN":true,"cdnPlayDomain":""},result=>{
                                            console.log(result);                                          
                                        })
字段 说明
userId 用户id
sdkAppId 实时音视频和腾讯Im的appId
sdkAppKey 实时音视频和腾讯Im的appKey
userSig 用户签名,与sdkAppKey二选其一,一般为了安全测试期间使用sdkAppKey,上线的时候使用userSig
useCDN true or false,是否使用cdn
cdnPlayDomain cdn的播放域名

登出

liveRoom.logout(result=>{
                                            console.log(result);
                                        })

设置用户信息

liveRoom.setSelfProfile({userName:userName,userAvatar:userAvatar},result=>{
                    console.log(result);
                })
            }
| 字段      | 说明                                                         |
| --------- | ------------------------------------------------------------ |
| userName    | 用户名称                                                       |
| userAvatar  | 用户头像                                   |

创建房间

liveRoom.createRoom({roomId:roomId, roomName:"",coverUrl:""},result=>{
                    console.log(result);
                })
字段 说明
roomId 房间号

销毁房间

liveRoom.destroyRoom(result=>{
                    console.log(result);
            })

加入房间

liveRoom.enterRoom({roomId:roomId},result=>{
                    console.log(result);
                })
字段 说明
roomId 房间号

离开房间

liveRoom.exitRoom(result=>{
                    console.log(result);
                })

获取房间信息

liveRoom.getRoomInfos({roomIdList:[this.roomId]},result=>{
                    console.log(result);
                })
字段 说明
roomIdList 房间列表

获取主播列表

liveRoom.getAnchorList(result=>{
                    console.log(result);
                })

获取观众列表

liveRoom.getAudienceList(result=>{
                    console.log(result);
                })

推流并发布

liveRoom.startPublish({"streamId":streamId},result=>{
                    console.log(result);
                })
字段 说明
streamId 流id

停止发布

liveRoom.stopPublish(result=>{
                    console.log(result);
                })

观众端请求连麦

liveRoom.requestJoinAnchor({reason:""},result=>{
                    console.log(result);
});

主播端相应连麦

liveRoom.responseJoinAnchor({userId:this.user2,agree:true,reason:""},result=>{
                        console.log(result);
                    })
字段 说明
userId 用户id
agree 是否同意
reason 原因

主播踢除连麦观众

liveRoom.kickoutJoinAnchor({userId:this.user2},result=>{
                    console.log(result);
                })
| 字段      | 说明                                                         |
| --------- | ------------------------------------------------------------ |
| userId    |用户id                                                     |

请求pk

liveRoom.requestRoomPK({
                    roomId:roomId,
                    userId:this.user2
                },result=>{
                    console.log(result);
                    if(result.agree) {

                    }
                })
字段 说明
userId 用户id
roomId 房间id

响应pk

    liveRoom.responseRoomPK({
                        userId:this.user1,
                        agree:true,
                        reason:"",
                    } ,result=>{
                        console.log(result);
                    })
字段 说明
userId 用户id
agree 是否同意
reason 原因

退出pk

liveRoom.quitRoomPK(result=>{
                    console.log(result);
            })

设置镜像

liveRoom.setMirror(true);

是否静音

liveRoom.muteLocalAudio(true);

是否静音远端用户

liveRoom.muteRemoteAudio({userId:"",mute:true})

是否静音远端用户

liveRoom.muteAllRemoteAudio({mute:true});

设置音频质量

liveRoom.setAudioQuality({quality:1})

发送房间消息

liveRoom.sendRoomTextMsg({msg:""},result=>{
                    console.log(result);
                })
字段 说明
msg 消息内容

发送房间自定义消息

liveRoom.sendRoomCustomMsg({cmd:"",msg:""},result=>{
                    console.log(result);
                })
字段 说明
msg 消息内容
cmd 自定义字段

tx-trtc-meeting 快速实现常规的直播聊天室的逻辑

引入模块

const trtcMeeting = uni.requireNativePlugin('tx-trtc-meeting');

设置监听

    trtcMeeting.addDelegate(result=>{
                    console.log(result);
                },result=>{
                    console.log(result);
                })

移除监听

  trtcMeeting.removeDelegate(result=>{
                   console.log(result);
               })

登陆

trtcMeeting.login({"sdkAppId":0,"sdkAppKey":"","userId":_self.user1},result=>{
                                            console.log(result);

                                        })

设置用户信息

trtcMeeting.setSelfProfile({userName:userName,userAvatar:userAvatar},result=>{
                    console.log(result);
                })

创建会议

trtcMeeting.createMeeting({roomId:roomId},result=>{
                    console.log(result);
                })

加入会议

trtcMeeting.enterMeeting({roomId:roomId},result=>{
                    console.log(result);
                })

销毁会议

trtcMeeting.destroyMeeting({roomId:roomId},result=>{
                    console.log(result);
                })

离开会议

trtcMeeting.leaveMeeting(result=>{
                    console.log(result);
                })

获取用户信息列表

trtcMeeting.getUserInfoList(result=>{
                    console.log(result);
                })

获取用户信息

trtcMeeting.getUserInfo({userId:this.user1},result=>{
                    console.log(result);
                })

设置远程流模式

trtcMeeting.setRemoteViewFillMode(this.user2,0);

设置旋转

trtcMeeting.setRemoteViewRotation(this.user2,0);

设置静音

trtcMeeting.muteRemoteAudio(this.user2,true);

屏蔽远程流

trtcMeeting.muteRemoteVideoStream(this.user2,true);

设置分辨率相关

trtcMeeting.setVideoResolution(112);
trtcMeeting.setVideoFps(15);
trtcMeeting.setVideoBitrate(900);

设置镜像

trtcMeeting.setLocalViewMirror(true);

开启麦克风

trtcMeeting.startMicrophone();

停止麦克风

trtcMeeting.stopMicrophone();

设置声音质量

trtcMeeting.setAudioQuality(1);

静音本地

trtcMeeting.muteLocalAudio(true);

设置扬声器

trtcMeeting.setSpeaker(true);

设置声音采集

trtcMeeting.setAudioCaptureVolume(100);

设置声音播放音量

trtcMeeting.setAudioPlayoutVolume(100);

开启屏幕分享

trtcMeeting.startScreenCapture({videoResolution:112,resMode:1,videoFps:10,enableAdjustRes:false,videoBitrate:1500},result=>{
                    console.log(result);
                })

停止屏幕分享

trtcMeeting.stopScreenCapture();

暂停屏幕分享

trtcMeeting.pauseScreenCapture();

恢复屏幕分享

trtcMeeting.resumeScreenCapture();

发送文本消息

trtcMeeting.sendRoomTextMsg({msg:"hello"},result=>{
                    console.log(result);
                })

发送自定义消息

trtcMeeting.sendRoomCustomMsg({cmd:"0",msg:"hello"},result=>{
                    console.log(result);
                })

切换摄像头

trtcMeeting.switchCamera(true);

TRTCCloud

简介

TRTCCloud插件致力于让开发者一键实现腾讯的推流功能,需要uni-app的开发者门阅读腾讯文档,然后根据我的文档就可以找到对应的方法,轻松实现推流逻辑

快速接入

1.请前往https://cloud.tencent.com/product/trtc申请账号

2.下载示例项目

3.使用自己的appId和appKey替换app.js中的appId和appKey

4.在App原生插件配置选择云端插件,打包自定义基座,然后体验demo(如果不会制作安卓证书参考http://www.appuploader.net/appuploader/onlinetools.php)

api说明

推流组件:TRTCCloud

函数名称 说明
enterRoom 加入房间,具体参数见下
参数名 说明
appid 腾讯平台申请的appid(整数)
appkey 腾讯平台申请的appsecret(字符串)
userSig 可以不传appkey的签名,而是直接使用服务器签名好的userSig,这个和appkey二选其一(字符串)
roomId 房间号(整数)
userId 用户id(字符串)
role 用户角色:20 主播 21观众(整数)
scene 场景说明: 0视频聊天 1直播(整数)
callback 加入房间后的状态回调
strRoomId 字符串房间号(新增)和roomId二者选其一
scene 场景,可以取值为正数(1,2,3)
privateMapKey 用于权限控制的权限票据(选填),当您希望某个房间只能让特定的 userId 进入时,需要使用 privateMapKey 进行权限保护。
streamId 用于指定在腾讯云直播平台上的 streamId(选填),设置之后,您可以在腾讯云直播 CDN 上通过标准拉流方案(FLV或HLS)播放该用户的音视频流
userDefineRecordId 自动录制方案:需要在“https://console.cloud.tencent.com/trtc => 应用管理 => 云端录制配置”中开启云端录制(选填)

离开房间

        trtcCloud.exitRoom({},result=>{
                    console.log(result);
                });

是否屏蔽自己的视频画面

trtcCloud.muteLocalVideo({mute:true,streamType:0},result=>{
                    console.log(result);
                })
参数 说明
mute 是否静止视频
streamType 流类型

停止显示所有远端视频画面

trtcCloud.stopAllRemoteView({},result=>{
                    console.log(result);
                })

暂停接收指定的远端视频流

    trtcCloud.muteRemoteVideoStream({userId:this.user2,streamType:0,mute:true},result=>{
                     console.log(result);
                });
参数 说明
userId 用户id
streamType 流类型
mute 是否静止视频

停止接收所有的远端视频流

    trtcCloud.muteRemoteVideoStream({mute:true},result=>{
                     console.log(result);
                });
参数 说明
mute 是否静止视频

开启本地音频的采集和上行

trtcCloud.startLocalAudio({quality:2},result=>{
                    console.log(result);
                });
参数 说明
quality 1 人声模式 2 默认模式 3 音乐模式

关闭本地音频的采集和上行

    trtcCloud.stopLocalAudio({},result=>{
                    console.log(result);
                })

静音本地的音频

    trtcCloud.muteLocalAudio({mute:true},result=>{
                    console.log(result);
                })
参数 说明
mute 是否静音

静音掉某一个用户的声音

    trtcCloud.muteRemoteAudio({userId:this.user2,mute:true},result=>{
                    console.log(result);
                })
参数 说明
userId 用户id
mute 是否静音

静音掉所有用户的声音

    trtcCloud.muteAllRemoteAudio({mute:true},result=>{
                    console.log(result);
                })
参数 说明
mute 是否静音

切换摄像头

    trtcCloud.switchCamera({"frontCamera":false},result=>{
                    console.log(result);
                })
参数 说明
frontCamera 是否启用前置摄像头

设置音频路由

    trtcCloud.setAudioRoute({route:0},result=>{
                    console.log(result);
                })
参数 说明
route 整型 0 扬声器 1听筒

销毁 TRTCCloud 单例

        trtcCloud.destroySharedInstance({},result=>{
                    console.log(result);
                });

转换角色

    trtcCloud.switchRole({"role":20},result=>{
                    console.log(result);
                })
参数 说明
role 20主播 21观众

开启音量回调

        trtcCloud.enableAudioVolumeEvaluation({interval:5000},result=>{
                    console.log(result);
                })
参数 说明
interval 整形,回调间隔时间

发送消息

    trtcCloud.sendCustomCmdMsg({cmd:1,data:"hello",reliable:true,ordered:false},result=>{
                        console.log(result);
                    });
参数 说明
cmd cmd (1-10)
data 字符串
reliable bool
ordered bool

发送sei

        trtcCloud.sendSEIMsg({data:"hello",repeatCount:5},result=>{
                    console.log(result);
                });
参数 说明
data 字符串
repeatCount 重复次数

设置本地画面的渲染参数

    trtcCloud.setLocalRenderParams({rotation:0,fillMode:0,mirrorType:0},result=>{
                    console.log(result);
                });
参数 说明
rotation 0 不旋转
1 顺时针旋转90度
2 顺时针旋转180度
3 顺时针旋转270度
fillMode 0 填充模式 1 适应模式
mirrorType 0 自动模式 1 强制开启镜像 2 强制关闭镜像

设置远端渲染参数

    trtcCloud.setRemoteRenderParams({rotation:0,fillMode:0,mirrorType:0,streamType:0,userId:this.user2},result=>{
                     console.log(result);
                });
参数 说明
rotation 0 不旋转
1 顺时针旋转90度
2 顺时针旋转180度
3 顺时针旋转270度
fillMode 0 填充模式 1 适应模式
mirrorType 0 自动模式 1 强制开启镜像 2 强制关闭镜像
streamType 0 高清大画面
1 低清小画面
2 辅流画面 一般用于屏幕分享,同一时间在同一个房间中只允许一个用户发布辅流视频
userId 用户id

播放本地存储的音乐

        trtcCloud.startPlayMusic({
                    path:"http://mp3.9ku.com/mp3/555/554523.mp3",
                    loopCount:0,
                    id:5
                },result=>{
                    console.log(result);
                })
参数 说明
path 音乐的路径
loopCount 循环次数
id 音乐id

停止播放本地存储的音乐

        trtcCloud.stopPlayMusic({
                    id:5
                },result=>{
                    console.log(result);
                })
参数 说明
id 音乐id

暂停播放本地存储的音乐

    trtcCloud.pausePlayMusic({
                    id:5
                },result=>{
                    console.log(result);
                })
参数 说明
id 音乐id

继续播放本地存储的音乐

    trtcCloud.resumePlayMusic({
                    id:5
                },result=>{
                    console.log(result);
                })
参数 说明
id 音乐id

设置背景音乐的远端音量大小

        trtcCloud.setMusicPublishVolume({
                    id:5,
                    volume:100
                },result=>{
                    console.log(result);
                })
参数 说明
id 音乐id
volume 声音大小

设置背景音乐的本地音量大小

    trtcCloud.setMusicPlayoutVolume({
                    id:5,
                    volume:100
                },result=>{
                    console.log(result);
                })
参数 说明
id 音乐id
volume 声音大小

开始录音

    trtcCloud.startAudioRecording({},result=>{
                    console.log(result);
                })

停止录音

    trtcCloud.stopAudioRecording({},result=>{
                    console.log(result);
                })

跨房pk

    let jsonString = JSON.stringify({userId:this.user2,roomId:2});
                trtcCloud.connectOtherRoom({param:jsonString},result=>{
                    console.log(result);
                });

停止跨房pk

    trtcCloud.disconnectOtherRoom({},result=>{
                    console.log(result);
                });

设置订阅模式

    trtcCloud.setDefaultStreamRecvMode({autoRecvAudio:true,autoRecvVideo:true},result=>{
                    console.log(result);
                });
参数 说明
autoRecvAudio 是否自动接收音频数据,默认值:YES
autoRecvVideo 是否自动接收视频数据,默认值:YES

开始向腾讯云直播 CDN 上发布音视频流

    trtcCloud.startPublishing({streamId:"",streamType:0},result=>{
                    console.log(result);
                });
参数 说明
streamId 自定义流 ID
streamType 0 高清大画面
1 低清小画面
2 辅流画面 一般用于屏幕分享,同一时间在同一个房间中只允许一个用户发布辅流视频

停止向腾讯云的直播 CDN 推流

    trtcCloud.stopPublishing({},result=>{
                    console.log(result);
                });

SDK 采集音量

    trtcCloud.setAudioCaptureVolume({volume:100},result=>{
                    console.log(result);
                })
参数 说明
volume 音量大小

获取 SDK 采集音量

    trtcCloud.getAudioCaptureVolume({},result=>{
                    console.log(result);
                })

SDK 播放音量

        trtcCloud.setAudioPlayoutVolume({volume:100},result=>{
                    console.log(result);
                })
参数 说明
volume 范围是:[0 ~ 150],默认值为100

获取 SDK 播放音量

        trtcCloud.getAudioPlayoutVolume({},result=>{
                    console.log(result);
                })

设置远程音量

    trtcCloud.setRemoteAudioVolume({userId:this.user2,volume:150},result=>{
                    console.log(result);
                })
参数 说明
userId 用户id
volume 音量大小

截取图片

trtcCloud.snapshotVideo({sourceType:0,userId:"",type:0},result=>{})
参数 说明
type 0 高清大画面 1 低清小画面 2 辅流画面
sourceType 0 从视频流中截取原生的视频内容 1 从渲染控件中截取显示的视频内容
userId userId 用户 ID,如指定空置表示截取本地的视频画面 不传截取自己

设置视频编码器相关参数

        trtcCloud.setVideoEncoderParam({videoResolution:112,videoBitrate:1200,videoFps:15,resMode:1},result=>{
                    console.log(result);
                });
参数 说明
videoResolution 类型多,见腾讯文档
videoBitrate 目标视频码率
videoFps 视频采集帧率
resMode 分辨率模式(横屏分辨率 or 竖屏分辨率)0 横屏分辨率 1 竖屏分辨率

设置编码器输出的画面镜像模式

trtcCloud.setVideoEncoderMirror({mirror:true},result=>{
                    console.log(result);
                });
参数 说明
mirror true:开启远端画面镜像;false:关闭远端画面镜像,默认值:false

设置重力感应的适应模式,聊天模式下可以关闭重力感应

trtcCloud.setGSensorMode({model:0},result=>{
                    console.log(result);
                });
参数 说明
model 0 不适配重力感应 1 适配重力感应 2 适配重力感应
 trtcCloud.startLocalRecording({recordType:2,interval:1000},result=>{
                         console.log(result);
                     })
参数 说明
recordType 0表示仅录制音频 1表示仅录制视频 2表示同时录制音频和视频
path 录制文件路径,可以不传
interval 制信息更新频率

停止录制

trtcCloud.stopLocalRecording({},result=>{
         console.log(result);
     });

推流组件 TX-PlayView

函数名称 参数 说明
startLocalPreview 开启本地视频的预览画面
函数名称 参数 说明
stopLocalPreview 停止本地视频采集及预览
函数名称 参数 说明
startRemoteView 参数用户的userid,比如"xiaoming" 开始显示远端视频画面
函数名称 参数 说明
stopRemoteView 参数用户的userid 停止显示远端视频画面
函数名称 参数 说明
joinRoom 加入房间
函数名称 参数 说明
leaveRoom 离开房间
函数名称 参数 说明
enterRoom 参数列表,回调函数 参数列表支持{"appId":xxx,"appKey":xxx,"userSig":xxx,"roomId":xxx,"userId":xxx,"role":xxx,"privateMapKey":xxx,"streamId":xxx,"scene":xxx,"videoResolution":xxx,"videoBitrate":xxx,"videoFps":xxx,"resMode":xxx} 作用:加入房间

播放组件:TX-AVPlayer

函数名称 参数 说明
startPlay 开始播放
stopPlay 停止播放
pause 暂停播放
resume 继续播放
setCacheStrategy 整型 设置播放的速度 0 快速 1 平滑 2 自动
startPlayWithUrl 参数一 播放url地址(String) 参数二:播放类型type(int) type取值:0 RTMP 直播 1 FLV 直播 2 FLV 点播 3 HLS 点播 4 MP4点播 5 RTMP 直播加速播放

TX-PlayView属性说明:

属性名 属性值 备注
appId 应用id(整数) (必填)
appKey 应用的签名key(字符串) 与userSig二选其一
userSig 用户的签名(字符串) 后台生成 与appKey二选其一
roomId 房间号(整数) (必填)
userId 用户id (字符串) (必填)
remoteUserId 远程的用户id (字符串) 拉取远程用户的流,获取到远程用户id时赋值
role 用户角色 (整数) 20 主播 21观众 (可选)默认20
scene 场景 (整数) 0视频聊天 1直播 (可选)可选 默认0
whiteness 美白级别 (整数) 取值范围0 - 9;0表示关闭,1 - 9值越大,效果越明显 (可选)
ruddiness 红润级别 (整数) 取值范围0 - 9;0表示关闭,1 - 9值越大,效果越明显 (可选)
beauty 美颜级别 (整数) 取值范围0 - 9; 0表示关闭,1 - 9值越大,效果越明显 (可选)
beatyStyle 美颜风格 (整数) 光滑或者自然,0 光滑 1自然 (可选)
videoResolution 分辨率 (整数) 见视频分辨率 (可选)
videoBitrate 视频上行码率 (整数) 见后文说明,单位kbps (可选)
videoFps 视频采集帧率 (整数) (可选)
resMode 分辨率模式 (整数) 0横屏 1竖屏 (可选)
enableLocalPreview 是否开启本地预览 true开启 false关闭 (可选)
enableLocalAudio 是否开启音频采集 true 开启 false关闭 (可选)
mirror 是否开启镜像模式 true 开启 false关闭 (可选)
statechange 推流中的状态回调用 (可选)
filterFileName 滤镜图片 可取值有15种,见下面说明 (可选)
remoteSubStreamUserId 远程的屏幕共享的userid (字符串)
remoteSubStreamModel 远程屏幕共享的拉流方式 0 全屏 1 自适应
streamId 流id(字符串)如果开启旁路推流,此参数有用,用来指令旁路的拉流地址,最终观看的格式为:http://播放域名/live/[streamId].flv (可选)
filterFileName可取值如下:
bailan.png
chaotuo.png
chunzhen.png
fennen.png
huaijiu.png
landiao.png
langman.png
normal.png
qingliang.png
qingxin.png
rixi.png
weimei.png
white.png
xiangfen.png
yinghong.png
yuanqi.png
yunshang.png

TX-AVPlayer属性说明

属性名 属性值 备注
url 播放地址 (必填)
playModel 播放模式 画面裁剪模式: 0 全屏 1 图像适应屏幕,保持画面完整 (可选)
playRotation 设置画面方向 Ios : 0 HOME 键在右边,横屏模式 1 HOME 键在下面,手机直播中最常见的竖屏直播模式 2 键在左边,横屏模式 3 HOME 键在上边,竖屏直播. andriod: 0 竖屏 270 横屏模式 ios和安卓在这个属性上有差别,需要分平台判断,如果用竖屏模式可以不用设置这个,使用默认值,如果设置错误会导致安卓不能全屏
statechange 状态回调 (可选)

LivePlayer常用函数

函数名称 参数 说明
initLivePlayer 初始化播放器
函数名称 参数 说明
setObserver 回调函数 设置播放监听
函数名称 参数 说明
removeObserver 移除播放监听
函数名称 参数 说明
startPlay {url:""} 开始播放音视频流
函数名称 参数 说明
setPlayoutVolume {playoutVolume:100} 设置播放器音量 取值0-100
函数名称 参数 说明
setRenderFillMode 整数 设置画面的填充模式 0: 图像铺满屏幕 1: 图像长边填满屏幕
函数名称 参数 说明
setRenderRotation 整数 0: 不旋转 1: 顺时针旋转90度 2: 顺时针旋转180度 3: 顺时针旋转270度
函数名称 参数 说明
enableVolumeEvaluation 整数 启用播放音量大小提 0为不开启,单位ms
函数名称 参数 说明
enableReceiveSeiMessage (bool类型,整数) 开启接收 SEI 消息
函数名称 参数 说明
snapshot 截取播放过程中的视频画面
函数名称 参数 说明
stopPlay 停止播放
函数名称 参数 说明
isPlaying 是否正在播放
函数名称 参数 说明
pauseAudio 暂停播放器的音频流
函数名称 参数 说明
resumeAudio 恢复播放器的音频流
函数名称 参数 说明
pauseVideo 暂停播放器的视频流
函数名称 参数 说明
resumeVideo 恢复播放器的视频流
函数名称 参数 说明
setCacheParams {minTime:1,maxTime:5} 设置播放器缓存自动调整的最小和最大时间 ( 单位:秒 )

TX-TRTCScreenView属性说明

属性名 属性值 备注
appId 应用id(整数) (必填)
appKey 应用的签名key(字符串) 与userSig二选其一
roomId 房间号(整数) (必填)
userId 用户id (字符串) (必填)
role 用户角色 (整数) 20 主播 21观众 (可选)默认20
scene 场景 (整数) 0视频聊天 1直播 (可选)可选 默认0

TX-TRTCScreenView方法说明

函数名称 参数 说明
startScreen {audio:1,camera:1,,key:value ....} key 为 TX-TRTCScreenView属性支持的key如roomId,userId,如果这些属性之前设置过,可以不用设置,audio为1开启声音,0关闭声音,camera为1启动视频预览界面,0关闭 开启录屏
stopScreen 结束录屏

关于ios和安卓使用TX-TXTRTCCloud录屏的处理

函数名称 参数 说明
startScreenCapture {appGroup:xxxx,enableAdjustRes:false,videoResolution:108,resMode:1,videoFps:15,videoBitrate:500} appGroup:ios使用,可以不填写,安卓直接忽略,enableAdjustRes,videoResolution,resMode,videoFps,videoBitrate都是可选,可以不填写
stopScreenCapture 停止录屏
pauseScreenCapture 2个参数 传参数({},result=>{})
resumeScreenCapture 2个参数 传参数({},result=>{})

ios需要应用扩展才能使用录屏功能如果不需要ios的录屏功能请忽略以下步骤

1.按图示创建文件夹和文件具体资源群资源里下载,把nativeplugins放到与pages同级目录

image

2.修改文件

image

修改identifier为你的应用id,如果你ios工程的包名为com.test.ios,那么你这里应创建的应用id为com.test.ios.xxx类型,然后填写到此处

修改profile为你所创建的应用id对应的profile证书,命名类型为ios-xxxxxx.mobileprovision

修改CFBundleDisplayName为应用扩展的名字,它将显示在此处

image

3.下载插件例子工程进入screenshare.nvue点击开始录屏

4.长按录屏按钮弹出上图的界面,点击Start Broadcasrt开始录屏

视频分辨率说明

常量 描述
TRTCVideoResolution_120_120 = 1 建议码率80kbps
TRTCVideoResolution_160_160 = 3 建议码率100kbps
TRTCVideoResolution_270_270 = 5 建议码率200kbps
TRTCVideoResolution_480_480 = 7 建议码率350kbps
TRTCVideoResolution_160_120 = 50 建议码率100kbps
TRTCVideoResolution_240_180 = 52 建议码率150kbps
TRTCVideoResolution_280_210 = 54 建议码率200kbps
TRTCVideoResolution_320_240 = 56 建议码率250kbps
TRTCVideoResolution_400_300 = 58 建议码率300kbps
TRTCVideoResolution_480_360 = 60 建议码率400kbps
TRTCVideoResolution_640_480 = 62 建议码率600kbps
TRTCVideoResolution_960_720 = 64 建议码率1000kbps
TRTCVideoResolution_160_90 = 100 建议码率100kbps
TRTCVideoResolution_256_144 = 102 建议码率150kbps
TRTCVideoResolution_320_180 = 104 建议码率250kbps
TRTCVideoResolution_480_270 = 106 建议码率350kbps
TRTCVideoResolution_640_360 = 108 建议码率550kbps
TRTCVideoResolution_960_540 = 110 建议码率850kbps
TRTCVideoResolution_1280_720 = 112 摄像头采集 - 建议码率1200kbps
TRTCVideoResolution_1920_1080 = 114 屏幕分享 - 建议码率800kbps

使用说明: 见示例工程中的index.nvue文件

TX-TencentIM组件

TX-TencentIM组件

TX-TencentIM致力于让用户轻松使用im的各种功能,插件永久维护,欢迎提需求👏👏👏

快速接入方法

加载模块

const txIm = uni.requireNativePlugin('TX-TencentIM');

初始化腾讯云SDK

 let isSuccess = txIm.initSDK({
     sdkAppID:1400267352,
     logLevel:0
   },result=>{
        console.log(result);
   })
字段 说明
sdkAppID 腾讯云IM后台应用的appid
logLevel 日志等级(V2TIM_LOG_NONE = 0, ///< 不输出任何 sdk log V2TIM_LOG_DEBUG = 3, ///< 输出 DEBUG,INFO,V2TIM_LOG_INFO = 4, ///< 输出 INFO,WARNING,ERROR 级别的 log,V2TIM_LOG_WARN = 5, ///< 输出 WARNING,ERROR 级别的 log,V2TIM_LOG_ERROR = 6, ///<
见例子中的index.nvue出 ERROR 级别的 log) 可以不填写

登录腾讯云IM(一定要先初始化腾讯云SDK后登录)

txIm.login({
                                            sdkAppID: 1400267352,
                                            sdkAppKey: "5f787315061dcad732b8b41185c7b63b09d2a57d8efe1219d803920f84963a0b",
                                            userId: "userTest1",
                                            expireTime:604800,
                                            filePath: plus.io.convertLocalFileSystemURL('_doc')
                                        }, result => {
                                            console.log(result);
                        })
字段 说明
sdkAppID 腾讯云IM后台应用的appid
sdkAppKey 腾讯云IM后台应用的appKey
userId 用户id
expireTime 登录过期时间,可以不填写
logLevel 日志等级(V2TIM_LOG_NONE = 0, ///< 不输出任何 sdk log V2TIM_LOG_DEBUG = 3, ///< 输出 DEBUG,INFO,V2TIM_LOG_INFO = 4, ///< 输出 INFO,WARNING,ERROR 级别的 log,V2TIM_LOG_WARN = 5, ///< 输出 WARNING,ERROR 级别的 log,V2TIM_LOG_ERROR = 6, ///< 输出 ERROR 级别的 log) 可以不填写
filePath 资源存储地址,可以不填写,使用默认的资源路径
userSig 用户签名与sdkAppKey二选其一,一般上线后使用userSig

登出腾讯云im

txIm.logout(result=>{
                                            console.log(result);
                        }) 

获取当前登录用户

let user = txIm.getLoginUser();
                console.log(user);

销毁im

    txIm.unInitSDK(result=>{
                    console.log(result);
                })  

获取腾讯云im的登录状态

let status = txIm.getLoginStatus();
console.log(status);

设置基本消息(文本消息和自定义消息)的事件监听器

txIm.addSimpleMsgListener(result=>{
                    console.log(result);
                })

设置高级消息接口监听

    txIm.addAdvancedMsgListener(result=>{
                    console.log(result);
                })

设置群消息监听

    txIm.setGroupListener(result=>{
                    console.log(result);
    })

设置会话监听器

txIm.setConversationListener(result=>{
                    console.log(result);
                })

设置好友消息监听

    txIm.setFriendListener(result=>{
                    console.log(result);
    })

移除基本消息(文本消息和自定义消息)的事件监听器

txIm.removeSimpleMsgListener();

移除高级消息监听

txIm.removeAdvancedMsgListener()

移除群消息监听

txIm.removeGroupListener()

移除好友消息监听

txIm.removeFriendListener()

移除好友监听器

txIm.removeConversationListener()

移除不需要的消息,可以关闭会话的时候调用

txIm.removeMessages({"msgIdList":[this.currentMsgId]},result=>{
                    console.log(result);
                })
字段 说明
msgIdList 消息id的数组

针对某个用户的 C2C 消息接收选项

txIm.setC2CReceiveMessageOpt({userIdList:["userTest1"],opt:0},result=>{
    console.log(result);
})
字段 说明
userIdList 用户id列表
opt 0, ///< 在线正常接收消息,离线时会进行 APNs 推送 1, ///< 不会接收到消息,离线不会有推送通知 2, ///< 在线正常接收消息,离线不会有推送通知

设置群消息的接收选项

txIm.setGroupReceiveMessageOpt({groupId:"groupTest",opt:0},result=>{
    console.log(result);
})
字段 说明
groupId 群id
opt 0, ///< 在线正常接收消息,离线时会进行 APNs 推送 1, ///< 不会接收到消息,离线不会有推送通知 2, ///< 在线正常接收消息,离线不会有推送通知

添加朋友

txIm.addFriend({"userId":"user","addWording":"你好","addSource":"andriod",addType:1},result=>{
                    console.log(result)
 })
字段 说明
userId 用户id
addWording 添加说明
friendRemark 备注
addSource 添加来源
addType 添加类型 1 ///< 单向好友 2 ///< 双向好友

获取当前用户已经加入的群列表

    txIm.getJoinedGroupList(result=>{
                                                console.log(result);
    });

好友列表

    txIm.getFriendList(result=>{
                console.log(result);
    });

获取指定好友资料

txIm.getFriendsInfo({"userIdList":["userTest1","userTest2"]},result=>{
                    console.log(result);
})
字段 说明
userIdList 用户id列表

拉取群资料

txIm.getGroupsInfo({"groupIdList":["groupTest1","groupTest2"]},result=>{
                    console.log(result);
})
字段 说明
groupIdList 群组id列表

修改群资料

    txIm.setGroupInfo({"groupId":"","groupName":"测试设置       groupName","groupAvatar":"","introduction":"",notification:""},result=>{
                    console.log(result);
    })
字段 说明
groupId 群id
groupName 群名称
groupAvatar 群头像
introduction 群简介
notification 群公告
allMuted 是否全员禁言
groupAddOpt 加群是否需要管理员审批, 0禁止加群 1需要管理员审批 2任何人可以加入
customInfo {key:value} 自定义字段

修改群消息接收选项

    txIm.setReceiveMessageOpt({"groupId":"testGroup1","opt":0},result=>{
                    console.log(result);
    })
字段 说明
groupName 群名称
opt 0, ///< 在线正常接收消息 1, ///< 不会接收到群消息 2, ///< 在线正常接收消息,离线不会有推送通知

获取群成员列表

txIm.getGroupMemberList({"groupId":"testGroup1","filter":0,"nextSeq":0},result=>{
                    console.log(result);
    })
字段 说明
groupId 群id
filter 0, ///< 全部成员 1, ///< 群主 2, ///< 管理员 4, ///< 普通成员
nextSeq 分页拉取标志,第一次拉取填0

获取指定的群成员资料

    txIm.getGroupMembersInfo({"groupId":this.groupId,"memberList":userIdArr},result=>{
                    console.log(result);
                })

修改指定的群成员资料

txIm.setGroupMemberInfo({"groupId":"testGroup1","userId":"userTest1","nameCard":"nameCard"},result=>{
                    console.log(result);
})
字段 说明
groupId 群id
userId 用户id
nameCard 群成员名片

禁言群成员

txIm.muteGroupMember({"groupId":"testGroup1","userId":"userTest1","stime":1000},result=>{
                    console.log(result);
    })
字段 说明
groupId 群id
userId 用户id
stime 禁言时间

邀请他人入群

    txIm.inviteUserToGroup({"groupId":"testGroup1","userIdList":["userTest1"]},result=>{
                    console.log(result);
                })
字段 说明
groupId 群id
userIdList 用户id列表

踢人

    txIm.kickGroupMember({"groupId":"testGroup1","userIdList":["userTest1"],"reason":"reason"},result=>{
                    console.log(result);
                })
字段 说明
groupId 群id
userIdList 用户id列表
reason 原因

切换群成员的角色

txIm.setGroupMemberRole({"groupId":"testGroup1","userId":"userTest1","role":300},result=>{
                    console.log(result);
    })
字段 说明
groupId 群id
userId 用户id
role 用户角色 200, ///< 群成员 300, ///< 群管理员 400, ///< 群主

转让群

txIm.transferGroupOwner({"groupId":"testGroup1","userId":"userTest2"},result=>{
                    console.log(result);
                })
字段 说明
groupId (群id)
userId 用户id

获取加群的申请列表

txIm.getGroupApplicationList(result=>{
                    console.log(result);
                    if(result.groupApplicationList.length > 0) {
                        this.groupApplicationIndex = 0;
                    }
                })

获取加群的申请列表

txIm.getGroupApplicationList(result=>{
                    console.log(result);
                    if(result.groupApplicationList.length > 0) {
                        this.groupApplicationIndex = 0;
                    }
})

同意某一条加群申请

txIm.acceptGroupApplication({"index":0},result=>{
                    console.log(result);
    })
字段 说明
index 下标值,有getGroupApplicationList返回

拒绝某一条加群申请

    txIm.refuseGroupApplication({"index":0},result=>{
                    console.log(result);
                })
字段 说明
index 下标值,有getGroupApplicationList返回
reason 原因

标记申请列表为已读

txIm.setGroupApplicationRead(result=>{
                    console.log(result);
                })

获取会话列表

txIm.getConversationList({nextSeq:0,count:100},result=>{
                    console.log(result);
                    if(result.conversationList.length > 0) {
                        this.conversationId = result.conversationList[0].conversationId
                    }
    })
字段 说明
nextSeq 分页拉取游标,第一次默认取传 0
count 分页拉取的个数,一次分页拉取不宜太多,会影响拉取的速度,建议每次拉取 100 个会话

删除会话

    txIm.deleteConversation({conversationId:""},result=>{
                    console.log(result);
        })
字段 说明
conversationId 会话id,由getConversationList返回

设置会话草稿

txIm.setConversationDraft({conversationId:"",draftText:""},result=>{

})
字段 说明
conversationId 会话id,由getConversationList返回
draftText 草稿文本

获取用户资料

txIm.getUsersInfo({userIdList:["userTest1"]},result=>{
                    console.log(result);
        })
字段 说明
userIdList 用户id列表

修改个人资料

    txIm.setSelfProfile({"userName":"myUserName","userAvatar":"",gender:1},result=>{
                    console.log(result);
                })
字段 说明
userName 用户昵称
userAvatar 用户头像
gender 性别 0, ///< 未知性别 1, ///< 男性 2, ///< 女性
allowType 0, ///< 同意任何用户加好友 1, ///< 需要验证 2, ///< 拒绝任何人加好友
customInfo {key:value} 自定义字段

设置会话草稿

    txIm.setConversationDraft({"conversationId":"test","draftText":"test"},result=>{
                    console.log(result);
                })

发送群文本消息

    txIm.sendGroupTextMessage({"textMsg":"hello my group message","groupId":"testGroup1","priority":0},result=>{
                    console.log(result);
                })
字段 说明
textMsg 消息
groupId 群id

发送群自定义消息

txIm.sendGroupCustomMessage({"customMsg":"hello my group custom message","groupId":"","priority":0},result=>{
                    console.log(result);
        })
字段 说明
customMsg 消息
priority 消息优先级

发送一对一消息

txIm.sendC2CTextMessage({"textMsg":"hello","userId":"userTest1"},result=>{
                    console.log(result);
    });
字段 说明
textMsg 消息
userId 用户id

发送一对一自定义消息

txIm.sendC2CCustomMessage({"customMsg":"hello","userId":"userTest1"},result=>{
                    console.log(result);
    });
字段 说明
customMsg 消息
userId 用户id

创建群

    txIm.createGroup({
                    groupType: "Work",
                    groupId: this.groupId,
                    groupName: "my_group"
                }, result => {
                    console.log(result);

                })
字段 说明
groupType 群类型 Work 工作群 Public 公开群 Meeting 会议群 AVChatRoom 直播群
groupName 群名称
groupId 群id

选择群成员创建群

txIm.createGroupWithMemberList({
                    groupType: "Public",
                    groupId: this.groupId,
                    groupName: "my_group",
                    groupAvatar:"",
                    introduction:"",
                    memberList:[
                        {
                            userId:"MyGroupUserId1",
                            role:400
                        },
                        {
                            "userId":"MyGroupUserId2",
                            "role":0
                        },
                        {
                            "userId":"MyGroupUserId3",
                            "role":400
                        }

                    ]
                }, result => {
                    console.log(result);

                })
字段 说明
groupId 群id
groupName 群名称
groupType 群类型
memberList 群成员列表 userId:用户id role:200, ///< 群成员 300, ///< 群管理员 400, ///< 群主

加入群

txIm.joinGroup({"groupId":"testGroup1"},result=>{
                    console.log(result);
})
字段 说明
groupId 群id

离开群

    txIm.quitGroup({"groupId":"testGroup1"},result=>{
                    console.log(result);
    })
字段 说明
groupId 群id

删除群

    txIm.deleteGroup({"groupId":"testGroup1"},result=>{
                    console.log(result);
    })
字段 说明
groupId 群id

获取指定群在线人数

    txIm.getGroupOnlineMemberCount({groupId:this.groupId},result=>{
                    console.log(result);
                })
字段 说明
groupId id

获取所有的未读消息数量

txIm.getTotalUnreadMessageCount(result=>{
     console.log(result);
})

初始化群属性

    txIm.initGroupAttributes({groupId:this.groupId,attributes:{key:"key1"}},result=>{
                    console.log(result);
                })
字段 说明
groupId id
attributes 群属性,key value的形式

获取群属性

    txIm.getGroupAttributes({groupId:this.groupId},result=>{
                    console.log(result);
                })
字段 说明
groupId id

设置群属性

txIm.setGroupAttributes({groupId:this.groupId,attributes:{
                        "key1":"value1",
                        "key2":"value2"
                    }},result=>{
                        console.log(result);
                    })
字段 说明
groupId id
attributes 群属性,key value的形式

删除群属性

    txIm.deleteGroupAttributes({groupId:this.groupId,keys:["key1","key2"]},result=>{
                    console.log(result);
                })
字段 说明
groupId id
keys 清空的属性,不传清空所有的属性

禁言

字段 说明
groupId 群id
userId 用户id
stime 时间

禁言

字段 说明
groupId 群id
userId 用户id
stime 时间

发送图片消息

txIm.sendImageMessage({"path":"","userId":"userTest1"},result=>{
                    console.log(result);
    });
字段 说明
path 路径
userId 用户id
groupId 群id
priority 优先级,整数
onlineUserOnly 是否为在线接收,true or false,默认false
title 推送title
desc 推送描述
ext 推送附加信息

发送声音消息

    txIm.sendSoundMessage({"path":"","userId":"userTest1","duration":1},result=>{
                console.log(result); 
    });
字段 说明
path 路径
userId 用户id
groupId 群id
priority 优先级,整数
onlineUserOnly 是否为在线接收,true or false,默认false
duration 时间长度
title 推送title
desc 推送描述
ext 推送附加信息

发送视频消息

    txIm.sendVideoMessage({"path":"","userId":"userTest1","duration":1},result=>{
                console.log(result); 
    });
字段 说明
path 路径
userId 用户id
groupId 群id
priority 优先级,整数
onlineUserOnly 是否为在线接收,true or false,默认false
duration 时间长度
snapshotPath 封面图
type 视频类型,如 mp4 mov 等
title 推送title
desc 推送描述
ext 推送附加信息

发送文件消息

txIm.sendFileMessage({"path":res.filePath,"userId":user,fileName:res.fileName},result=>{
                                        console.log(result);
    });
字段 说明
path 路径
userId 用户id
groupId 群id
priority 优先级,整数
onlineUserOnly 是否为在线接收,true or false,默认false
fileName 文件名称
title 推送title
desc 推送描述
ext 推送附加信息

发送位置消息

txIm.sendLocationMessage({"userId":user,"des":"","longitude":66,"latitude":66,"priority":0},result=>{
                            console.log(result);
    });
字段 说明
des 描述
longitude 经度
latitude 纬度
userId 用户id
groupId 群id
priority 优先级,整数
onlineUserOnly 是否为在线接收,true or false,默认false
title 推送title
desc 推送描述
ext 推送附加信息

发送表情包消息

    txIm.sendFaceMessage({
                    "userId":user,
                    faceIndex:19,
                    faceData:""
                },result=>{
                    console.log(result);
    })
字段 说明
userId 用户id
groupId 群id
priority 优先级整数
onlineUserOnly rue or false,默认false
faceIndex 整数
faceData 字符串
title 推送title
desc 推送描述
ext 推送附加信息

创建文本消息

    let message = txIm.createTextMessage({textMsg:"test"});
字段 说明
textMsg 文本消息

创建图片消息

    let message = txIm.createImageMessage({path:this.imagePath});
字段 说明
path 图片路径

创建语音消息

    let message = txIm.createSoundMessage({path:"",duration:0}) 
字段 说明
path 语音文件路径
duration 时长

创建视频消息

    let message = txIm.createVideoMessage({path:"",type:0,duration:0,snapshotPath:""}); 
字段 说明
path 视频文件路径
duration 时长
snapshotPath 封面图

创建文件消息

    let message = txIm.createFileMessage({path:"",fileName:""});    
字段 说明
path 文件路径
fileName 文件名称

创建位置消息

    let message = txIm.createLocationMessage({des:"",longitude:0,latitude:0});  
字段 说明
des 描述
longitude 经度
latitude 纬度

创建表情消息

    let message = txIm.createFaceMessage({faceIndex:0,faceData:""});    
字段 说明
faceIndex 表情下标
faceData 表情data

创建@消息

    let message = txIm.createTextAtMessage({textMsg:"",userIdList:[]}); 
字段 说明
textMsg 文本消息
userIdList 用户id的列表

发送消息

    txIm.sendMessage({"userId":user,"createMessageId":this.createMessageId},result=>{
                    console.log(result);
                })      
字段 说明
userId 用户id
groupId 群id
priority 消息优先级
onlineUserOnly 是否在线用户
cloudCustomData 云端自定义数据
title 推送的title
desc 推送的描述
ext 推送的附加字段

删除好友

txIm.deleteFromFriendList({
                    "userIdList":["userTest2"],
                    "deleteType":1
                },result=>{
                    console.log(result);
    })
字段 说明
userIdList 用户id的列表
deleteType 1, ///< 单向好友 2, ///< 双向好友

删除消息

  txIm.deleteMessages({"msgIdList":[this.currentMsgId]},result=>{
                    console.log(result);
                })  
字段 说明
msgIdList 消息列表

检查指定用户的好友关系

txIm.checkFriend({
                    "userId":"userTest2",
                },result=>{
                    console.log(result);
    })

获取好友申请列表

txIm.getFriendApplicationList(result=>{
                    console.log(result);
    })

接受好友申请

txIm.acceptFriendApplication({
                    "userId":"userTest2",
                    "type":0
                },result=>{
                    console.log(result);
    })
字段 说明
userId 用户id
type 好友申请接受类型 0, ///< 接受加好友(建立单向好友)1, ///< 接受加好友并加对方为好友(建立双向好友)

拒绝好友申请

txIm.refuseFriendApplication({
                    "userId":"userTest2"
                },result=>{
                    console.log(result);
    })
字段 说明
userId 用户id

删除好友申请

txIm.deleteFriendApplication({
                    "userId":"userTest2"
                },result=>{
                    console.log(result);
    })
字段 说明
userId 用户id

置好友申请已读

txIm.setFriendApplicationRead(
        result=>{
                    console.log(result);
    })

添加用户到黑名单

txIm.addToBlackList({
                    "userIdList":["userTest2"]
                },result=>{
                    console.log(result);
    })
字段 说明
userIdList 用户id列表

获取黑名单列表

txIm.getBlackList(
                    result=>{
                        console.log(result);
                    }
    )

把用户从黑名单中删除

txIm.deleteFromBlackList({"userIdList":["userTest1"]},
                    result=>{
                        console.log(result);
                    }
                )
字段 说明
userIdList 用户id列表

新建好友分组

txIm.createFriendGroup({"groupName":this.friendGroupName,"userIdList":["userTest2"]},
                    result=>{
                        console.log(result);
                    }
                )
字段 说明
groupName 分组名称
userIdList 用户id列表

获取分组信息

txIm.getFriendGroupList({"groupNameList":["friendGroupName"]},result=>{
                    console.log(result);
    })
字段 说明
groupNameList 要获取信息的好友分组名称列表

删除好友分组

txIm.deleteFriendGroup({"groupNameList":["friendGroupName"]},result=>{
                    console.log(result);
})
字段 说明
groupNameList 好友分组名称列表

修改好友分组的名称

txIm.renameFriendGroup({"oldName":"oldName","newName":"newName"},result=>{
                    console.log(result);
    })
字段 说明
oldName 旧的名称
newName 新的名称

添加好友到一个好友分组

txIm.addFriendsToFriendGroup({"groupName":"friendGroupName","userIdList":["userTest1"]},
                    result=>{
                        console.log(result);
                    }
    )
字段 说明
groupName 组名
userIdList 用户id的列表

从好友分组中删除好友

txIm.deleteFriendsFromFriendGroup({"groupName":"friendGroupName","userIdList":["userTest1"]},
                    result=>{
                        console.log(result);
                    }
)
字段 说明
groupName 组名
userIdList 用户id的列表

获取单聊历史消息

txIm.getC2CHistoryMessageList({"userId":"userTest1","count":10,"msgId":""},result=>{
                    console.log(result);
    })
字段 说明
userId 用户id
count 拉取消息的个数
msgId 分页的msgId,第一次可以传""

获取群组历史消息

txIm.getGroupHistoryMessageList({"groupId":"groupTest1","count":10,"msgId":""},result=>{
                    console.log(result);
    })
字段 说明
groupId 群组id
count 拉取消息的个数
msgId 分页的msgId,第一次可以传""

撤回消息

    txIm.revokeMessage({"msgId":this.currentMsgId},result=>{
                    console.log(result);
    });
字段 说明
msgId 消息id

设置单聊消息已读

    txIm.markC2CMessageAsRead({"userId":"userTest2"},result=>{
                    console.log(result);
    })
字段 说明
userId 用户id

设置群组消息已读

txIm.markGroupMessageAsRead({"groupId":this.groupId},result=>{
                    console.log(result);
    })
字段 说明
groupId 群组id

删除本地消息

    txIm.deleteMessageFromLocalStorage({"msgId":this.currentMsgId},result=>{
                    console.log(result);
    });
字段 说明
msgId 消息id

向群组消息列表中添加一条消息

txIm.insertGroupMessageToLocalStorage({"createMessageId":this.createMessageId,"groupId":this.groupId,"userId":this.currentUser},result=>{
                    console.log(result);
    });
字段 说明
createMessageId 创建的消息id
sender 群id
userId 发送者id

清空群聊本地及云端的消息

txIm.clearGroupHistoryMessage({groupId:""},result=>{
    console.log(result);
});
字段 说明
groupId 群id

插入一对一单聊消息

txIm.insertC2CMessageToLocalStorage({"createMessageId":this.createMessageId,"sender":this.currentUser,"to":user},result=>{
                    console.log(result);
    });
字段 说明
createMessageId 创建的消息id
sender 发送者id
to 发送给其他人的id

清空单聊本地及云端的消息

txIm.clearC2CHistoryMessage({userId:""},result=>{
    console.log(result);
});
字段 说明
userId 用户id

发送群@消息

txIm.sendTextAtMessage({"textMsg":"@消息","groupId":this.groupId,"userIdList":["userTest1","all"]},result=>{
                    console.log(result);
    });
字段 说明
textMsg 文本消息
groupId 群id
userIdList 用户id列表,需要@所有人,在id列表中加all
priority 消息优先级
onlineUserOnly 是否在线用户
title 推送title
desc 推送描述
ext 推送附加信息

设置指定好友资料

txIm.setFriendInfo({"userId":"userTest2","friendRemark":"friendRemarkValue"},result=>{
                    console.log(result);
    });
字段 说明
userId 用户id
friendRemark 好友备注
friendCustomInfo {key:value} 自定义字段

添加信令监听

邀请某个人

txIm.invite({"invitee":user,"data":JSON.stringify(data),"onlineUserOnly":false},result=>{
                    console.log(result);
                });
字段 说明
invitee 被邀请人用户 ID
data 自定义数据
onlineUserOnly 是否只有在线用户才能收到邀请
timeout 超时时间,单位 s,如果设置为 0,SDK 不会做超时检测
title 推送title
desc 推送描述
ext 推送附加信息

移除信令监听

邀请群内的某些人

txIm.inviteInGroup({"groupId":this.group,"inviteeList":[user],"data":JSON.stringify(data),"onlineUserOnly":false},result=>{
                    console.log(result);
                });
字段 说明
groupId 发起邀请所在群组
inviteeList 被邀请人列表
data 自定义数据
onlineUserOnly 是否只有在线用户才能收到邀请
timeout 超时时间,单位 s,如果设置为 0,SDK 不会做超时检测
title 推送title
desc 推送描述
ext 推送附加信息

接收方接受邀请

txIm.accept({"inviteId":this.inviteData.inviteId,data:JSON.stringify(data)},result=>{
                        console.log(result);
                    });
字段 说明
inviteId 邀请id
data 自定义数据

接收方拒绝邀请

txIm.reject({"inviteId":this.inviteData.inviteId,data:JSON.stringify(data)},result=>{
                        console.log(result);
                    });
字段 说明
inviteId 邀请id
data 自定义数据

邀请方取消邀请

txIm.cancel({"inviteId":this.inviteData.inviteId,data:JSON.stringify(data)},result=>{
                        console.log(result);
                    });
字段 说明
inviteId 邀请id
data 自定义数据

下载图片

txIm.downloadImage({"msgId":msg.msgId},progressResult=>{
                                console.log(progressResult);
                            },succResult=>{
                                console.log(succResult);
                            },failResult=>{
                                console.log(failResult);
                            })
字段 说明
msgId 消息id
progressResult 下载进度
succResult 成功回调
failResult 失败回调

下载语音

txIm.downloadSound({"msgId":msg.msgId},progressResult=>{
                                console.log(progressResult);
                            },succResult=>{
                                console.log(succResult);
                            },failResult=>{
                                console.log(failResult);
                            })
字段 说明
msgId 消息id
progressResult 下载进度
succResult 成功回调
failResult 失败回调

下载视频

txIm.downloadVideo({"msgId":msg.msgId},progressResult=>{
                                console.log(progressResult);
                            },succResult=>{
                                console.log(succResult);
                            },failResult=>{
                                console.log(failResult);
                            })
字段 说明
msgId 消息id
progressResult 下载进度
succResult 成功回调
failResult 失败回调

下载文件

txIm.downloadFile({"msgId":msg.msgId},progressResult=>{
                                console.log(progressResult);
                            },succResult=>{
                                console.log(succResult);
                            },failResult=>{
                                console.log(failResult);
                            })
字段 说明
msgId 消息id
progressResult 下载进度
succResult 成功回调
failResult 失败回调

获取sound资源url

txIm.getSoundUrl({"msgId":msg.msgId},result=>{
                                console.log(result);
                            })
字段 说明
msgId 消息id
result 资源回调

获取视频资源url

txIm.getVideoUrl({"msgId":msg.msgId},result=>{
                                console.log(result);
                            })
字段 说明
msgId 消息id
result 资源回调

获取文件url

txIm.getFileUrl({"msgId":msg.msgId},result=>{
                                console.log(result);
                            })
字段 说明
msgId 消息id
result 资源回调

上传apple推送证书

txIm.setAPNS({businessId:23834},result=>{

                                                });
字段 说明
businessId 腾讯后台填写平台推送信息后获取的id
result 回调数据

上传安卓平台证书

txIm.setOfflinePushConfig({"businessId":11632,"token":""},result=>{
                                                    console.log(result);
                                                })
字段 说明
businessId 腾讯后台填写平台推送信息后获取的id
result 回调数据
token 使用tpns获取的token值

加强版函数新增

搜索本地消息

txIm.searchLocalMessages({"keywordList":["test"],"pageIndex":0,"pageSize":10},result=>{
                                                    console.log(result);
                                                })
字段 说明
keywordList 搜索关键字列表,最多支持5个,数组类型
messageTypeList 指定搜索的消息类型集合,不传表示搜索支持的全部类型消息,数组类型
conversationId 搜索“全部会话”还是搜索“指定的会话,不传“全部会话”
searchTimePosition 搜索的起始时间点。默认为0即代表从现在开始搜索
searchTimePeriod 从起始时间点开始的过去时间范围,单位秒。默认为0即代表不限制时间范围
pageIndex 用于分页展示查找结果,从零开始起步
pageSize 每页结果数量:用于分页展示查找结果,如不希望分页可将其设置成 0

置顶会话

txIm.pinConversation({"conversationId":"","isPinned":true},result=>{
                                                    console.log(result);
                                                })
字段 说明
conversationId 会话id
isPinned 是否置顶

创建转发消息

let messageOne = txIm.createTextMessage({textMsg:"test1"});
                let user = this.currentUser === this.user1 ? this.user2 : this.user1;
                txIm.sendMessage({"userId":user,"createMessageId":messageOne.createMessageId},result=>{
                    console.log(result);
                    let messageTwo = txIm.createForwardMessage({msgId:result.msgId});
                        txIm.sendMessage({"userId":user,"createMessageId":messageTwo.createMessageId},result=>{
                        console.log(result);
                    });

                });
字段 说明
msgId 消息id

创建合并消息

                var that = this;
                var messageIdList = [];
                let messageOne = txIm.createTextMessage({textMsg:"test1"});
                let user = this.currentUser === this.user1 ? this.user2 : this.user1;
                txIm.sendMessage({"userId":user,"createMessageId":messageOne.createMessageId},result=>{
                    console.log(result);
                    messageIdList.push(result.msgId);
                    let messageTwo = txIm.createTextMessage({textMsg:"test2"});
                    txIm.sendMessage({"userId":user,"createMessageId":messageTwo.createMessageId},result=>{
                        console.log(result);
                        messageIdList.push(result.msgId);
                        let messageMerger = txIm.createMergerMessage({"msgIdList":messageIdList,"abstractList":["testone","testtwo"],"title":"title","compatibleText":"compatibleText"});
                        txIm.sendMessage({"userId":user,"createMessageId":messageMerger.createMessageId},result=>{
                            console.log(result);
                            txIm.downloadMergerMessage({msgId:result.msgId},result=>{
                                console.log(result);
                            });
                        })
                    });

                })  
字段 说明
msgIdList 消息id列表
title 合并消息的来源
abstractList 合并消息的摘要列表(最大支持 5 条摘要,每条摘要的最大长度不超过 100 个字符)
compatibleText 合并消息兼容文本,低版本 SDK 如果不支持合并消息,默认会收到一条文本消息,文本消息的内容为 compatibleText

下载合并消息

txIm.downloadMergerMessage({msgId:result.msgId},result=>{
                                console.log(result);
                            });
字段 说明
msgId 消息id

搜索朋友

txIm.searchFriends({
                    "keywordList":["userId"],
                },result=>{
                    console.log(result);
                })
字段 说明
keywordList 搜索关键字列表,最多支持5个,数组类型
isSearchUserId 设置是否搜索 userID bool类型
isSearchNickName 是否设置搜索昵称 bool类型
isSearchRemark 是否设置搜索备注 bool类型

搜索群成员

txIm.searchGroupMembers({"keywordList":["groupMember"]},result=>{
                })
字段 说明
keywordList 搜索关键字列表,最多支持5个,数组类型
groupIdList 指定群 ID 列表,若不指定则搜索全部群中的群成员
isSearchMemberUserId 设置是否搜索群成员 userID bool类型
isSearchMemberNickName 设置是否搜索群成员昵称
isSearchMemberRemark 设置是否搜索群成员备注
isSearchMemberNameCard 设置是否搜索群成员名片

查找消息

txIm.findMessages({"msgIdList":[""]},result=>{})
字段 说明
msgIdList 消息id的字符串列表

获取ios的token

let token = txIm.getPushToken();

隐私、权限声明

1. 本插件需要申请的系统权限列表:

NSCameraUsageDescription NSMicrophoneUsageDescription android.permission.RECORD_AUDIO android.permission.CAMERA

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件使用腾讯云sdk采集数据,详情参考: https://cloud.tencent.com/product/trtc 插件使用腾讯云IM sdk ,详情见文档:https://cloud.tencent.com/document/product/269

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问