RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/humble/Concepts/Basic/About-Client-Libraries.html?highlight=rclnodejs#community-maintained
Apache License 2.0
325 stars 71 forks source link

Update typings to support pub-sub of serialized messages #706

Closed wayneparrott closed 4 years ago

wayneparrott commented 4 years ago

646 describes the need to support publishing and subscribing to a serialized message topic. The TypeScript typings need to be updated to reflect the api changes.

Reviewing the code for #703 & #704, I have identified the following touch points:

  1. Node#Options - add isRaw: boolean property
  2. Node#SubscriptionCallback = (message: Message) => void
  3. Publisher#publish(msg: Message)

Edit - deleted initial thoughts about SerializableMessage

I think by tightening up the following methods and type declarations using generic types we can support sending and receiving a Buffer as an alternative to a structured Message:

Example:

class Publisher<T extends MessageTypeClassName> extends Entity {
    publish(message: MessageType<T> | Buffer): void;
  }

Node#createPublisher<T extends MessageTypeClassName>(typeClass: T, topic: string, options?: Options): Publisher<T>

Node#createSubscription<T extends MessageTypeClassName>(
      typeClass: T,
      topic: string,
      options: Options,
      callback: SubscriptionCallback<T>
    ): Subscription;

type SubscriptionCallback<T extends MessageTypeClassName> = (message: MessageType<T> | Buffer) => void;

Looking for feedback. (@mattrichard, @koonpeng, ...)

minggangw commented 4 years ago

I have merged #703 & #704, so I think we could start the typescript part for the serialized messages, thanks!