From 285783b518870eaecfc4d3199ccaf14338e59c94 Mon Sep 17 00:00:00 2001 From: hello-amal Date: Tue, 16 Jul 2024 17:14:33 -0700 Subject: [PATCH 1/2] Add getPublishers function --- src/core/Ros.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/core/Ros.js b/src/core/Ros.js index e7fa5155a..ecc01fa70 100644 --- a/src/core/Ros.js +++ b/src/core/Ros.js @@ -280,6 +280,40 @@ export default class Ros extends EventEmitter { }); } } + /** + * Retrieve a list of active publishers for a topic in ROS. + * + * @param {string} topic - The topic to find publishers for. + * @param {function} callback - Function with the following params: + * @param {string[]} callback.publishers - Array of publisher names. + * @param {function} [failedCallback] - The callback function when the service call failed with params: + * @param {string} failedCallback.error - The error message reported by ROS. + */ + Ros.prototype.getPublishers = function(topic, callback, failedCallback) { + var publishersClient = new Service({ + ros : this, + name : '/rosapi/publishers', + serviceType : 'rosapi/Publishers' + }); + + var request = new ServiceRequest({ + 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. From 77b7e9df46b298b0b0a55931f07c523671cb0733 Mon Sep 17 00:00:00 2001 From: Amal Nanavati Date: Tue, 16 Jul 2024 17:25:37 -0700 Subject: [PATCH 2/2] Fixes to conform to style --- src/core/Ros.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/core/Ros.js b/src/core/Ros.js index ecc01fa70..643fe4234 100644 --- a/src/core/Ros.js +++ b/src/core/Ros.js @@ -281,24 +281,30 @@ export default class Ros extends EventEmitter { } } /** - * Retrieve a list of active publishers for a topic in ROS. + * @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 {function} callback - Function with the following params: - * @param {string[]} callback.publishers - Array of publisher names. - * @param {function} [failedCallback] - The callback function when the service call failed with params: - * @param {string} failedCallback.error - The error message reported by ROS. + * @param {getPublishersCallback} callback - Function with the following params: + * @param {getPublishersFailedCallback} [failedCallback] - The callback function when the service call failed with params: */ - Ros.prototype.getPublishers = function(topic, callback, failedCallback) { + getPublishers(topic, callback, failedCallback) { var publishersClient = new Service({ - ros : this, - name : '/rosapi/publishers', - serviceType : 'rosapi/Publishers' + ros: this, + name: '/rosapi/publishers', + serviceType: 'rosapi/Publishers' }); - var request = new ServiceRequest({ + var request = { topic: topic - }); + }; if (typeof failedCallback === 'function'){ publishersClient.callService(request, function(result) {