Skip to content

Peripheral Devices Component Documentation

Overview

The Peripheral Devices component provides an interface for managing and interacting with connected peripheral devices in a video conferencing application. It displays available peripherals and allows users to select active devices.

Key Features

  1. Peripheral Device Management:

    • Displays connected peripheral devices
    • Shows active device state
    • Provides visual feedback for selection
  2. Device Information:

    • Device icons and names
    • Active/inactive state visualization
    • Loading state for device enumeration
  3. User Interaction:

    • Device selection
    • Panel closing
    • Empty state handling

Component Structure

Module Context (API Functions)

typescript
export async function getActivePeripheral(command: {
  deviceTypeId: string;
  deviceIds: string[];
}) {
  // Queries server for active peripheral status
}

export async function loadPeripherals() {
  // Loads available peripheral types from server
}

Props

typescript
export let selectedId = "";          // Currently selected peripheral ID
export let peripherals: IPeripheral[]; // Array of peripheral devices

State Management

typescript
let load = true; // Loading state flag

UI Components

Main Panel Structure

svelte
<aside class="bg-white flex flex-col h-full">
  <!-- Header -->
  <div class="flex justify-between border-b px-4 py-2">
    <span class="font-semibold">Peripherals</span>
    <button on:click={() => dispatch("close")}>
      <Icon src={Close} size="21" />
    </button>
  </div>

  <!-- Content States -->
  {#if load}
    <Progress step={1} /> <!-- Loading indicator -->
  {:else if peripherals.length}
    <!-- Peripheral Grid -->
    <div class="grid grid-cols-2 gap-4">
      {#each peripherals as peripheral}
        <!-- Peripheral Item -->
      {/each}
    </div>
  {:else}
    <!-- Empty State -->
    <div class="bg-orange-200 p-4 rounded-lg">
      No peripherals available
    </div>
  {/if}
</aside>

Peripheral Item

svelte
<button
  on:click={() => dispatch("activePeripheral", id)}
  class:text-blue-500={isActive}
  class:loginbox={isActive}
  class:shadow-sm={!isActive}
  class:bg-blue-50={isActive}
  class:border={!isActive}
  class:border-gray-300={!isActive}
  class:hover:bg-gray-100={!isActive}
>
  <iconify-icon {icon} style="font-size: 30px;" />
  <p class="text-center text-sm">{name}</p>
</button>

Technical Implementation

Data Flow

  1. Initialization:

    • Shows loading state
    • Receives peripherals via props
    • Updates UI when data loads
  2. User Interaction:

    • Clicking a peripheral dispatches activePeripheral event
    • Clicking close button dispatches close event
    • Visual feedback for active device

Event Handling

  1. Component Events:

    • close: Requests panel closure
    • activePeripheral: Notifies of peripheral selection
  2. UI Interactions:

    • Peripheral selection
    • Panel closing

Usage Example

svelte
<script>
  import Peripherals from "./peripherals.svelte";
  
  let peripherals = [
    { id: "1", name: "Stethoscope", icon: "medical-icon" },
    { id: "2", name: "Headphones", icon: "audio-icon" }
  ];
  let selectedPeripheralId = "1";
  
  function handlePeripheralSelect(event) {
    selectedPeripheralId = event.detail;
    // Handle peripheral activation
  }
</script>

<Peripherals 
  bind:selectedId={selectedPeripheralId}
  {peripherals}
  on:close={closePanel}
  on:activePeripheral={handlePeripheralSelect}
/>

Dependencies

  • @steeze-ui/svelte-icon for icons
  • @steeze-ui/remix-icons (Close)
  • Custom Progress component
  • Server query utilities
  • Iconify for device icons

Styling Notes

  • Clean white background with subtle borders
  • Grid layout for peripherals
  • Blue accent for active device
  • Hover states for interactive elements
  • Responsive padding and spacing
  • Visual loading indicator

Accessibility Features

  • Semantic HTML structure
  • Clear visual feedback for interactions
  • Sufficient contrast for text
  • Focus states for interactive elements
  • ARIA attributes for icons (recommended addition)

Released under the MIT License.