首页 技术 正文
技术 2022年11月9日
0 收藏 435 点赞 4,505 浏览 2478 个字

 前言:

  公司的产品是一款基于社交的内容聊天软件,需要集成语音通讯功能,在写iOS原生项目时,用到的就是Agora SDK,现在写React Native也直接采用了Agora的库。

 集成iOS、Android的步骤:

  请参考链接:https://github.com/syanbo/react-native-agora

  提示:因为Agora的库有两个版本,必须采用最新版,以免有些功能不支持(笔者在集成时,当时没有注意,有不少折腾呢)

 使用记录:

  不知道怎么开头写的时候,参考官方Demo : https://github.com/agoraio-community/agora-rn-quickstart

  1、主要功能代码:

configureAgora(){
var that = this;
const config = {
appid: "17423c8***********5cd46f89e",
channelProfile: this.props.channelProfile,
clientRole: this.props.clientRole,
audioProfile: AudioProfileMusicHighQuality,
audioScenario: AudioScenarioChatRoomGaming,
} console.log("[CONFIG]", JSON.stringify(config));
console.log("[CONFIG.encoderConfig", config.videoEncoderConfig);
RtcEngine.on('videoSizeChanged', (data) => {
console.log("[RtcEngine] videoSizeChanged ", data)
})
RtcEngine.on('remoteVideoStateChanged', (data) => {
console.log('[RtcEngine] `remoteVideoStateChanged`', data);
})
RtcEngine.on('userJoined', (data) => { //用户加入 })
RtcEngine.on('userOffline', (data) => {//用户下线 })
RtcEngine.on('audioVolumeIndication', (data) => {
console.log(data);
})
RtcEngine.on('clientRoleChanged', (data) => {
console.log("[RtcEngine] onClientRoleChanged", data);
})
RtcEngine.on('joinChannelSuccess', (data) => {
console.log('[RtcEngine] onJoinChannelSuccess', data);
// console.log(RtcEngine.options);
RtcEngine.startPreview().then(data => {
// this.setState({
// joinSucceed: true,
// animating: false
// }) })
// RtcEngine.setEnableSpeakerphone(true)
// RtcEngine.setDefaultMuteAllRemoteAudioStreams(true) global.channel = data.channel
global.voiceStatus = 'join'; }) RtcEngine.init(config);
RtcEngine.enableAudio()
}

  2、加入频道

RtcEngine.joinChannel(this.props.childTribeId,Parse.User.current().attributes.uid,"","")
.then(result => { });

  3、退出频道

RtcEngine.leaveChannel((status)=>{
console.log(status) })

  4、当有人加入或退出时,播放提示音

  提示:

  1、在以下代码中filepath:为绝对路径或url,不能使用相对路径

  2、soundid是正确的,如果直接粘贴demo,会出错误(Demo中是:soundId)

RtcEngine.on('userJoined', (data) => { //用户加入
console.log('[RtcEngine] onUserJoined', data);
let playEffectOption = {
soundid: 1,
filepath:'https://oops-*****.cos.ap-shanghai.myqcloud.com/in.mp3',
loopcount: 0,
pitch: 1,
pan: 0,
gain: 40,
publish: false,
};
RtcEngine.playEffect(playEffectOption)
// const {peerIds} = this.state;
// if (peerIds.indexOf(data.uid) === -1) {
// this.setState({
// peerIds: [...peerIds, data.uid]
// })
// }
})
RtcEngine.on('userOffline', (data) => {//用户下线
console.log('[RtcEngine] onUserOffline', data);
let playEffectOption = {
soundid: 2,
filepath:'https://oops-*****.cos.ap-shanghai.myqcloud.com/in.mp3',
loopcount: 0,
pitch: 1,
pan: 0,
gain: 40,
publish: false,
}; RtcEngine.playEffect(playEffectOption)
})
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905