|
1 | 1 | <script lang="ts"> |
2 | | - import { Button, Label, Switch, ToggleButtons } from '@viamrobotics/prime-core' |
| 2 | + import { Button, Label, Select, Switch, ToggleButtons } from '@viamrobotics/prime-core' |
3 | 3 | import { CameraClient } from '@viamrobotics/sdk' |
4 | 4 | import { createResourceClient, createResourceQuery } from '@viamrobotics/svelte-sdk' |
5 | 5 |
|
|
14 | 14 |
|
15 | 15 | import PCDWidget from '../pcd/pcd-widget.svelte' |
16 | 16 | import ExportScreenshot from './export-screenshot.svelte' |
| 17 | + import { getSourceNames } from './get-source-names' |
17 | 18 | import LiveOrPollingVideo from './live-or-polling-video.svelte' |
18 | 19 | import PictureInPictureButton from './picture-in-picture-button.svelte' |
19 | 20 |
|
|
30 | 31 | 'camera' |
31 | 32 | ) |
32 | 33 | let isShowingPointcloud = $state(false) |
| 34 | + let selectedSource = $state('') |
| 35 | + let sourceNames = $state<string[]>([]) |
33 | 36 |
|
34 | 37 | const { addImageToDataset } = useAddImageToDataset() |
35 | 38 | const setIsShowingPointcloud = (event: CustomEvent<boolean>) => { |
|
42 | 45 | () => resourceName |
43 | 46 | ) |
44 | 47 |
|
45 | | - const imageQuery = createResourceQuery(client, 'getImages', () => ({ |
46 | | - enabled: refetchInterval.current !== RefetchIntervals.LIVE, |
47 | | - refetchInterval: refetchInterval.current, |
48 | | - })) |
| 48 | + const imageQuery = createResourceQuery( |
| 49 | + client, |
| 50 | + 'getImages', |
| 51 | + () => (selectedSource ? ([[selectedSource]] as [string[]]) : ([] as [])), |
| 52 | + () => ({ |
| 53 | + enabled: refetchInterval.current !== RefetchIntervals.LIVE, |
| 54 | + refetchInterval: refetchInterval.current, |
| 55 | + }) |
| 56 | + ) |
| 57 | +
|
| 58 | + $effect(() => { |
| 59 | + if (sourceNames.length === 0 && imageQuery.data?.images) { |
| 60 | + const names = getSourceNames(imageQuery.data.images) |
| 61 | + if (names.length > 0) { |
| 62 | + sourceNames = names |
| 63 | + selectedSource = names[0]! |
| 64 | + } |
| 65 | + } |
| 66 | + }) |
49 | 67 |
|
50 | 68 | const pointcloudQuery = createResourceQuery(client, 'getPointCloud', () => ({ |
51 | 69 | enabled: isShowingPointcloud, |
|
59 | 77 | // A separate, disabled query for exporting a screenshot |
60 | 78 | // since this button should work regardless of refetch |
61 | 79 | // interval and not affect the image feed. |
62 | | - const exportScreenshotQuery = createResourceQuery(client, 'getImages', { |
63 | | - enabled: false, |
64 | | - refetchInterval: false, |
65 | | - }) |
| 80 | + const exportScreenshotQuery = createResourceQuery( |
| 81 | + client, |
| 82 | + 'getImages', |
| 83 | + () => (selectedSource ? ([[selectedSource]] as [string[]]) : ([] as [])), |
| 84 | + { |
| 85 | + enabled: false, |
| 86 | + refetchInterval: false, |
| 87 | + } |
| 88 | + ) |
66 | 89 |
|
67 | 90 | // Firefox has native support for picture-in-picture and does not need |
68 | 91 | // to be requested separately. Don't show a "toggle pip" button in Firefox. |
69 | 92 | const isFirefox = navigator.userAgent.toLowerCase().includes('firefox') |
70 | 93 |
|
| 94 | + const onSourceSelect = (event: Event) => { |
| 95 | + const { value } = event.target as HTMLSelectElement |
| 96 | + selectedSource = value |
| 97 | + } |
| 98 | +
|
71 | 99 | let mousePostionTooltip = $state<'On' | 'Off'>('Off') |
72 | 100 | const setMousePostionTooltip = (event: CustomEvent<string>) => { |
73 | 101 | mousePostionTooltip = event.detail as 'On' | 'Off' |
|
78 | 106 |
|
79 | 107 | <ConnectionStatus {partID}> |
80 | 108 | {#snippet connected()} |
81 | | - <div class="flex gap-2 p-4 pb-3"> |
| 109 | + <div class="flex gap-4 p-4 pb-3"> |
82 | 110 | <RefetchController |
83 | 111 | {refetchInterval} |
84 | 112 | allowLive |
85 | 113 | queries={[imageQuery, pointcloudQuery]} |
86 | 114 | /> |
| 115 | + {#if sourceNames.length > 0 && refetchInterval.current !== RefetchIntervals.LIVE} |
| 116 | + <Label position="left"> |
| 117 | + Source |
| 118 | + <Select |
| 119 | + value={selectedSource} |
| 120 | + on:change={onSourceSelect} |
| 121 | + slot="input" |
| 122 | + > |
| 123 | + {#each sourceNames as name (name)} |
| 124 | + <option value={name}>{name}</option> |
| 125 | + {/each} |
| 126 | + </Select> |
| 127 | + </Label> |
| 128 | + {/if} |
87 | 129 | </div> |
88 | 130 | <div class="flex h-full w-full gap-4 p-4"> |
89 | 131 | <div class="grow"> |
|
0 commit comments