subscribe method

Future<void> subscribe(
  1. SubscribeHandler subscribeHandler
)

Implementation

Future<void> subscribe(SubscribeHandler subscribeHandler) async {
  if (subscribeId == null) {
    // Create the listenable broadcast subscription stream.
    subscription = ros.stream;
    subscribeId = ros.requestSubscriber(name);
    await safeSend(Request(
      op: 'subscribe',
      id: subscribeId,
      type: type,
      topic: name,
      compression: compression,
      throttleRate: throttleRate,
      queueLength: queueLength,
    ));
    subscription!.listen((Map<String, dynamic> message) async {
      if (message['topic'] != name) {
        return;
      }
      await subscribeHandler(message['msg']);
    });
  }
}