Device Management API
Audio/video device enumeration, switching, and hot-plug handling.
API Reference
getCameraList()
Get the list of available camera devices.
Must be called after init(), otherwise returns TResultCode.NOT_INITIALIZED.
Returns: Promise<TResult<TDeviceInfo[]>>
getCurrentDeviceId()
Get the currently active device ID (synchronous).
与响应式 state.currentCameraId$ / currentMicId$ / currentSpeakerId$ 等价, Equivalent to the reactive state.currentCameraId$ / currentMicId$ / currentSpeakerId$; for one-shot reads when subscribing to a Signal isn't needed.
| Parameter | Type | Description |
|---|---|---|
| type | DeviceType | Microphone / Speaker) / Device type |
Returns: string | undefined
Example:
const camId = classroom.getCurrentDeviceId(DeviceType.Camera);
console.log('当前摄像头:', camId);getMicrophoneList()
Get the list of available microphone devices.
Must be called after init().
Returns: Promise<TResult<TDeviceInfo[]>>
getSpeakerList()
Get the list of available speaker devices.
Must be called after init().
Returns: Promise<TResult<TDeviceInfo[]>>
refreshDeviceLists()
Refresh all device lists (enumerates camera / microphone / speaker simultaneously).
使用场景:用户插拔了 USB 摄像头/耳机后主动调用,或在系统级设备变更事件后刷新。 SDK 内部已订阅 navigator.mediaDevices.devicechange,正常情况下会自动刷新; Use case: actively call after the user hot-plugs a USB camera/headset, or to refresh after a system-level device change event. The SDK already subscribes to navigator.mediaDevices.devicechange and refreshes automatically — use this to force-refresh on demand.
Refresh results are pushed via state.cameraList$ / micList$ / speakerList$.
Returns: Promise<TResult<void>>
Example:
// 用户点击"刷新设备"按钮 / User clicks "Refresh devices"
await classroom.refreshDeviceLists();
const cams = classroom.state.cameraList$.get();switchDevice()
Switch to the specified device (supports hot-switching during streaming without interruption).
| Parameter | Type | Description |
|---|---|---|
| type | DeviceType | Microphone / Speaker) / Device type (Camera / Microphone / Speaker) |
| deviceId | string | Target device ID |
Returns: Promise<TResult<void>>
Example:
// 切换摄像头 / Switch camera
const cams = await classroom.getCameraList();
if (cams.ok) await classroom.switchDevice(DeviceType.Camera, cams.data[1].deviceId);
// 切换麦克风 / Switch microphone
const mics = await classroom.getMicrophoneList();
if (mics.ok) await classroom.switchDevice(DeviceType.Microphone, mics.data[0].deviceId);