tencent cloud

Feedback

TUIDeviceManager

Last updated: 2024-09-10 15:30:52

    Introduction

    TUIDeviceManager is an multimedia device manager used to manage audio and video-related hardware devices such as cameras, microphones, and speakers.
    Installation
    // npm
    npm i @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3 --save
    
    // pnpm
    pnpm i @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3 --save
    
    // yarn
    yarn add @tencentcloud/tuiroom-engine-electron@2.4.0-alpha.3
    
    Example code
    import TUIRoomEngine, {
    TUIDeviceManager, TUIDeviceInfo
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const cameraList: Array<TUIDeviceInfo> = deviceManager.getCameraDevicesList();

    API

    Method
    Description
    Get the list of camera devices
    Get the list of microphone devices
    Get the list of speaker devices
    Set the current device
    Get the current device
    Set the volume of the current device
    Get the volume of the current device
    Mute the current device
    Get the mute status of the current device
    Enable system device following
    Start microphone test
    Stop microphone test
    Start speaker test
    Stop speaker test
    Start camera test
    Stop camera test
    Enable mirror during camera test
    Set the camera device during camera test
    Set the capture resolution of the camera during the test
    Set the video preprocessing plugin library file path during camera test
    Set video preprocessing parameters during camera test
    on
    Register event listener
    off
    Unregister event listener

    Type Definitions

    Type
    Description
    Camera capture parameters
    Audio and video device information
    TUIRect
    Rectangular coordinate area

    Enumerations

    Enum
    Description
    Camera capture mode
    Audio and video device event type
    Audio and video device state
    Audio and video device type

    API explaination

    getCameraDevicesList

    Get camera devices
    import TUIRoomEngine, {
    TUIDeviceManager, TUIDeviceInfo
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const cameraList: Array<TUIDeviceInfo> = deviceManager.getCameraDevicesList();
    Parameters None
    Return Array<TUIDeviceInfo>

    getMicDevicesList

    Get microphone devices
    import TUIRoomEngine, {
    TUIDeviceManager, TUIDeviceInfo
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const cameraList: Array<TUIDeviceInfo> = deviceManager.getMicDevicesList();
    Parameters None
    Return Array<TUIDeviceInfo>

    getSpeakerDevicesList

    Get speaker devices
    import TUIRoomEngine, {
    TUIDeviceManager, TUIDeviceInfo
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const cameraList: Array<TUIDeviceInfo> = deviceManager.getSpeakerDevicesList();
    Parameters None
    Return Array<TUIDeviceInfo>

    setCurrentDevice

    Set current device of specified media device type
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCurrentDevice(TUIMediaDeviceType.kMediaDeviceTypeAudioOutput, 'Your speaker ID');
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    type
    -
    -
    Device type
    deviceId
    string
    -
    -
    Device ID
    Return Promise<void>

    getCurrentDevice

    Get current device
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const currentSpeaker:TUIDeviceInfo = await deviceManager.getCurrentDevice(TUIMediaDeviceType.kMediaDeviceTypeAudioOutput);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    type
    -
    -
    Device type
    Return Promise<TUIDeviceInfo>

    setCurrentDeviceVolume

    Set volume of current microphone or speaker.
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCurrentDeviceVolume(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, value);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    type
    -
    -
    Device type. Only for microphone and speaker
    volume
    number
    [0-100]
    60
    Volume, range: 0 - 100
    Return Promise<void>

    getCurrentDeviceVolume

    Get volumne of current microphone or speaker device
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const currentMicVolume = await deviceManager.getCurrentDeviceVolume(TUIMediaDeviceType.kMediaDeviceTypeAudioInput);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    type
    -
    -
    Device type
    Return Promise<number>

    setCurrentDeviceMute

    Mute current device. Only work for microphone and speaker.
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCurrentDeviceMute(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, true);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    type
    -
    -
    Device type
    mute
    boolean
    -
    -
    Whether to mute or not
    Return Promise<void>

    getCurrentDeviceMute

    Check whether current microphone or speaker is muted.
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const isCurrentMicMuted = await deviceManager.getCurrentDeviceMute(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, true);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    type
    -
    -
    Device type
    Return Promise<boolean>

    enableFollowingDefaultAudioDevice

    Enable System Device Following
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.enableFollowingDefaultAudioDevice(TUIMediaDeviceType.kMediaDeviceTypeAudioInput, true);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    type
    -
    -
    Device type
    enable
    boolean
    -
    -
    Whether to follow the system's default audio device
    Return Promise<void>

    startMicDeviceTest

    Start test current or system default microphone device.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.startMicDeviceTest(300, true);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    interval
    number
    -
    -
    Microphone volume callback interval, unit: milliseconds.
    playback
    boolean
    -
    -
    Whether to enable microphone sound playback. After enabling, the user will hear their own voice when testing the microphone. If the playback parameter is not passed, it defaults to false.
    Return Promise<void>

    stopMicDeviceTest

    Stop microphone device test.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.stopMicDeviceTest();
    Parameters None
    Return Promise<void>

    startSpeakerDeviceTest

    Start test current or system default speaker device.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const audioFilePath = '';
    deviceManager.startSpeakerDeviceTest(audioFilePath);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    filePath
    string
    Valid audio file path
    -
    Audio file path used to test speaker.
    Return Promise<void>

    stopSpeakerDeviceTest

    Stop speaker device test.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.stopSpeakerDeviceTest();
    Parameters None
    Return Promise<void>

    startCameraDeviceTest

    Start camera device test.
    import TUIRoomEngine, {
    TUIDeviceManager, TUIRect
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const rect: TUIRect = {
    left: 100,
    top: 50,
    right: 740,
    bottom: 410,
    };
    const windowID: Uint8Array; // Get by Electron API BrowserWindow.getNativeWindowHandle()
    deviceManager.startCameraDeviceTest(windowID, rect);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    windowID
    Uint8Array
    -
    -
    Window ID, got by Electron API BrowserWindow.getNativeWindowHandle(), to preview camera.
    rect
    TUIRect
    -
    -
    The position area used to display camera video in the window.
    Return Promise<void>

    stopCameraDeviceTest

    Stop camera device test.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.stopCameraDeviceTest();
    Parameters None
    Return Promise<void>

    setCameraTestRenderMirror

    Enable or disable video mirror when test camera.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCameraTestRenderMirror(true);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    mirror
    boolean
    -
    -
    Whether to enable mirroring
    Return Promise<void>

    setCameraTestDeviceId

    Set the camera device ID used to test.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCameraTestDeviceId('Your camera ID');
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    cameraId
    string
    -
    -
    Camera device ID
    Return Promise<void>

    setCameraTestResolution

    Set video resolution when camera test.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCameraTestResolution(1920, 1080);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    width
    number
    -
    -
    Camera capture width
    height
    number
    -
    -
    Camera capture height
    Return Promise<void>

    setCameraTestVideoPluginPath

    Set custom video preprocess dynamic library path when camera test.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCameraTestVideoPluginPath('Your library path');
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    path
    string
    -
    -
    Video preprocess dynamic library path
    Return Promise<void>

    setCameraTestVideoPluginParameter

    Set video preprocess parameter when camera test.
    import TUIRoomEngine, {
    TUIDeviceManager
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    deviceManager.setCameraTestVideoPluginParameter('{}'); // JSON string
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    params
    string
    -
    -
    JSON parameter string
    Return Promise<void>

    on

    Register event listener
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType, TUIMediaDeviceState
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const onDeviceChanged = (deviceId: string, type: TUIMediaDeviceType, state: TUIMediaDeviceState) => {
    // ...
    }
    deviceManager.on(TUIMediaDeviceEventType.onDeviceChanged, onDeviceChanged);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    eventName
    -
    -
    Event name
    func
    (...args: any[]) => void
    -
    -
    Event handler function
    Return Promise<void>

    off

    Unregister event listener
    import TUIRoomEngine, {
    TUIDeviceManager, TUIMediaDeviceType, TUIMediaDeviceState
    } from '@tencentcloud/tuiroom-engine-electron';
    
    const deviceManager:TUIDeviceManager = TUIRoomEngine.getDeviceManager();
    const onDeviceChanged = (deviceId: string, type: TUIMediaDeviceType, state: TUIMediaDeviceState) => {
    // ...
    }
    deviceManager.off(TUIMediaDeviceEventType.onDeviceChanged, onDeviceChanged);
    Parameters
    Parameter
    Type
    Validation
    Default value
    Description
    eventName
    -
    -
    Event name
    func
    (...args: any[]) => void
    -
    -
    Event handler function
    Return Promise<void>

    Type explaination

    TUICameraCaptureParam

    Camera capture parameter
    Field
    Type
    Description
    mode
    Camera capture mode
    width
    number
    Camera capture width
    height
    number
    Camera capture height

    TUIDeviceInfo

    Media device information
    Field
    Type
    Description
    deviceId
    string
    Device ID
    deviceName
    string
    Device Name
    deviceProperties
    Record<string, any>
    Device properties. Only cameras supported, including the capture resolutions supported by the camera.

    TUIRect

    Rectangular coordinate area
    Field
    Type
    Description
    left
    number
    Left line coordinate
    top
    number
    Top line coordinate
    right
    number
    Right line coordinate
    bottom
    number
    Bottom line coordinate

    Enumerations explaination

    TUICameraCaptureMode

    Camera capture mode
    Enumeration item
    Type
    Description
    kCameraResolutionStrategyAuto
    number
    Automatically adjust capture parameters. The SDK selects appropriate camera output parameters based on the actual performance of the capture device and network conditions, maintaining a balance between device performance and video preview quality.
    kCameraResolutionStrategyPerformance
    number
    Priority on device performance. The SDK selects the closest camera output parameters based on the user's settings for encoder resolution and frame rate, thereby ensuring device performance.
    kCameraResolutionStrategyHighQuality
    number
    Priority on video preview quality. The SDK selects higher camera output parameters to improve the quality of the preview video. In this case, more CPU and memory will be consumed for video preprocessing.
    kCameraCaptureManual
    number
    Allows users to set the local camera capture video width and height.

    TUIMediaDeviceEventType

    Media device events
    Enumeration item
    Type
    Value
    Description
    string
    'onDeviceChanged'
    Device state change event name

    TUIMediaDeviceState

    Media device status.
    Enumeration item
    Type
    Value
    Description
    kMediaDeviceStateAdd
    number
    0
    New device added
    kMediaDeviceStateRemove
    number
    1
    Device removed
    kMediaDeviceStateActive
    number
    2
    Device activated
    kMediaDefaultDeviceChanged
    number
    3
    System default device changed

    TUIMediaDeviceType

    Media device type
    Enumeration item
    Type
    Value
    Description
    kMediaDeviceTypeUnknown
    number
    -1
    Unkonw media
    kMediaDeviceTypeAudioInput
    number
    0
    Microphone
    kMediaDeviceTypeAudioOutput
    number
    1
    Speaker
    kMediaDeviceTypeVideoCamera
    number
    2
    Camera

    Events

    onDeviceChanged

    Device state change event
    Paramter
    Type
    Description
    deviceID
    string
    Device ID
    type
    Device type
    state
    Device state
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support