From 0421c25cd195cb2caec17c36cf89bb8d5ecf318a Mon Sep 17 00:00:00 2001 From: Minggang Wang Date: Mon, 29 Jun 2026 13:55:57 +0800 Subject: [PATCH 1/2] [docs] Demonstrate web-native SSE subscribe in READMEs --- README.md | 7 +++++++ scripts/npmjs-readme.md | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 060e3169..59d00998 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,13 @@ how much glue you want to write. ); // reply.sum is typed as `${number}n` ``` + No SDK needed for subscribe — any browser streams a live ROS 2 topic via built-in `EventSource`: + + ```js + const es = new EventSource('http://host:9000/capability/subscribe/chatter'); + es.onmessage = (e) => console.log(JSON.parse(e.data)); // live ROS 2 messages + ``` + - **[`rosocket`](./rosocket/README.md)** — thin WebSocket gateway, zero browser dependencies (just built-in `WebSocket` + `JSON`). Best for quick prototypes and `roslibjs`-style apps. diff --git a/scripts/npmjs-readme.md b/scripts/npmjs-readme.md index 7e6251f3..19eecd49 100644 --- a/scripts/npmjs-readme.md +++ b/scripts/npmjs-readme.md @@ -110,6 +110,13 @@ Then `import * as rclnodejs from 'rclnodejs'` works the same as the JavaScript e ); // reply.sum is typed as `${number}n` ``` + No SDK needed for subscribe — any browser streams a live ROS 2 topic via built-in `EventSource`: + + ```js + const es = new EventSource('http://host:9000/capability/subscribe/chatter'); + es.onmessage = (e) => console.log(JSON.parse(e.data)); // live ROS 2 messages + ``` + See the [Web SDK guide](https://github.com/RobotWebTools/rclnodejs/tree/develop/web). - **`rosocket`** — thin WebSocket gateway, zero browser dependencies (just built-in `WebSocket` + `JSON`). Best for quick prototypes and `roslibjs`-style apps. From 30ebf436616d9ebe6abe7207b2f80c85ccccbfce Mon Sep 17 00:00:00 2001 From: Minggang Wang Date: Mon, 29 Jun 2026 14:03:23 +0800 Subject: [PATCH 2/2] Address comments --- README.md | 4 ++-- scripts/npmjs-readme.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 59d00998..16bd21d6 100644 --- a/README.md +++ b/README.md @@ -133,10 +133,10 @@ how much glue you want to write. ); // reply.sum is typed as `${number}n` ``` - No SDK needed for subscribe — any browser streams a live ROS 2 topic via built-in `EventSource`: + No SDK needed for subscribe — with the HTTP/SSE transport enabled (`--http-sse`, plus `--http-cors` for cross-origin), any browser streams a live ROS 2 topic via built-in `EventSource`: ```js - const es = new EventSource('http://host:9000/capability/subscribe/chatter'); + const es = new EventSource('http://host:9001/capability/subscribe/chatter'); es.onmessage = (e) => console.log(JSON.parse(e.data)); // live ROS 2 messages ``` diff --git a/scripts/npmjs-readme.md b/scripts/npmjs-readme.md index 19eecd49..cd9584cd 100644 --- a/scripts/npmjs-readme.md +++ b/scripts/npmjs-readme.md @@ -110,10 +110,10 @@ Then `import * as rclnodejs from 'rclnodejs'` works the same as the JavaScript e ); // reply.sum is typed as `${number}n` ``` - No SDK needed for subscribe — any browser streams a live ROS 2 topic via built-in `EventSource`: + No SDK needed for subscribe — with the HTTP/SSE transport enabled (`--http-sse`, plus `--http-cors` for cross-origin), any browser streams a live ROS 2 topic via built-in `EventSource`: ```js - const es = new EventSource('http://host:9000/capability/subscribe/chatter'); + const es = new EventSource('http://host:9001/capability/subscribe/chatter'); es.onmessage = (e) => console.log(JSON.parse(e.data)); // live ROS 2 messages ```