rtc-detect
npm install rtc-detectrtc-detect 用于检测当前环境在由 TRTC SDK 构建的 WebRTC 应用程序中是否工作顺利。
    
简体中文 | English
shell
npm install rtc-detect
`使用方法
`javascript
import RTCDetect from 'rtc-detect';
// 初始化监测模块
const detect = new RTCDetect();
// 获得当前环境监测结果
const result = await detect.getReportAsync();
console.log('result is: ' + result);
`API
$3
判断当前环境是否支持 TRTC。
`javascript
const detect = new RTCDetect();
const data = await detect.isTRTCSupported();if (data.result) {
console.log('current browser supports TRTC.')
} else {
console.log(
current browser does not support TRTC, reason: ${data.reason}.)
}
`
$3
获取当前系统环境参数。| Item | Type | Description |
| ----------------- | ------ | ---------------------------- |
| UA | string | 浏览器的 ua |
| OS | string | 当前设备的系统型号 |
| browser | object | 当前浏览器信息{ name, version } |
| displayResolution | object | 当前分辨率 { width, height } |
| getHardwareConcurrency | number | 当前设备 CPU 核心数 |
`javascript
const detect = new RTCDetect();
const result = detect.getSystem();
`$3
获取当前环境 API 支持度。| Item | Type | Description |
| --------------------------------- | ------- | ---------------------- |
| isUserMediaSupported | boolean | 是否支持获取用户媒体数据流 |
| isWebRTCSupported | boolean | 是否支持 WebRTC |
| isWebSocketSupported | boolean | 是否支持 WebSocket |
| isWebAudioSupported | boolean | 是否支持 WebAudio |
| isScreenCaptureAPISupported | boolean | 是否支持获取屏幕的流 |
| isCanvasCapturingSupported | boolean | 是否支持从 canvas 获取数据流 |
| isVideoCapturingSupported | boolean | 是否支持从 video 获取数据流 |
| isRTPSenderReplaceTracksSupported | boolean | 是否支持替换 track 时不和 peerConnection 重新协商 |
| isApplyConstraintsSupported | boolean | 是否支持变更摄像头的分辨率不通过重新调用 getUserMedia |
`javascript
const detect = new RTCDetect();
const result = detect.getAPISupported();
`
$3
获取当前环境可用的设备。
| Item | Type | Description |
|-------------------------|---------------------|----------------------------------------------------|
| hasWebCamPermissions | boolean | 是否支持获取用户摄像头数据 |
| hasMicrophonePermission | boolean | 是否支持获取用户麦克风数据 |
| cameras | array | 用户的摄像头设备列表,包含摄像头支持的分辨率信息,最大宽高以及最大帧率(最大帧率有部分浏览器不支持) |
| microphones | array | 用户的麦克风设备列表 |
| speakers | array | 用户的扬声器设备列表 |
CameraItem
| Item | Type | Description |
|------------|---------|----------------------------------------------------------------------|
| deviceId | string | 设备 ID, 通常是唯一的,可以用于采集识别设备 |
| groupId | string | 组的标识符,如果两个设备属于同一个物理设备,他们就有相同的标识符 |
| kind | string | 摄像头设备类型:'videoinput' |
| label | string | 描述该设备的标签 |
| resolution | object | 摄像头支持的最大分辨率的宽高和帧率 {maxWidth: 1280, maxHeight: 720, maxFrameRate: 30} |
DeviceItem
| Item | Type | Description |
|----------|----------|--------------------------------------|
| deviceId | string | 设备 ID, 通常是唯一的,可以用于采集识别设备 |
| groupId | string | 组的标识符,如果两个设备属于同一个物理设备,他们就有相同的标识符 |
| kind | string | 设备类型,例如: 'audioinput', 'audiooutput' |
| label | string | 描述该设备的标签 |
`javascript
const detect = new RTCDetect();
const result = await detect.getDevicesAsync();
`$3
获取当前环境参数对编码的支持度。| Item | Type | Description |
|------------------------|----------|--------------|
| isH264EncodeSupported | boolean | 是否支持 h264 上行 |
| isH264DecodeSupported | boolean | 是否支持 h264 下行 |
| isVp8EncodeSupported | boolean | 是否支持 vp8 上行 |
| isVp8DecodeSupported | boolean | 是否支持 vp8 下行 |
| isVp9EncodeSupported | boolean | 是否支持 vp9 上行 |
| isVp9DecodeSupported | boolean | 是否支持 vp9 下行 |
| isH265EncodeSupported | boolean | 是否支持 h265 上行 |
| isH265DecodeSupported | boolean | 是否支持 h265 下行 |
| isAV1EncodeSupported | boolean | 是否支持 AV1 上行 |
| isAV1DecodeSupported | boolean | 是否支持 AV1 下行 |
`javascript
const detect = new RTCDetect();
const result = await detect.getCodecAsync();
`
$3
获取当前环境监测报告。| Item | Type | Description |
| -------------------- | ------- | -------------------------------- |
| system | object | 和 getSystem() 的返回值一致 |
| APISupported | object | 和 getAPISupported() 的返回值一致 |
| codecsSupported | object | 和 getCodecAsync() 的返回值一致 |
| devices | object | 和 getDevicesAsync() 的返回值一致 |
`javascript
const detect = new RTCDetect();
const result = await detect.getReportAsync();
`$3
检测 Chrome 浏览器是否开启硬件加速。
注意:该接口的实现依赖于 WebRTC 原生接口,建议在 isTRTCSupported 检测支持后,再调用该接口进行检测。检测最长耗时 30s。经实测:
1. 开启硬件加速的情况下,该接口在 Windows 耗时 2s 左右, Mac 需耗时 10s 左右。
2. 关闭硬件加速的情况下,该接口在 Windows 和 Mac 耗时均为 30s。
`javascript
const detect = new RTCDetect();
const data = await detect.isTRTCSupported();if (data.result) {
const result = await detect.isHardWareAccelerationEnabled();
console.log(
is hardware acceleration enabled: ${result});
} else {
console.log(hardware acceleration is disabled)
}
`Changelog
$3
Improvement
- 增加 VP9 编码格式检测
$3
Improvement
- 增加 H265 AV1 编码格式检测
- 增加 GPU 信息
$3
Improvement
- 优化某些特定 Android 设备上表现。
$3
Improvement
- 优化了 Windows 上的性能。
$3
Bug Fixed
- 修复了 Safari 上资源占用问题。
$3
Feature
- 从
getDevicesAsync() 获取的 camera 参数新增 maxFrameRate 参数,代表摄像头可以支持的最大帧率。$3
Improvement
- 新增检测不支持 WebRTC 时的原因提示
$3
Feature
- 新增
isHardWareAccelerationEnable()` 方法,检测 Chrome 浏览器是否开启硬件加速。Improvement
- 优化部分参数的命名
- 发布 rtc-detect@0.0.1