-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add audio input and audio output widgets (#47) #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
claude
wants to merge
8
commits into
main
Choose a base branch
from
claude/add-audio-in-out-widgets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8ec8a0e
feat: add audio input and audio output widgets (#47)
github-actions[bot] b6ffc80
fix: sort AudioInput/OutputWidget exports after Arm in index.ts
github-actions[bot] c1a58eb
add audio i/o to widgets
DTCurrie 9d47e23
Merge branch 'claude/add-audio-in-out-widgets' of https://github.com/…
DTCurrie 89f8bb0
lint
DTCurrie b25441d
pr comments
DTCurrie 0f5d864
cleanup
DTCurrie 838215d
Merge branch 'main' of https://github.com/viamrobotics/test-widgets i…
DTCurrie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@viamrobotics/test-widgets': minor | ||
| --- | ||
|
|
||
| Add `AudioInputWidget` and `AudioOutputWidget` components for audio in/out resources |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/lib/components/widgets/audio-input/__tests__/properties.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { ComponentProps } from 'svelte' | ||
|
|
||
| import { render, screen } from '@testing-library/svelte' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import Subject from '../properties.svelte' | ||
|
|
||
| const renderSubject = (props: Partial<ComponentProps<typeof Subject>> = {}) => | ||
| render(Subject, { | ||
| supportedCodecs: [], | ||
| sampleRateHz: 0, | ||
| numChannels: 0, | ||
| ...props, | ||
| }) | ||
|
|
||
| describe('AudioInput Properties', () => { | ||
| it('displays supported codecs', () => { | ||
| renderSubject({ supportedCodecs: ['mp3', 'pcm16'] }) | ||
| expect(screen.getByText('mp3, pcm16')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays None when no codecs are supported', () => { | ||
| renderSubject({ supportedCodecs: [] }) | ||
| expect(screen.getByText('None')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays sample rate', () => { | ||
| renderSubject({ sampleRateHz: 48000 }) | ||
| expect(screen.getByText('48000 Hz')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays number of channels', () => { | ||
| renderSubject({ numChannels: 2 }) | ||
| expect(screen.getByText('2')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <script lang="ts"> | ||
| import { AudioInClient } from '@viamrobotics/sdk' | ||
| import { createResourceClient, createResourceQuery } from '@viamrobotics/svelte-sdk' | ||
|
|
||
| import ApiSection from '$lib/components/api-section.svelte' | ||
| import ConnectionStatus from '$lib/components/connection-status.svelte' | ||
| import Query from '$lib/components/query.svelte' | ||
| import RefetchController from '$lib/components/refetch-controller.svelte' | ||
| import { createRefetchIntervalStore } from '$lib/components/refetch-interval-store.svelte' | ||
|
|
||
| import Properties from './properties.svelte' | ||
|
|
||
| interface Props { | ||
| partID: string | ||
| resourceName: string | ||
| } | ||
|
|
||
| const { partID, resourceName }: Props = $props() | ||
|
|
||
| const refetchInterval = createRefetchIntervalStore( | ||
| () => partID, | ||
| () => resourceName, | ||
| 'audio-input' | ||
| ) | ||
|
|
||
| const client = createResourceClient( | ||
| AudioInClient, | ||
| () => partID, | ||
| () => resourceName | ||
| ) | ||
|
|
||
| const propertiesQuery = createResourceQuery(client, 'getProperties', () => ({ | ||
|
DTCurrie marked this conversation as resolved.
|
||
| refetchInterval: refetchInterval.current, | ||
| })) | ||
| </script> | ||
|
|
||
| <ConnectionStatus {partID}> | ||
| {#snippet connected()} | ||
| <div class="p-4 pb-3"> | ||
| <RefetchController | ||
| {refetchInterval} | ||
| queries={[propertiesQuery]} | ||
| /> | ||
| </div> | ||
|
|
||
| <ApiSection | ||
| title="GetProperties" | ||
| description="Audio input properties" | ||
| class="relative" | ||
| > | ||
| <Query | ||
| query={propertiesQuery} | ||
| contentCx="h-6" | ||
| > | ||
| {#if propertiesQuery.data !== undefined} | ||
| <Properties | ||
| supportedCodecs={propertiesQuery.data.supportedCodecs} | ||
| sampleRateHz={propertiesQuery.data.sampleRateHz} | ||
| numChannels={propertiesQuery.data.numChannels} | ||
| /> | ||
| {/if} | ||
| </Query> | ||
| </ApiSection> | ||
| {/snippet} | ||
| </ConnectionStatus> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <script lang="ts"> | ||
| interface Props { | ||
| supportedCodecs: string[] | ||
| sampleRateHz: number | ||
| numChannels: number | ||
| } | ||
|
|
||
| const { supportedCodecs, sampleRateHz, numChannels }: Props = $props() | ||
| </script> | ||
|
|
||
| <dl class="font-roboto-mono flex flex-col gap-y-2 text-sm"> | ||
| <div class="flex flex-row"> | ||
| <dt class="text-default w-50 min-w-50 pr-2 font-medium">Supported Codecs</dt> | ||
| <dd class="text-subtle-1"> | ||
| {supportedCodecs.length > 0 ? supportedCodecs.join(', ') : 'None'} | ||
| </dd> | ||
| </div> | ||
| <div class="flex flex-row"> | ||
| <dt class="text-default w-50 min-w-50 pr-2 font-medium">Sample Rate</dt> | ||
| <dd class="text-subtle-1">{sampleRateHz} Hz</dd> | ||
| </div> | ||
| <div class="flex flex-row"> | ||
| <dt class="text-default w-50 min-w-50 pr-2 font-medium">Channels</dt> | ||
| <dd class="text-subtle-1">{numChannels}</dd> | ||
| </div> | ||
| </dl> |
36 changes: 36 additions & 0 deletions
36
src/lib/components/widgets/audio-output/__tests__/properties.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { ComponentProps } from 'svelte' | ||
|
|
||
| import { render, screen } from '@testing-library/svelte' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import Subject from '../properties.svelte' | ||
|
|
||
| const renderSubject = (props: Partial<ComponentProps<typeof Subject>> = {}) => | ||
| render(Subject, { | ||
| supportedCodecs: [], | ||
| sampleRateHz: 0, | ||
| numChannels: 0, | ||
| ...props, | ||
| }) | ||
|
|
||
| describe('AudioOutput Properties', () => { | ||
| it('displays supported codecs', () => { | ||
| renderSubject({ supportedCodecs: ['mp3', 'pcm16'] }) | ||
| expect(screen.getByText('mp3, pcm16')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays None when no codecs are supported', () => { | ||
| renderSubject({ supportedCodecs: [] }) | ||
| expect(screen.getByText('None')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays sample rate', () => { | ||
| renderSubject({ sampleRateHz: 44100 }) | ||
| expect(screen.getByText('44100 Hz')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('displays number of channels', () => { | ||
| renderSubject({ numChannels: 1 }) | ||
| expect(screen.getByText('1')).toBeInTheDocument() | ||
| }) | ||
| }) |
65 changes: 65 additions & 0 deletions
65
src/lib/components/widgets/audio-output/audio-output.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <script lang="ts"> | ||
| import { AudioOutClient } from '@viamrobotics/sdk' | ||
| import { createResourceClient, createResourceQuery } from '@viamrobotics/svelte-sdk' | ||
|
|
||
| import ApiSection from '$lib/components/api-section.svelte' | ||
| import ConnectionStatus from '$lib/components/connection-status.svelte' | ||
| import Query from '$lib/components/query.svelte' | ||
| import RefetchController from '$lib/components/refetch-controller.svelte' | ||
| import { createRefetchIntervalStore } from '$lib/components/refetch-interval-store.svelte' | ||
|
|
||
| import Properties from './properties.svelte' | ||
|
|
||
| interface Props { | ||
| partID: string | ||
| resourceName: string | ||
| } | ||
|
|
||
| const { partID, resourceName }: Props = $props() | ||
|
|
||
| const refetchInterval = createRefetchIntervalStore( | ||
| () => partID, | ||
| () => resourceName, | ||
| 'audio-output' | ||
| ) | ||
|
|
||
| const client = createResourceClient( | ||
| AudioOutClient, | ||
| () => partID, | ||
| () => resourceName | ||
| ) | ||
|
|
||
| const propertiesQuery = createResourceQuery(client, 'getProperties', () => ({ | ||
|
DTCurrie marked this conversation as resolved.
|
||
| refetchInterval: refetchInterval.current, | ||
| })) | ||
| </script> | ||
|
|
||
| <ConnectionStatus {partID}> | ||
| {#snippet connected()} | ||
| <div class="p-4 pb-3"> | ||
| <RefetchController | ||
| {refetchInterval} | ||
| queries={[propertiesQuery]} | ||
| /> | ||
| </div> | ||
|
|
||
| <ApiSection | ||
| title="GetProperties" | ||
| description="Audio output properties" | ||
| class="relative" | ||
| > | ||
| <Query | ||
| query={propertiesQuery} | ||
| contentCx="h-6" | ||
| > | ||
| {#if propertiesQuery.data !== undefined} | ||
| <Properties | ||
| supportedCodecs={propertiesQuery.data.supportedCodecs} | ||
| sampleRateHz={propertiesQuery.data.sampleRateHz} | ||
| numChannels={propertiesQuery.data.numChannels} | ||
| /> | ||
| {/if} | ||
| </Query> | ||
| </ApiSection> | ||
| {/snippet} | ||
| </ConnectionStatus> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <script lang="ts"> | ||
|
DTCurrie marked this conversation as resolved.
|
||
| interface Props { | ||
| supportedCodecs: string[] | ||
| sampleRateHz: number | ||
| numChannels: number | ||
| } | ||
|
|
||
| const { supportedCodecs, sampleRateHz, numChannels }: Props = $props() | ||
| </script> | ||
|
|
||
| <dl class="font-roboto-mono flex flex-col gap-y-2 text-sm"> | ||
| <div class="flex flex-row"> | ||
| <dt class="text-default w-50 min-w-50 pr-2 font-medium">Supported Codecs</dt> | ||
| <dd class="text-subtle-1"> | ||
| {supportedCodecs.length > 0 ? supportedCodecs.join(', ') : 'None'} | ||
| </dd> | ||
| </div> | ||
| <div class="flex flex-row"> | ||
| <dt class="text-default w-50 min-w-50 pr-2 font-medium">Sample Rate</dt> | ||
| <dd class="text-subtle-1">{sampleRateHz} Hz</dd> | ||
| </div> | ||
| <div class="flex flex-row"> | ||
| <dt class="text-default w-50 min-w-50 pr-2 font-medium">Channels</dt> | ||
| <dd class="text-subtle-1">{numChannels}</dd> | ||
| </div> | ||
| </dl> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.