-
Notifications
You must be signed in to change notification settings - Fork 83
Add Observable subscriptions with RxJS support #1357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Observable subscriptions with RxJS support #1357
Conversation
7003b5b to
e35eff1
Compare
minggangw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting the PR, the implementation looks elegant! Some comments left, thanks!
lib/node.js
Outdated
| 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, | ||
| } | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lines above are dup with
Line 762 in 4a1b0db
| createSubscription(typeClass, topic, options, callback, eventCallbacks) { |
| obsSub.observable | ||
| .pipe( | ||
| map((msg) => msg.data), | ||
| filter((data) => data.includes('ROS')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the readme to have an example for content filter + RxJS
minggangw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Public API Changes
New method on
Node:New exported class
ObservableSubscription:observableObservable<T>subscriptionSubscriptiontopicstringisDestroyedbooleancomplete()voiddestroy()voidcomplete()New dependency:
rxjs@^7.8.1#1347