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