Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a getPublishers method to the ROS class #760

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/core/Ros.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,46 @@ export default class Ros extends EventEmitter {
});
}
}
/**
* @callback getPublishersCallback
* @param {string[]} publishers - Array of publisher names.
*/
/**
* @callback getPublishersFailedCallback
* @param {string} error - The error message reported by ROS.
*/
/**
* Retrieve a list of active publishers in ROS.
*
* @param {string} topic - The topic to find publishers for.
* @param {getPublishersCallback} callback - Function with the following params:
* @param {getPublishersFailedCallback} [failedCallback] - The callback function when the service call failed with params:
*/
getPublishers(topic, callback, failedCallback) {
var publishersClient = new Service({
ros: this,
name: '/rosapi/publishers',
serviceType: 'rosapi/Publishers'
});

var request = {
topic: topic
};
if (typeof failedCallback === 'function'){
publishersClient.callService(request,
function(result) {
callback(result.publishers);
},
function(message){
failedCallback(message);
}
);
} else {
publishersClient.callService(request, function(result) {
callback(result.publishers);
});
}
}
/**
* @callback getServicesCallback
* @param {string[]} services - Array of service names.
Expand Down