3.0.1 • Published 4 days ago
dingrtc v3.0.1
Aliyun WebRtc SDK
阿里云音视频通信dingRtc,提供基于WebRTC适用于浏览器的SDK。
Installation
You can install it as dependency with npm/cnpm or yarn.
$ # save into package.json dependencies with -S
$ npm install dingrtc -S
$ # you can use cnpm for fast install
$ cnpm install dingrtc -S
$ # use yarn for install
$ yarn add dingrtc
一、接入前准备
阿里云RTC提供移动端、PC等多端SDK,并兼容标准WebRTC浏览器接入网络,帮助您快速搭建多端实时应用。接入RTC的方法,请参见接口文档。 当您成功搭建本地SDK,可以在终端调用API与RTC服务端进行交互,在加入频道或房间后,您可以进行本地推流、订阅远端用户等操作,实现频道内不同用户之间的音视频实时通话。 阿里云RTC拥有全球实时智能调度系统,并结合实时媒体处理系统和1500+边缘节点,运用行业领先的音频3A(AGC、AEC、ANS)、视频编码、弱网对抗等算法为您提供低延时、抗丢包的音视频实时通信。
二、快速开启
- 创建实例
import RtcEngine from 'dingrtc'
/**
* 创建客户端实例
*/
const client = RtcEngine.createClient();
- 检测浏览器是否支持webrtc
const supported = RtcEngine.checkSystemRequirements();
if (supported) {
//支持webrtc
} else {
//不支持webrtc
}
- 订阅user-published回调。当远程用户推流时,在SDK里会触发user-published回调,通过订阅这个回调,能够得到频道里已经推流的用户。
client.on('user-published',(user, mediaType) =>{
//远程发布者userId
console.log(user.userId);
//远程发布轨道类型
console.log(mediaType);
});
- 加入频道
client.join({
uid, // 用户ID,只能由数字、字母、下划线组成
channel, // 频道
appId, // 应用ID
token, // 令牌
userName, // 用户名
}).then(()=>{
// 入会成功
}).catch((error)=>{
// 入会失败,打印错误内容,可以看到失败原因
console.log(error.message);
});
- 采集摄像头
const cameraTrack = await RtcEngine.createCameraVideoTrack({
frameRate: 15,
dimension: 'VD_1280x720',
})
- 采集麦克风
const micTrack = await RtcEngine.createMicrophoneAudioTrack()
- 推流
await client.publish([cameraTrack, micTrack]);
- 订阅和显示远程流。通过subscribe方法订阅远程流,订阅成功后在调用track.play显示远程流。
通常在user-published回调中进行订阅与设置视图。
client.subscribe(userId, 'video').then((track)=>{
track.play(`#${userId}`)
}).catch((error)=>{
console.log(error.message);
});
- 离开频道。
client.leave().catch((error)=>{
console.log(error.message);
});
3.0.1
4 days ago
3.0.0
25 days ago
3.0.0-beta.14
1 month ago
3.0.0-beta.12
1 month ago
3.0.0-beta.13
1 month ago
3.0.0-beta.11
1 month ago
3.0.0-beta.10
1 month ago
3.0.0-beta.9
1 month ago
3.0.0-beta.8
1 month ago
3.0.0-beta.7
1 month ago
3.0.0-beta.6
2 months ago
3.0.0-beta.5
2 months ago
3.0.0-beta.4
2 months ago
3.0.0-beta.3
2 months ago
3.0.0-beta.2
2 months ago
3.0.0-beta.1
3 months ago
3.0.0-beta.0
3 months ago