Skip to content

Commit db2a685

Browse files
authored
Add getNodeNamesAndNamespaces to Node (#566)
Fix getNodeNames return type and adds getNodeNamesAndNamespaces to align with the interface of Node in rclpy more closely. Fix #None
1 parent 9db8939 commit db2a685

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

lib/node.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,17 @@ class Node {
501501

502502
/**
503503
* Get the list of nodes discovered by the provided node.
504-
* @return {array} - An array of the names and namespaces.
504+
* @return {array} - An array of the names.
505505
*/
506506
getNodeNames() {
507+
return this.getNodeNamesAndNamespaces().map(item => item.name);
508+
}
509+
510+
/**
511+
* Get the list of nodes and their namespaces discovered by the provided node.
512+
* @return {array} - An array of the names and namespaces.
513+
*/
514+
getNodeNamesAndNamespaces() {
507515
return rclnodejs.getNodeNames(this.handle);
508516
}
509517

test/test-node.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ describe('rcl node methods testing', function() {
308308
it('node.getNodeNames', function() {
309309
var nodeNames = node.getNodeNames();
310310

311+
var currentNode = nodeNames.indexOf('my_node');
312+
313+
assert.notStrictEqual(currentNode, -1);
314+
});
315+
316+
it('node.getNodeNamesAndNamespaces', function() {
317+
var nodeNames = node.getNodeNamesAndNamespaces();
318+
311319
var currentNode = nodeNames.find(function(nodeName) {
312320
return nodeName.name === 'my_node';
313321
});

test/types/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ node.getSubscriptionNamesAndTypesByNode(NODE_NAME);
5555
// $ExpectType NamesAndTypesQueryResult[]
5656
node.getTopicNamesAndTypes();
5757

58-
// $ExpectType NodeNamesQueryResult[]
58+
// $ExpectType string[]
5959
node.getNodeNames();
6060

61+
// $ExpectType NodeNamesQueryResult[]
62+
node.getNodeNamesAndNamespaces();
63+
6164
// $ExpectType number
6265
node.countPublishers(TOPIC);
6366

types/node.d.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,22 @@ declare module 'rclnodejs' {
337337
/**
338338
* Get the list of nodes discovered by the provided node.
339339
*
340-
* @returns An array of the names and namespaces.
341-
* [
342-
* { name: 'gazebo', namespace: '/' },
343-
* { name: 'robot_state_publisher', namespace: '/' },
344-
* { name: 'cam2image', namespace: '/demo' }
345-
* ]
340+
* @returns An array of the node names.
346341
*/
347-
getNodeNames(): Array<NodeNamesQueryResult>;
348-
342+
getNodeNames(): string[];
343+
344+
/**
345+
* Get the list of nodes and their namespaces discovered by the provided node.
346+
*
347+
* @returns An array of the node names and namespaces.
348+
* [
349+
* { name: 'gazebo', namespace: '/' },
350+
* { name: 'robot_state_publisher', namespace: '/' },
351+
* { name: 'cam2image', namespace: '/demo' }
352+
* ]
353+
*/
354+
getNodeNamesAndNamespaces(): Array<NodeNamesQueryResult>;
355+
349356
/**
350357
* Return the number of publishers on a given topic.
351358
* @param topic - The name of the topic.

0 commit comments

Comments
 (0)