Skip to content

Commit 15fe862

Browse files
authored
Replace ID counter with UUIDs (#1037)
* Replace id counter with UUIDs * Prefer template string for formatting
1 parent e996525 commit 15fe862

File tree

14 files changed

+79
-64
lines changed

14 files changed

+79
-64
lines changed

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default defineConfig(
2929
"@typescript-eslint/no-namespace": 0,
3030
// Plenty of APIs (like mocking APIs in Vitest) require empty functions to be declared.
3131
"@typescript-eslint/no-empty-function": 0,
32+
"prefer-template": 2,
3233
},
3334
},
3435
{

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"cbor-js": "^0.1.0",
4646
"eventemitter3": "^5.0.1",
4747
"pngparse": "^2.0.0",
48+
"uuid": "^13.0.0",
4849
"ws": "^8.0.0"
4950
},
5051
"directories": {

src/actionlib/ActionClient.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,31 @@ export default class ActionClient<
8686
// create the topics associated with actionlib
8787
this.feedbackListener = new Topic({
8888
ros: this.ros,
89-
name: this.serverName + "/feedback",
90-
messageType: this.actionName + "Feedback",
89+
name: `${this.serverName}/feedback`,
90+
messageType: `${this.actionName}Feedback`,
9191
});
9292

9393
this.statusListener = new Topic({
9494
ros: this.ros,
95-
name: this.serverName + "/status",
95+
name: `${this.serverName}/status`,
9696
messageType: "actionlib_msgs/GoalStatusArray",
9797
});
9898

9999
this.resultListener = new Topic({
100100
ros: this.ros,
101-
name: this.serverName + "/result",
102-
messageType: this.actionName + "Result",
101+
name: `${this.serverName}/result`,
102+
messageType: `${this.actionName}Result`,
103103
});
104104

105105
this.goalTopic = new Topic({
106106
ros: this.ros,
107-
name: this.serverName + "/goal",
108-
messageType: this.actionName + "Goal",
107+
name: `${this.serverName}/goal`,
108+
messageType: `${this.actionName}Goal`,
109109
});
110110

111111
this.cancelTopic = new Topic({
112112
ros: this.ros,
113-
name: this.serverName + "/cancel",
113+
name: `${this.serverName}/cancel`,
114114
messageType: "actionlib_msgs/GoalID",
115115
});
116116

src/actionlib/ActionListener.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ export default class ActionListener<
5555
// create the topics associated with actionlib
5656
const goalListener = new Topic<TGoal>({
5757
ros: this.ros,
58-
name: this.serverName + "/goal",
59-
messageType: this.actionName + "Goal",
58+
name: `${this.serverName}/goal`,
59+
messageType: `${this.actionName}Goal`,
6060
});
6161

6262
const feedbackListener = new Topic<{
6363
status: actionlib_msgs.GoalStatus;
6464
feedback: TFeedback;
6565
}>({
6666
ros: this.ros,
67-
name: this.serverName + "/feedback",
68-
messageType: this.actionName + "Feedback",
67+
name: `${this.serverName}/feedback`,
68+
messageType: `${this.actionName}Feedback`,
6969
});
7070

7171
const statusListener = new Topic<actionlib_msgs.GoalStatusArray>({
7272
ros: this.ros,
73-
name: this.serverName + "/status",
73+
name: `${this.serverName}/status`,
7474
messageType: "actionlib_msgs/GoalStatusArray",
7575
});
7676

@@ -79,8 +79,8 @@ export default class ActionListener<
7979
result: TResult;
8080
}>({
8181
ros: this.ros,
82-
name: this.serverName + "/result",
83-
messageType: this.actionName + "Result",
82+
name: `${this.serverName}/result`,
83+
messageType: `${this.actionName}Result`,
8484
});
8585

8686
goalListener.subscribe((goalMessage) => {

src/actionlib/Goal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { EventEmitter } from "eventemitter3";
77
import ActionClient from "./ActionClient";
88
import { actionlib_msgs } from "../types/actionlib_msgs";
9+
import { v4 as uuidv4 } from "uuid";
910

1011
/**
1112
* An actionlib goal that is associated with an action server.
@@ -28,7 +29,7 @@ export default class Goal<
2829
result?: TResult = undefined;
2930
feedback?: TFeedback = undefined;
3031
// Create a random ID
31-
goalID = `goal_${Math.random().toString()}_${new Date().getTime().toString()}`;
32+
goalID = `goal_${uuidv4()}`;
3233
actionClient: ActionClient<TGoal, TFeedback, TResult>;
3334
goalMessage: { goal: TGoal; goal_id: actionlib_msgs.GoalID };
3435
/**

0 commit comments

Comments
 (0)