Add Observable subscriptions with RxJS support#1357
Conversation
7003b5b to
e35eff1
Compare
minggangw
left a comment
There was a problem hiding this comment.
Thanks for submitting the PR, the implementation looks elegant! Some comments left, thanks!
| if (typeof typeClass === 'string' || typeof typeClass === 'object') { | ||
| typeClass = loader.loadInterface(typeClass); | ||
| } | ||
|
|
||
| options = this._validateOptions(options); | ||
|
|
||
| if (typeof typeClass !== 'function') { | ||
| throw new TypeValidationError('typeClass', typeClass, 'function', { | ||
| nodeName: this.name(), | ||
| entityType: 'subscription', | ||
| }); | ||
| } | ||
| if (typeof topic !== 'string') { | ||
| throw new TypeValidationError('topic', topic, 'string', { | ||
| nodeName: this.name(), | ||
| entityType: 'subscription', | ||
| }); | ||
| } | ||
| if ( | ||
| eventCallbacks && | ||
| !(eventCallbacks instanceof SubscriptionEventCallbacks) | ||
| ) { | ||
| throw new TypeValidationError( | ||
| 'eventCallbacks', | ||
| eventCallbacks, | ||
| 'SubscriptionEventCallbacks', | ||
| { | ||
| nodeName: this.name(), | ||
| entityType: 'subscription', | ||
| entityName: topic, | ||
| } | ||
| ); | ||
| } |
| obsSub.observable | ||
| .pipe( | ||
| map((msg) => msg.data), | ||
| filter((data) => data.includes('ROS')) |
There was a problem hiding this comment.
As the ROS2 DDS also supports subscription content filtering, which is more efficient I believe, shall we point out the difference between the two filter?
There was a problem hiding this comment.
I have updated the readme to have an example for content filter + RxJS
minggangw
left a comment
There was a problem hiding this comment.
LGTM, thanks for your contributions!
|
@mahmoud-ghalayini I deem the feature implemented by this PR is worth being promoted, can you please add an short description of it into https://github.com/RobotWebTools/rclnodejs/blob/develop/README.md and link it to tutorials/observable-subscriptions.md if the users want to understand more details. |
afeeae4
into
RobotWebTools:develop
• Added createObservableSubscription() method to Node class • Returns ObservableSubscription with RxJS Observable for ROS 2 messages • Enables reactive programming with operators like throttleTime(), debounceTime(), map(), combineLatest() • New ObservableSubscription class exported from rclnodejs
Public API Changes
New method on
Node:New exported class
ObservableSubscription:observableObservable<T>subscriptionSubscriptiontopicstringisDestroyedbooleancomplete()voiddestroy()voidcomplete()New dependency:
rxjs@^7.8.1#1347