Skip to content

Conversation

@mahmoud-ghalayini
Copy link
Collaborator

Public API Changes

New method on Node:

createObservableSubscription<T>(
  typeClass: T,
  topic: string,
  options?: Options,
  eventCallbacks?: (event: object) => void
): ObservableSubscription<MessageType<T>>

New exported class ObservableSubscription:

Member Type Description
observable Observable<T> RxJS Observable emitting messages
subscription Subscription Underlying ROS 2 subscription
topic string Topic name
isDestroyed boolean Whether the observable has been completed
complete() void Complete the observable
destroy() void Alias for complete()

New dependency: rxjs@^7.8.1

#1347

@mahmoud-ghalayini mahmoud-ghalayini force-pushed the add-observable-subscriptions-with-rxjs-support-1347 branch from 7003b5b to e35eff1 Compare December 17, 2025 15:50
@coveralls
Copy link

coveralls commented Dec 17, 2025

Coverage Status

coverage: 80.454% (+0.05%) from 80.403%
when pulling 8b606c7 on mahmoud-ghalayini:add-observable-subscriptions-with-rxjs-support-1347
into 4a1b0db on RobotWebTools:develop.

Copy link
Member

@minggangw minggangw left a 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
Comment on lines 842 to 874
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,
}
);
}
Copy link
Member

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

createSubscription(typeClass, topic, options, callback, eventCallbacks) {

obsSub.observable
.pipe(
map((msg) => msg.data),
filter((data) => data.includes('ROS'))
Copy link
Member

@minggangw minggangw Dec 18, 2025

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?

Copy link
Collaborator Author

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

Copy link
Member

@minggangw minggangw left a 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!

@minggangw
Copy link
Member

@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.

@mahmoud-ghalayini mahmoud-ghalayini merged commit afeeae4 into RobotWebTools:develop Dec 18, 2025
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants