Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rtc-detect

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rtc-detect

rtc-detect

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
341
decreased by-32.34%
Maintainers
1
Weekly downloads
 
Created
Source

探测环境插件

rtc-detect 用来检测当前环境对 TRTC SDK 的支持度。

安装

npm install rtc-detect

使用方法

import RTCDetect from 'rtc-detect';
// 初始化监测模块
const detect = new RTCDetect();
// 获得当前环境监测结果
const result = await detect.getReportAsync();
console.log('result is: ' + result);

API

(async) isTRTCSupported()

判断当前环境是否支持 TRTC。

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}.`)
}

getSystem()

获取当前系统环境参数。

ItemTypeDescription
UAstring浏览器的 ua
OSstring当前设备的系统型号
browserobject当前浏览器信息{ name, version }
displayResolutionobject当前分辨率 { width, height }
getHardwareConcurrencynumber当前设备 CPU 核心数
const detect = new RTCDetect();
const result = detect.getSystem();

getAPISupported()

获取当前环境 API 支持度。

ItemTypeDescription
isUserMediaSupportedboolean是否支持获取用户媒体数据流
isWebRTCSupportedboolean是否支持 WebRTC
isWebSocketSupportedboolean是否支持 WebSocket
isWebAudioSupportedboolean是否支持 WebAudio
isScreenCaptureAPISupportedboolean是否支持获取屏幕的流
isCanvasCapturingSupportedboolean是否支持从 canvas 获取数据流
isVideoCapturingSupportedboolean是否支持从 video 获取数据流
isRTPSenderReplaceTracksSupportedboolean是否支持替换 track 时不和 peerConnection 重新协商
isApplyConstraintsSupportedboolean是否支持变更摄像头的分辨率不通过重新调用 getUserMedia
const detect = new RTCDetect();
const result = detect.getAPISupported();

(async) getDevicesAsync()

获取当前环境可用的设备。

ItemTypeDescription
hasWebCamPermissionsboolean是否支持获取用户摄像头数据
hasMicrophonePermissionboolean是否支持获取用户麦克风数据
camerasarray用户的摄像头设备列表,包含支持视频流的最大宽高和帧率
microphonesarray用户的麦克风设备列表
speakersarray用户的扬声器设备列表
const detect = new RTCDetect();
const result = await detect.getDevicesAsync();

(async) getCodecAsync()

获取当前环境参数对编码的支持度。

ItemTypeDescription
isH264EncodeSupportedboolean是否支持 h264 上行
isH264DecodeSupportedboolean是否支持 h264 下行
isVp8EncodeSupportedboolean是否支持 vp8 上行
isVp8DecodeSupportedboolean是否支持 vp8 下行
const detect = new RTCDetect();
const result = await detect.getCodecAsync();

(async) getReportAsync()

获取当前环境监测报告。

ItemTypeDescription
systemobject和 getSystem() 的返回值一致
APISupportedobject和 getAPISupported() 的返回值一致
codecsSupportedobject和 getCodecAsync() 的返回值一致
devicesobject和 getDevicesAsync() 的返回值一致
const detect = new RTCDetect();
const result = await detect.getReportAsync();

(async) isHardWareAccelerationEnabled()

检测 Chrome 浏览器是否开启硬件加速。

注意:该接口的实现依赖于 WebRTC 原生接口,建议在 isTRTCSupported 检测支持后,再调用该接口进行检测。检测最长耗时 30s。经实测:

  1. 开启硬件加速的情况下,该接口在 Windows 耗时 2s 左右, Mac 需耗时 10s 左右。
  2. 关闭硬件加速的情况下,该接口在 Windows 和 Mac 耗时均为 30s。
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(`current browser does not support TRTC, reason: ${data.reason}.`)
}

Keywords

FAQs

Package last updated on 15 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc