You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+158-1Lines changed: 158 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,154 @@
1
1
# viam-svelte-sdk
2
2
3
+
`pnpm i --save @viamrobotics/svelte-sdk @viamrobotics/sdk @tanstack/svelte-query`
4
+
5
+
## Getting started
6
+
7
+
The Viam Svelte SDK provides a reactive layer over `@viamrobotics/sdk`.
8
+
9
+
To get started, Include the `ViamProvider` component. Any child component will have access to the SDK hooks.
10
+
11
+
A map of `PartID`s to `DialConf`s must also be provided to connect to your machine(s).
12
+
13
+
```svelte
14
+
<script lang="ts">
15
+
import { ViamProvider } from '@viamrobotics/svelte-sdk';
16
+
import type { DialConf } from '@viamrobotics/sdk';
17
+
18
+
let { children } = $props();
19
+
20
+
const dialConfigs: Record<string, DialConf> = {
21
+
'my-part-id': {
22
+
host: 'my-host',
23
+
credentials: {
24
+
type: 'api-key',
25
+
authEntity: 'my-api-key-id',
26
+
payload: 'my-api-key-value',
27
+
},
28
+
signalingAddress: 'https://app.viam.dev:443',
29
+
disableSessions: false,
30
+
},
31
+
};
32
+
</script>
33
+
34
+
<ViamProvider {dialConfigs}>
35
+
{@render children()}
36
+
</ViamProvider>
37
+
```
38
+
39
+
### useRobotClient / useConnectionStatus
40
+
41
+
In any child component, you can access the `RobotClient` and `MachineConnectionStatus` of any connected machine with the `useRobotClient` and `useConnectionStatus` hooks.
42
+
43
+
```svelte
44
+
<script lang="ts">
45
+
import { useConnectionStatus, useRobotClient } from '@viamrobotics/svelte-sdk';
46
+
47
+
interface Props {
48
+
partID: string;
49
+
}
50
+
51
+
let { partID }: Props = $props();
52
+
53
+
const status = useConnectionStatus(() => partID);
54
+
const client = useRobotClient(() => partID);
55
+
56
+
$inspect(status.current);
57
+
$inspect(client.current);
58
+
</script>
59
+
```
60
+
61
+
### createRobotQuery / createRobotMutation
62
+
63
+
To execute queries / mutations directly on the robot client, use the following convenience hooks.
64
+
65
+
```svelte
66
+
<script lang="ts">
67
+
import {
68
+
createRobotMutation,
69
+
createRobotQuery,
70
+
useRobotClient,
71
+
} from '@viamrobotics/svelte-sdk';
72
+
73
+
let { partID } = $props();
74
+
75
+
const client = useRobotClient(() => partID);
76
+
const version = createRobotQuery(client, 'getVersion');
0 commit comments