Skip to content

Commit

Permalink
Copy getPublishers in for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hello-amal committed Jul 17, 2024
1 parent 22c537f commit c99ee17
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/pages/robot/tsx/robot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,21 @@ export class Robot extends React.Component {
],
timeout_ms: number = 5000,
): Promise<boolean> {
// For backwards compatibility with older versions of roslibjs, use the
// local copy of getPublishers if the ROS object does not have it.
let getPublishers = this.getPublishers.bind(this);
if (this.ros.getPublishers !== undefined) {
getPublishers = this.ros.getPublishers.bind(this.ros);
}

let numRequiredTopicsWithPublisher = 0;
let isResolved = false;
console.log("Checking ROS connection...");
return new Promise(async (resolve) => {
if (this.ros.isConnected) {
for (let topic of required_topics) {
// Verify that the topic has a publisher
this.ros.getPublishers(
getPublishers(
topic,
// Success callback
(publishers: string[]) => {
Expand Down Expand Up @@ -1097,4 +1104,38 @@ export class Robot extends React.Component {
// Send an empty string and override behavior 1 to interrupt the current speech
this.playTextToSpeech("", 1);
}

/**
* Copied from https://github.com/hello-vinitha/roslibjs/pull/1 and
* https://github.com/RobotWebTools/roslibjs/pull/760 , included here for
* backwards compatibility.
*/
getPublishers(
topic: string,
callback: (publishers: string[]) => void,
failedCallback: (message: any) => void,
) {
var publishersClient = new ROSLIB.Service({
ros: this.ros,
name: "/rosapi/publishers",
serviceType: "rosapi_msgs/srv/Publishers",
});

var request = new ROSLIB.ServiceRequest({
topic: topic,
});
if (typeof failedCallback === "function") {
publishersClient.callService(
request,
function (result: any) {
callback(result.publishers);
},
failedCallback,
);
} else {
publishersClient.callService(request, function (result) {
callback(result.publishers);
});
}
}
}

0 comments on commit c99ee17

Please sign in to comment.