@luxonis/depthai-viewer-common 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxonis/depthai-viewer-common",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Common utilities and components for building a frontend application for DepthAI projects",
5
5
  "license": "ISC",
6
6
  "author": "Luxonis Holding Corporation",
@@ -0,0 +1,12 @@
1
+ import type React from 'react';
2
+ import { Button, type ButtonProps } from '@luxonis/common-fe-components';
3
+ import { Link, type LinkProps } from './Link.js';
4
+
5
+ export type ButtonLinkProps = ButtonProps & {
6
+ linkProps: LinkProps;
7
+ };
8
+
9
+ export const ButtonLink: React.FC<ButtonLinkProps> = ({ linkProps, ...buttonProps }) => {
10
+ const button = <Button {...buttonProps} />;
11
+ return !buttonProps.disabled ? <Link {...linkProps}>{button}</Link> : button;
12
+ };
@@ -0,0 +1,39 @@
1
+ import { ExternalLink, Flex, SubLabel } from '@luxonis/common-fe-components';
2
+ import { useConnection } from '../providers/ConnectionProvider.js';
3
+ import React from 'react';
4
+
5
+ const DISPLAY_LABEL_TIMEOUT = 30_000 as const;
6
+
7
+ export const CTASubLabel = () => {
8
+ const { connected, topics } = useConnection();
9
+ const [shouldDisplayLabel, setShouldDisplayLabel] = React.useState(false);
10
+ React.useEffect(() => {
11
+ if (connected && topics.length === 0 && !shouldDisplayLabel) {
12
+ const timeout = setTimeout(() => setShouldDisplayLabel(true), DISPLAY_LABEL_TIMEOUT);
13
+ return () => clearTimeout(timeout);
14
+ }
15
+ }, [connected, topics, shouldDisplayLabel]);
16
+
17
+ return (
18
+ shouldDisplayLabel && (
19
+ <Flex textAlign="center">
20
+ <SubLabel
21
+ text={
22
+ <p>
23
+ You can purchase an OAK camera from the{' '}
24
+ <ExternalLink raw to="https://shop.luxonis.com" color="light.active">
25
+ <SubLabel color="link" text="Luxonis Store" />
26
+ </ExternalLink>
27
+ . After your purchase,
28
+ <br /> explore the{' '}
29
+ <ExternalLink raw to="https://rvc4.docs.luxonis.com/hardware" color="light.active">
30
+ <SubLabel color="link" text="Luxonis Documentation" />
31
+ </ExternalLink>{' '}
32
+ for comprehensive setup tutorials to get started.
33
+ </p>
34
+ }
35
+ />
36
+ </Flex>
37
+ )
38
+ );
39
+ };
@@ -0,0 +1,20 @@
1
+ import { DataProvider } from '../providers/DataProvider.js';
2
+ import { ConnectionProvider } from '../providers/ConnectionProvider.js';
3
+ import { Streams } from './Streams.js';
4
+ import type { DAIService } from '../dai-connection/connection.js';
5
+
6
+ type DepthAIEntrypointProps = {
7
+ activeServices: DAIService[];
8
+ };
9
+
10
+ export function DepthAIEntrypoint(props: Readonly<DepthAIEntrypointProps>) {
11
+ const { activeServices } = props;
12
+
13
+ return (
14
+ <DataProvider>
15
+ <ConnectionProvider activeServices={activeServices}>
16
+ <Streams />
17
+ </ConnectionProvider>
18
+ </DataProvider>
19
+ );
20
+ }
@@ -0,0 +1,10 @@
1
+ import { Link as _Link } from 'react-router-dom';
2
+ import { useNavigation } from '../hooks/navigation.js';
3
+
4
+ export type LinkProps = { to: 'pipeline' | 'streams' };
5
+
6
+ export const Link: React.FC<React.PropsWithChildren<LinkProps>> = ({ to, children }) => {
7
+ const { makePath } = useNavigation();
8
+
9
+ return <_Link to={makePath(to)}>{children}</_Link>;
10
+ };
@@ -0,0 +1,35 @@
1
+ import { Flex, Header } from '@luxonis/common-fe-components';
2
+ import { PipelineCanvas } from '@luxonis/depthai-pipeline-lib';
3
+ import { useConnection } from '../providers/ConnectionProvider.js';
4
+ import React from 'react';
5
+
6
+ const PIPELINE_LOADING_TIMEOUT = 60_000;
7
+
8
+ export const Pipeline: React.FC = () => {
9
+ const { pipeline, isPipelineLoading, setIsPipelineLoading } = useConnection();
10
+
11
+ React.useEffect(() => {
12
+ if (isPipelineLoading && pipeline === undefined) {
13
+ const timeout = setTimeout(() => {
14
+ setIsPipelineLoading(false);
15
+ }, PIPELINE_LOADING_TIMEOUT);
16
+ return () => clearTimeout(timeout);
17
+ }
18
+ }, [isPipelineLoading, pipeline, setIsPipelineLoading]);
19
+
20
+ if (isPipelineLoading) {
21
+ return (
22
+ <Flex align="center" justify="center" full>
23
+ <Header text="Loading pipeline..." />
24
+ </Flex>
25
+ );
26
+ }
27
+
28
+ return pipeline === undefined ? (
29
+ <Flex align="center" justify="center" full>
30
+ <Header text="Pipeline is not available" />
31
+ </Flex>
32
+ ) : (
33
+ <PipelineCanvas pipeline={pipeline} height="full" />
34
+ );
35
+ };
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
3
+
4
+ export type ResizableItem = {
5
+ component: React.ReactNode;
6
+ };
7
+
8
+ export type ResizableLayoutProps = {
9
+ id?: string | null;
10
+ items: ResizableItem[][];
11
+ };
12
+
13
+ export const ResizableLayout: React.FC<ResizableLayoutProps> = ({
14
+ items,
15
+ id = 'resizable-layout',
16
+ }) => {
17
+ const groupStyles: React.CSSProperties = React.useMemo(
18
+ () => ({
19
+ display: 'flex',
20
+ gap: '5px',
21
+ }),
22
+ [],
23
+ );
24
+
25
+ const panels = React.useMemo(
26
+ () =>
27
+ items.map((row, rowIndex) => (
28
+ <React.Fragment key={`resizable-row-${rowIndex}`}>
29
+ <Panel order={rowIndex}>
30
+ <PanelGroup
31
+ autoSaveId={id && `${id}-${rowIndex}`}
32
+ direction="horizontal"
33
+ style={groupStyles}
34
+ >
35
+ {row.map((item, itemIndex) => (
36
+ <React.Fragment key={`resizable-row-${rowIndex}-item-${itemIndex}`}>
37
+ <Panel order={itemIndex} style={{ display: 'flex' }}>
38
+ {item.component}
39
+ </Panel>
40
+ {itemIndex !== row.length - 1 && <PanelResizeHandle />}
41
+ </React.Fragment>
42
+ ))}
43
+ </PanelGroup>
44
+ </Panel>
45
+ {rowIndex !== items.length - 1 && <PanelResizeHandle />}
46
+ </React.Fragment>
47
+ )),
48
+ [groupStyles, id, items],
49
+ );
50
+
51
+ return (
52
+ <PanelGroup autoSaveId={id} direction="vertical" style={groupStyles}>
53
+ {panels}
54
+ </PanelGroup>
55
+ );
56
+ };
@@ -0,0 +1,261 @@
1
+ import {
2
+ Button,
3
+ DropdownMenu,
4
+ DropdownMenuCheckboxItem,
5
+ DropdownMenuContent,
6
+ DropdownMenuTrigger,
7
+ Flex,
8
+ Header,
9
+ Input,
10
+ NormalText,
11
+ SubHeader,
12
+ Tooltip,
13
+ } from '@luxonis/common-fe-components';
14
+ import { ImagePanel, PanelLayout, PointCloudPanel } from '@luxonis/visualizer-protobuf';
15
+ import React from 'react';
16
+
17
+ import { ResizableLayout, type Topic } from '@luxonis/depthai-viewer-common';
18
+ import { StreamTypes } from '../constants/streams.js';
19
+ import { useConnection } from '../providers/ConnectionProvider.js';
20
+ import { useData } from '../providers/DataProvider.js';
21
+ import { makeColumns } from '../utils/arrays.js';
22
+ import { CTASubLabel } from './CTASubLabel.js';
23
+ import { FaUsersViewfinder as VisualizerIcon } from 'react-icons/fa6';
24
+ import { sortStreamsDefault } from '../utils/sorting.js';
25
+ import type { DeviceConfiguration } from '../models/device-configuration.js';
26
+
27
+ const EnabledStreamsView: React.FC<{
28
+ topics: Topic[][];
29
+ targetFps?: number;
30
+ isRawSteamEnabledManually?: boolean;
31
+ setIsRawSteamEnabledManually?: (value: boolean) => void;
32
+ triggerToast?: () => void;
33
+ deviceOptions?: DeviceConfiguration | null;
34
+ }> = ({
35
+ topics,
36
+ targetFps,
37
+ triggerToast,
38
+ isRawSteamEnabledManually,
39
+ setIsRawSteamEnabledManually,
40
+ }) => {
41
+ const { toggleTopic, topics: allTopics } = useConnection();
42
+
43
+ const items = React.useMemo(() => {
44
+ return topics.map((row) => {
45
+ let filteredRow = row.filter((topic) => !topic.name.startsWith('_'));
46
+
47
+ if (
48
+ filteredRow.some((topic) => topic.name === StreamTypes.PointCloud) &&
49
+ filteredRow.some((topic) => topic.name !== StreamTypes.Encoded) &&
50
+ !isRawSteamEnabledManually
51
+ ) {
52
+ filteredRow = filteredRow.filter((topic) => topic.name !== StreamTypes.Encoded);
53
+ }
54
+ return filteredRow.map(({ name, annotations, extraAnnotations, kind }) => ({
55
+ component:
56
+ kind === 'pointCloud' || name === StreamTypes.PointCloud ? (
57
+ <PointCloudPanel
58
+ key={name}
59
+ toggleTopic={(topic) => {
60
+ if (allTopics.find((t) => t.name === StreamTypes._PointCloudColor)) {
61
+ toggleTopic(StreamTypes._PointCloudColor);
62
+ } else if (allTopics.find((t) => t.name === StreamTypes.Encoded)) {
63
+ toggleTopic(StreamTypes.Encoded);
64
+ }
65
+ toggleTopic(topic);
66
+ }}
67
+ topic={name}
68
+ />
69
+ ) : name !== StreamTypes.Raw &&
70
+ name !== StreamTypes.LeftRaw &&
71
+ name !== StreamTypes.RightRaw &&
72
+ !navigator.userAgent.includes('Chrome') ? (
73
+ <PanelLayout>
74
+ <Flex
75
+ full
76
+ justify="center"
77
+ align="center"
78
+ direction="column"
79
+ gap="sm"
80
+ textAlign="center"
81
+ >
82
+ <SubHeader text={`${name} is only supported in Google Chrome.`} />
83
+ <SubHeader text="Please switch to Chrome for the best experience." />
84
+ </Flex>
85
+ </PanelLayout>
86
+ ) : (
87
+ <ImagePanel
88
+ key={name}
89
+ toggleTopic={(topic) => {
90
+ if (isRawSteamEnabledManually && topic === StreamTypes.Encoded) {
91
+ setIsRawSteamEnabledManually?.(false);
92
+ }
93
+ toggleTopic(topic);
94
+ }}
95
+ topic={name}
96
+ annotationTopics={annotations}
97
+ extraAnnotationTopics={extraAnnotations}
98
+ targetFps={targetFps}
99
+ triggerToast={triggerToast}
100
+ disableAnnotations={
101
+ name === StreamTypes.LeftRaw ||
102
+ name === StreamTypes.RightRaw ||
103
+ name === StreamTypes.LeftEncoded ||
104
+ name === StreamTypes.RightEncoded
105
+ }
106
+ />
107
+ ),
108
+ }));
109
+ });
110
+ }, [topics, targetFps, triggerToast, isRawSteamEnabledManually, setIsRawSteamEnabledManually]);
111
+
112
+ return <ResizableLayout items={items} />;
113
+ };
114
+
115
+ export const Streams: React.FC<{
116
+ targetFps?: number;
117
+ triggerToast?: () => void;
118
+ setIsRawSteamEnabledManually?: (value: boolean) => void;
119
+ isRawSteamEnabledManually?: boolean;
120
+ deviceOptions?: DeviceConfiguration | null;
121
+ }> = ({
122
+ targetFps,
123
+ triggerToast,
124
+ isRawSteamEnabledManually = true,
125
+ setIsRawSteamEnabledManually,
126
+ deviceOptions,
127
+ }) => {
128
+ const { changeWsUrl, columns, connectionType, wsUrl } = useData();
129
+ const { connected, topics, toggleTopic } = useConnection();
130
+ const [shouldDisplayHelper, setShouldDisplayHelper] = React.useState(false);
131
+ const [connecting, setConnecting] = React.useState(false);
132
+
133
+ const enabledTopics = React.useMemo(
134
+ () =>
135
+ makeColumns(
136
+ topics.filter((topic) => !topic.name.startsWith('_')).filter((topic) => topic.enabled),
137
+ columns,
138
+ ),
139
+ [columns, topics],
140
+ );
141
+
142
+ const wsUrlRef = React.useRef<HTMLInputElement>(null);
143
+
144
+ const handleChangeUrl = React.useCallback(
145
+ () => wsUrlRef.current?.value && changeWsUrl(wsUrlRef.current.value),
146
+ [changeWsUrl],
147
+ );
148
+
149
+ const shouldSuggestUrlChange = React.useMemo(
150
+ () => window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1',
151
+ [],
152
+ );
153
+
154
+ React.useEffect(() => {
155
+ if (!shouldDisplayHelper && !shouldSuggestUrlChange) {
156
+ setTimeout(() => {
157
+ setShouldDisplayHelper(true);
158
+ }, 10_000);
159
+ }
160
+ }, [shouldDisplayHelper, shouldSuggestUrlChange]);
161
+
162
+ const sortedTopics = React.useMemo(
163
+ () => sortStreamsDefault(topics.filter((topic) => !topic.name.startsWith('_'))),
164
+ [topics],
165
+ );
166
+
167
+ // TODO: Store detections in url or global provider
168
+ // to persist on re-renders
169
+ return (
170
+ <PanelLayout>
171
+ {enabledTopics.length === 0 || enabledTopics[0].length === 0 ? (
172
+ <Flex full justify="center" align="center" direction="column" gap="sm">
173
+ <Header
174
+ text={
175
+ connected ? (
176
+ sortedTopics.length === 0 ? (
177
+ 'DepthAI connected, awaiting device...'
178
+ ) : (
179
+ <p>
180
+ To view stream(s), select it with Streams Button{' '}
181
+ <DropdownMenu>
182
+ <Tooltip content="Streams">
183
+ <DropdownMenuTrigger>
184
+ <Button icon={VisualizerIcon} variant="outline" colorVariant="white" />
185
+ </DropdownMenuTrigger>
186
+ </Tooltip>
187
+ <DropdownMenuContent>
188
+ {sortedTopics.map((topic, i) => (
189
+ <DropdownMenuCheckboxItem key={i} onClick={() => toggleTopic(topic.name)}>
190
+ {topic.name}
191
+ </DropdownMenuCheckboxItem>
192
+ ))}
193
+ </DropdownMenuContent>
194
+ </DropdownMenu>{' '}
195
+ either here or in the top right corner
196
+ </p>
197
+ )
198
+ ) : // TODO: connection details (state, errors, retries, webrtc stage)
199
+ connectionType === 'ws' ? (
200
+ 'Connecting to DepthAI via WebSocket...'
201
+ ) : (
202
+ 'Connecting to DepthAI via WebRTC...'
203
+ )
204
+ }
205
+ />
206
+
207
+ {!connected &&
208
+ (shouldSuggestUrlChange ? (
209
+ <>
210
+ <SubHeader
211
+ text={connectionType === 'ws' ? 'Use another URL?' : 'Connect via WebSocket?'}
212
+ />
213
+ <form
214
+ onSubmit={(event) => {
215
+ event.stopPropagation();
216
+ event.preventDefault();
217
+
218
+ setConnecting(true);
219
+
220
+ handleChangeUrl();
221
+ }}
222
+ >
223
+ <Flex>
224
+ <Input
225
+ type="text"
226
+ ref={wsUrlRef}
227
+ placeholder={wsUrl}
228
+ roundedRight={0}
229
+ onChange={() => setConnecting(false)}
230
+ />
231
+ <Button
232
+ type="submit"
233
+ label={connecting ? 'Connecting...' : 'Connect'}
234
+ style={{
235
+ borderTopLeftRadius: 0,
236
+ borderBottomLeftRadius: 0,
237
+ }}
238
+ />
239
+ </Flex>
240
+ </form>
241
+ </>
242
+ ) : (
243
+ shouldDisplayHelper && (
244
+ <NormalText text="Please check that you have the correct link to DepthAI Visualizer and that your device is running. You need a new link after any app or device restart." />
245
+ )
246
+ ))}
247
+ <CTASubLabel />
248
+ </Flex>
249
+ ) : (
250
+ <EnabledStreamsView
251
+ topics={enabledTopics}
252
+ targetFps={targetFps}
253
+ triggerToast={triggerToast}
254
+ isRawSteamEnabledManually={isRawSteamEnabledManually}
255
+ setIsRawSteamEnabledManually={setIsRawSteamEnabledManually}
256
+ deviceOptions={deviceOptions}
257
+ />
258
+ )}
259
+ </PanelLayout>
260
+ );
261
+ };
@@ -0,0 +1,45 @@
1
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
2
+ export type DAIResponse<T = any> = {
3
+ data: T;
4
+ error: Error | string | null;
5
+ message: string | null;
6
+ status: number;
7
+ };
8
+
9
+ export const DAI_SERVICE_NAME = {
10
+ topicGroups: 'topicGroups',
11
+ pipelineSchema: 'pipelineSchema',
12
+ keyPressed: 'keyPressed',
13
+ // Devices
14
+ getDevices: 'getDevices',
15
+ startDevice: 'startDevice',
16
+ stopDevice: 'stopDevice',
17
+ getDeviceOptions: 'getDeviceOptions',
18
+ getFpsRange: 'getFpsRange',
19
+ // Configs
20
+ getSensors: 'getSensors',
21
+ setSensors: 'setSensors',
22
+ getStereoDepth: 'getStereoDepth',
23
+ setStereoDepth: 'setStereoDepth',
24
+ getStereoDepthPreset: 'getStereoDepthPreset',
25
+ setStereoDepthPreset: 'setStereoDepthPreset',
26
+ getStereoDepthCalibration: 'getStereoDepthCalibration',
27
+ setStereoDepthCalibration: 'setStereoDepthCalibration',
28
+ setIr: 'setIr',
29
+ setPointCloud: 'setPointCloud',
30
+ setThermal: 'setThermal',
31
+ getCameraIntrinsics: 'getCameraIntrinsics',
32
+ // Neural networks
33
+ getNeuralNetworks: 'getNeuralNetworks',
34
+ setNeuralNetwork: 'setNeuralNetwork',
35
+ getNeuralNetworkConfiguration: 'getNeuralNetworkConfiguration',
36
+ setNeuralNetworkConfiguration: 'setNeuralNetworkConfiguration',
37
+ };
38
+
39
+ export const SIGNALING_SERVER_URL = 'wss://signal.cloud.luxonis.com/session/';
40
+ export const ICE_SERVERS_API_ENDPOINT =
41
+ 'https://signal.cloud-stg.luxonis.com/api/v1/turn-credentials';
42
+
43
+ export const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
44
+ { urls: ['stun:stun.l.google.com:19302', 'stun:stun1.l.google.com:19302'] },
45
+ ];
@@ -0,0 +1,12 @@
1
+ export const StreamTypes = {
2
+ Encoded: 'H.264 Stream',
3
+ LeftEncoded: 'Left H.264 Stream',
4
+ RightEncoded: 'Right H.264 Stream',
5
+ Disparity: 'Disparity Stream',
6
+ Raw: 'Raw Stream',
7
+ LeftRaw: 'Left Raw Stream',
8
+ RightRaw: 'Right Raw Stream',
9
+ PointCloud: 'Point Cloud',
10
+ NeuralNetwork: 'Neural Network Stream',
11
+ _PointCloudColor: '_Point Cloud Color',
12
+ } as const;
@@ -0,0 +1,6 @@
1
+ export const DEFAULT_WS_URL = `wss://${window.location.hostname}:8000/dai`;
2
+
3
+ export const LOCALHOST_WS_URL = 'ws://localhost:8765';
4
+
5
+ export const IS_LOCALHOST =
6
+ window.origin.includes('localhost') || window.origin.includes('127.0.0.1');