Skip to content

静态方法

AliRtcEngine 提供了一系列静态方法,可以在不创建实例的情况下直接调用。

isSupported

检查浏览器是否支持 WebRTC。

方法签名

typescript
static isSupported(direction?: "sendonly" | "recvonly" | "sendrecv"): Promise<AliRtcCheckResult>

参数

  • direction (可选): 指定检查方向
    • "sendonly": 仅发送
    • "recvonly": 仅接收
    • "sendrecv": 双向收发

返回值

  • Promise<AliRtcCheckResult>: 浏览器支持情况检查结果

AliRtcCheckResult 接口

typescript
interface AliRtcCheckResult {
  support: boolean;          // 是否支持
  detail: {
    isWebRTCSupported: boolean;              // 是否支持 WebRTC
    isH264EncodeSupported: boolean;          // 是否支持 H264 编码
    isH264DecodeSupported: boolean;          // 是否支持 H264 解码
    isBrowserSupported: boolean;             // 浏览器是否支持
    isScreenShareSupported: boolean;         // 是否支持屏幕共享
    isSendMediaExtensionMsgSupported: boolean; // 是否支持发送媒体扩展消息
  };
}

示例

javascript
const result = await AliRtcEngine.isSupported('sendrecv');
console.log('WebRTC 支持情况:', result);
if (result.support) {
  console.log('当前浏览器支持 WebRTC');
} else {
  console.log('当前浏览器不支持 WebRTC');
}

getInstance

获取 AliRtcEngine 实例(单例模式)。

方法签名

typescript
static getInstance(config?: AliRtcEngineConfig): AliRtcEngine

参数

  • config (可选): 引擎配置参数

返回值

  • AliRtcEngine: AliRtcEngine 实例

详细说明 该方法为同步调用,以单例的形式提供对象创建。

示例

javascript
// 获取默认配置的实例
const engine = AliRtcEngine.getInstance();

// 使用自定义配置获取实例
const customEngine = AliRtcEngine.getInstance({
  // 自定义配置项
});

getCameraList

获取摄像头设备列表。

方法签名

typescript
static getCameraList(): Promise<MediaDeviceInfo[]>

返回值

  • Promise<MediaDeviceInfo[]>: 摄像头设备信息列表

示例

javascript
const cameras = await AliRtcEngine.getCameraList();
console.log('可用摄像头:', cameras);
cameras.forEach(camera => {
  console.log(`设备ID: ${camera.deviceId}, 设备名称: ${camera.label}`);
});

getMicrophoneList

获取麦克风设备列表。

方法签名

typescript
static getMicrophoneList(): Promise<MediaDeviceInfo[]>

返回值

  • Promise<MediaDeviceInfo[]>: 麦克风设备信息列表

示例

javascript
const microphones = await AliRtcEngine.getMicrophoneList();
console.log('可用麦克风:', microphones);
microphones.forEach(mic => {
  console.log(`设备ID: ${mic.deviceId}, 设备名称: ${mic.label}`);
});

getSpeakerList

获取扬声器设备列表。

方法签名

typescript
static getSpeakerList(): Promise<MediaDeviceInfo[]>

返回值

  • Promise<MediaDeviceInfo[]>: 扬声器设备信息列表

示例

javascript
const speakers = await AliRtcEngine.getSpeakerList();
console.log('可用扬声器:', speakers);
speakers.forEach(speaker => {
  console.log(`设备ID: ${speaker.deviceId}, 设备名称: ${speaker.label}`);
});

getSdkVersion

获取 SDK 版本号。

方法签名

typescript
static getSdkVersion(): string

返回值

  • string: SDK 版本号字符串

示例

javascript
const version = AliRtcEngine.getSdkVersion();
console.log('SDK 版本:', version);

setLogLevel

设置日志输出等级。

方法签名

typescript
static setLogLevel(level: AliRtcLogLevel): void

参数

  • level: 日志等级,详见 AliRtcLogLevel 枚举

示例

javascript
// 设置日志等级为调试模式
AliRtcEngine.setLogLevel(AliRtcEngine.AliRtcLogLevel.AliRtcLogLevelDebug);

isDualVideoStreamSupported

检查浏览器是否支持开启大小流。

方法签名

typescript
static isDualVideoStreamSupported(): boolean

返回值

  • boolean:
    • true: 支持大小流
    • false: 不支持大小流

示例

javascript
const supported = AliRtcEngine.isDualVideoStreamSupported();
if (supported) {
  console.log('浏览器支持大小流');
}