Agora声网-Uniapp拉流(Vue拉流)

/** 
 *  agora声网解决方案
 * 1. 创建 AgoraClient 对象
 * 2. join进入相应频道
 * 3. on 监听 user-published 拿到远端用户对象 AgoraRTCRemoteUser
 * 4. subscribe订阅流 将3.内的参数(远端用户对象, type('video'/'audio'))赋值给subscribe,拿到最新的远端用户信息
 * 5. 根绝监听 user-published 返回的type来分别处理音/视频
 *   video -> AgoraRTCRemoteUser.videoTrack.play(videoId 或者是 video的dom) 元素为 div
 *   user -> AgoraRTCRemoteUser.audioTrack.play()
 */

npm

npm install agora-rtc-sdk-ng --save

引入

import AgoraRTC from 'agora-rtc-sdk-ng'

创建AgoraClient对象

 const AgoraClient = AgoraRTC.createClient({
		mode: 'live', // 模式
    	codec: 'vp8', // 编码格式
	 	role: 'audience' // 角色
	 });

监听/订阅流

async initAgora() {
	await AgoraClient.join(this.appId, this.channel, this.token, null)
		  AgoraClient.on('user-published', async (user, type) => {
					// 开始订阅远端用户。
					let userData = await AgoraClient.subscribe(user, type)
					if (type === 'video') {
						// 这里的 id 可以是一个 div 盒子的 id 属性,也可以是一个 dom,但标签必须是 div
						userData.play(id)
						console.log('video订阅成功了')
					} else if (type === 'audio') {
						userData.play()
						console.log('audio订阅成功了')
					}

				})
			}

参考这位大佬和文档写出来的上面👆

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值