Appearance
Media Settings Panel Documentation
Overview
This component provides a user interface for managing media device settings in a video conferencing application. It allows users to select and configure their camera, microphone, and speaker devices, with real-time preview capabilities.
Key Features
Device Management:
- Camera selection and switching
- Microphone selection with audio level monitoring
- Speaker selection with test functionality
- Low frequency audio toggle for microphones
Real-time Feedback:
- Audio level visualization
- Speaker test with visual feedback
- Automatic device refresh when hardware changes
User Experience:
- Clean, organized interface
- Immediate application of settings
- Error handling for unsupported features
Component Structure
Module Context (Utility Functions)
typescript
export const openMediaDevices = async (constraints) => {
// Wrapper for getUserMedia
};
export async function getStream(audioSource?: string, videoSource?: string) {
// Gets media stream with specified devices
}
export async function attachSinkId(element: HTMLAudioElement, sinkId: string) {
// Sets audio output device
}
export async function getDevices() {
// Enumerates available media devices
}Props
typescript
export let selectedCamera: string; // Currently selected camera ID
export let selectedMic: string; // Currently selected microphone ID
export let selectedSpeaker: string; // Currently selected speaker ID
export let enableLowFrequencies: boolean; // Low frequency audio settingState Management
typescript
let speakerTestOn = false; // Speaker test active state
let speakerTestElement: HTMLAudioElement; // Audio element for speaker test
let localAudioStream: MediaStream; // Current microphone stream
let cameras = []; // Available video devices
let mics = []; // Available audio input devices
let speakers = []; // Available audio output devices
let isSupported; // Browser support flag
let error; // Error stateUI Components
Main Panel Structure
svelte
<aside class="bg-white h-full w-full border-l border-gray-200 flex flex-col">
<!-- Header -->
<div class="flex justify-between border-b p-2">
<span class="text-lg">Settings</span>
<button on:click={() => dispatch('close')}>
<Icon src={Close} size=20/>
</button>
</div>
<!-- Settings Content -->
<div class="py-2 flex-grow overflow-y-auto mx-2">
<div class="text-gray-700 text-sm">
<!-- Camera Settings -->
<div class="font-bold mb-2 text-[#2d4e8c]">Camera</div>
<select bind:value={selectedCamera}>
{#each cameras as camera}
<option value={camera.deviceId}>{camera.label}</option>
{/each}
</select>
<!-- Audio Settings -->
<div class="font-bold mb-2 text-[#2d4e8c]">Audio</div>
<!-- Microphone Settings -->
<div class="mb-4">
<select bind:value={selectedMic} on:change={getAudioPreview}>
{#each mics as mic}
<option value={mic.deviceId}>{mic.label}</option>
{/each}
</select>
<Toggle bind:toggled={enableLowFrequencies}>
Low Frequencies permitted/not permitted
</Toggle>
<AudioLevelIndicator stream={localAudioStream}/>
</div>
<!-- Speaker Settings -->
<div class="mt-2">
<select bind:value={selectedSpeaker} on:change={onSpeakerChange}>
{#each speakers as speaker}
<option value={speaker.deviceId}>{speaker.label}</option>
{/each}
</select>
<button on:click={toggleSpeakerTest}>
<Icon src={speakerTestOn ? VolumeUp : VolumeDown} size="24"/>
Test speakers
</button>
<audio bind:this={speakerTestElement} src="/assets/media/test.mp3"/>
</div>
</div>
</div>
</aside>Technical Implementation
Core Functionality
Device Management:
- Automatically refreshes device list when hardware changes
- Maintains selected devices between refreshes
- Handles device permission changes
Audio Monitoring:
- Creates microphone stream for level visualization
- Cleans up streams when component unmounts
- Handles device change events
Output Routing:
- Supports audio output device selection
- Provides speaker test functionality
- Falls back gracefully on unsupported browsers
Event Handling
Device Selection:
- Camera changes dispatch
cameraChangedevent - Microphone changes dispatch
micChangedevent - Speaker changes dispatch
speakerChangedevent
- Camera changes dispatch
User Interactions:
- Speaker test toggle
- Low frequency audio toggle
- Device selection changes
Lifecycle Management
Initialization:
- Sets up initial device selections
- Starts audio preview
- Attaches device change listeners
Cleanup:
- Removes event listeners
- Stops media streams
- Cleans up audio elements
Usage Example
svelte
<script>
import SettingsControls from "./settingsControls.svelte";
let selectedCamera = null;
let selectedMic = null;
let selectedSpeaker = null;
let enableLowFrequencies = false;
function handleClose() {
// Close settings panel
}
</script>
<SettingsControls
bind:selectedCamera
bind:selectedMic
bind:selectedSpeaker
bind:enableLowFrequencies
on:close={handleClose}
/>Dependencies
@steeze-ui/svelte-iconfor icons@steeze-ui/remix-icons(Close, VolumeUp, VolumeDown)svelte-togglefor toggle switch- Custom
AudioLevelIndicatorcomponent - Browser MediaDevices API
Styling Notes
- Clean white background with subtle borders
- Blue accent color for section headers
- Consistent spacing and padding
- Responsive layout
- Hidden audio elements for testing
Accessibility Features
- Semantic HTML structure
- Clear visual hierarchy
- Interactive elements have hover/focus states
- Labels for all form controls
- Keyboard-navigable interface