@avaya/infinity-agent-sdk - v1.0.0
    Preparing search index...

    Audio Device Management

    This guide covers managing the agent's audio hardware - checking microphone permission, listing available input and output devices, switching the active selection, and reacting to hot-plugging changes throughout the session.

    Personas: Agent, Supervisor - anyone on a voice call selects and manages their input and output audio devices.

    The SDK exposes audio device management through User, and it is relevant for any session that includes voice calls. The browser must grant microphone access before device enumeration is meaningful - User.getAudioDevicePermissionState lets you gate the device picker on permission state. Once permission is granted, User.getAvailableAudioDevices returns the full list and User.setAudioInputDevice / User.setAudioOutputDevice switch the active devices.

    Devices can be added or removed at any time (headsets plugged in or unplugged). Subscribe to UserEventType.AUDIO_DEVICES_CHANGED to refresh the picker whenever the device list changes, and to the permission events to react to browser-level changes.

    Check permission state before prompting the browser - avoid triggering an unexpected permission popup on page load:

    const state = user.getAudioDevicePermissionState();

    if (state === MediaDevicePermissionState.GRANTED) {
    const devices = await user.getAvailableAudioDevices();
    populateDevicePicker(devices);
    } else if (state === MediaDevicePermissionState.DENIED) {
    showMicPermissionError();
    } else {
    showRequestPermissionButton();
    }

    // React when permission is granted or denied at runtime
    user.subscribe(UserEventType.AUDIO_DEVICE_PERMISSION_GRANTED, async () => {
    const devices = await user.getAvailableAudioDevices();
    populateDevicePicker(devices);
    });

    user.subscribe(UserEventType.AUDIO_DEVICE_PERMISSION_DENIED, () => {
    showMicPermissionError();
    });

    User.getAvailableAudioDevices returns an AvailableAudioDevices object with inputDevices ( AudioInputDevice[]) and outputDevices ( AudioOutputDevice[]). The currently active selection is available via User.getSelectedAudioDevices.

    Switching is synchronous - User.setAudioInputDevice and User.setAudioOutputDevice take a deviceId string and return void:

    const devices = await user.getAvailableAudioDevices();
    const selected = user.getSelectedAudioDevices();

    // Populate pickers (use selected.inputDevice / selected.outputDevice for the current value)
    populatePicker("input", devices.inputDevices, selected.inputDevice);
    populatePicker("output", devices.outputDevices, selected.outputDevice);

    // Switch on agent selection (gate on capability check first)
    function onInputChange(deviceId: string) {
    if (user.canSetAudioInputDevice()) {
    user.setAudioInputDevice(deviceId);
    }
    }

    function onOutputChange(deviceId: string) {
    if (user.canSetAudioOutputDevice()) {
    user.setAudioOutputDevice(deviceId);
    }
    }

    When a headset is plugged in or unplugged mid-session, UserEventType.AUDIO_DEVICES_CHANGED fires with a fresh list of devices. Refresh the picker and verify the selected device is still available:

    user.subscribe(UserEventType.AUDIO_DEVICES_CHANGED, (event) => {
    const { available, selected } = event.payload;
    refreshDevicePicker(available, selected);
    });

    user.subscribe(UserEventType.NO_AUDIO_DEVICE_AVAILABLE, (event) => {
    showMissingDeviceWarning(event.payload.missingDeviceKinds);
    });

    User.getWebRtcRegistrationState reflects whether the voice endpoint is registered and ready to place or receive calls. Surface this as a "Voice Ready" indicator separate from the device picker - a device can be selected but the WebRTC stack may still be registering:

    import { WebRtcRegistrationState } from "@avaya/infinity-agent-sdk";

    const registered = user.getWebRtcRegistrationState() === WebRtcRegistrationState.REGISTERED;
    updateVoiceReadyIndicator(registered);

    Subscribe to WebRtcRegistrationEventType events (via AvayaInfinityAgentSdk.subscribe) to react to registration state changes throughout the session.

    Failures surface as typed AvayaInfinityAgentSdkErrors with stable codes from AvayaInfinityAgentSdkErrorCodes. Errors on the audio device path span the ASE_2xxx and ASE_4xxx families - match error.code against AvayaInfinityAgentSdkErrorCodes to identify the specific failure.