This commit is contained in:
LiXiaoqi 2024-11-21 15:00:51 +08:00
parent ba2369623b
commit e02f4bf6d8

View File

@ -100,7 +100,7 @@ class Topic {
if (subscribeId == null) {
// Create the listenable broadcast subscription stream.
subscription = ros.stream;
subscribeId = ros.requestSubscriber(name);
await safeSend(Request(
op: 'subscribe',
id: subscribeId,
@ -144,11 +144,11 @@ class Topic {
Future<void> publish(dynamic message) async {
// Advertise the topic and then send the publish request.
await advertise();
publishId = ros.requestPublisher(name);
await safeSend(publishReq(message));
}
Request publishReq(dynamic message) {
publishId = ros.requestPublisher(name);
return Request(
op: 'publish',
topic: name,
@ -162,7 +162,6 @@ class Topic {
Future<void> advertise() async {
if (!isAdvertised) {
// Send the advertisement request.
advertiseId = ros.requestAdvertiser(name);
await safeSend(advertiseReq());
// If the ROS connection closes show that we're not advertising anymore.
watchForClose();
@ -170,6 +169,7 @@ class Topic {
}
Request advertiseReq() {
advertiseId = ros.requestAdvertiser(name);
return Request(
op: 'advertise',
id: advertiseId,