Skip to content

Commit 99a8135

Browse files
Merge pull request #59 from viamrobotics/dial-method
Use new `robotClient.dial` method for connection
2 parents ef702cb + 14bc346 commit 99a8135

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

.changeset/wet-feet-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@viamrobotics/svelte-sdk": patch
3+
---
4+
5+
Use new `robotClient.dial` method for connection

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Package Managers
22
package-lock.json
33
pnpm-lock.yaml
4-
yarn.lock
4+
yarn.lock
5+
.changeset/*.md

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"peerDependencies": {
4646
"@tanstack/svelte-query": "5.87.1",
47-
"@viamrobotics/sdk": ">=0.38",
47+
"@viamrobotics/sdk": ">=0.51",
4848
"svelte": ">=5"
4949
},
5050
"devDependencies": {
@@ -63,7 +63,7 @@
6363
"@testing-library/svelte": "^5.2.8",
6464
"@viamrobotics/eslint-config": "^1.1.0",
6565
"@viamrobotics/prettier-config-svelte": "^1.1.0",
66-
"@viamrobotics/sdk": "^0.49.1",
66+
"@viamrobotics/sdk": "^0.51.0",
6767
"@viamrobotics/typescript-config": "^0.1.1",
6868
"eslint": "^9.30.0",
6969
"eslint-config-prettier": "^10.1.5",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/hooks/robot-clients.svelte.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {
22
type Client,
3-
createRobotClient,
43
type DialConf,
54
MachineConnectionEvent,
6-
type RobotClient,
5+
RobotClient,
76
} from '@viamrobotics/sdk';
87
import { getContext, onMount, setContext } from 'svelte';
98
import { useQueryClient } from '@tanstack/svelte-query';
@@ -35,12 +34,7 @@ export const provideRobotClientsContext = (
3534

3635
let lastConfigs: Record<PartID, DialConf | undefined> = {};
3736

38-
const disconnect = async (partID: PartID, config?: DialConf) => {
39-
// If currently making the initial connection, abort it.
40-
if (config?.reconnectAbortSignal !== undefined) {
41-
config.reconnectAbortSignal.abort = true;
42-
}
43-
37+
const disconnect = async (partID: PartID) => {
4438
const client = clients[partID];
4539

4640
if (!client) {
@@ -65,22 +59,18 @@ export const provideRobotClientsContext = (
6559
connectionStatus[partID] ??= MachineConnectionEvent.DISCONNECTED;
6660

6761
try {
68-
await disconnect(partID, config);
69-
70-
connectionStatus[partID] = MachineConnectionEvent.CONNECTING;
71-
72-
// Reset the abort signal if it exists
73-
if (config.reconnectAbortSignal !== undefined) {
74-
config.reconnectAbortSignal = {
75-
abort: false,
76-
};
77-
}
62+
await disconnect(partID);
7863

7964
config.reconnectMaxAttempts ??= 1e9;
8065
config.reconnectMaxWait ??= 1000;
8166

82-
const client = await createRobotClient(config);
67+
const client = new RobotClient();
8368
(client as RobotClient & { partID: string }).partID = partID;
69+
70+
clients[partID] = client;
71+
72+
connectionStatus[partID] = MachineConnectionEvent.CONNECTING;
73+
8474
client.on('connectionstatechange', async (event) => {
8575
connectionStatus[partID] = (
8676
event as { eventType: MachineConnectionEvent }
@@ -97,7 +87,8 @@ export const provideRobotClientsContext = (
9787
}
9888
});
9989

100-
clients[partID] = client;
90+
await client.dial(config);
91+
10192
connectionStatus[partID] = MachineConnectionEvent.CONNECTED;
10293
} catch (error) {
10394
console.error(error);
@@ -113,10 +104,8 @@ export const provideRobotClientsContext = (
113104
Object.keys(lastConfigs)
114105
);
115106

116-
lastConfigs = $state.snapshot(configs);
117-
118107
for (const partID of removed) {
119-
disconnect(partID, lastConfigs[partID]);
108+
disconnect(partID);
120109
}
121110

122111
for (const partID of added) {
@@ -134,6 +123,8 @@ export const provideRobotClientsContext = (
134123
connect(partID, config);
135124
}
136125
}
126+
127+
lastConfigs = $state.snapshot(configs);
137128
});
138129

139130
onMount(() => {

0 commit comments

Comments
 (0)