Skip to content

Commit 0960539

Browse files
committed
Update README.md
1 parent e4c69ba commit 0960539

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ how much glue you want to write.
124124
streaming as Server-Sent Events (`GET .../capability/subscribe/<name>`) —
125125
so shell scripts, Postman, AI-agent tool-use, and even a bare browser
126126
`fetch()` / `EventSource` (CORS-enabled) just work.
127-
_New in `2.0.0-beta.0`._
128127

129128
```ts
130129
import { connect } from 'rclnodejs/web';
@@ -137,7 +136,6 @@ how much glue you want to write.
137136
- **[`rosocket`](./rosocket/README.md)** — thin WebSocket gateway,
138137
zero browser dependencies (just built-in `WebSocket` + `JSON`).
139138
Best for quick prototypes and `roslibjs`-style apps.
140-
_New in `2.0.0-beta.0`._
141139

142140
```bash
143141
npx rosocket --port 9000 --topic /chatter:std_msgs/msg/String

scripts/npmjs-readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Then `import * as rclnodejs from 'rclnodejs'` works the same as the JavaScript e
100100

101101
`rclnodejs` ships **two** ways to reach ROS 2 from the browser — pick one based on how much glue you want to write.
102102

103-
- **`rclnodejs/web`** — typed, allow-listed, `curl`-able browser SDK. A `web.json` file is your public API; the browser SDK types `call` / `publish` / `subscribe` end-to-end from your ROS 2 message types; every capability is also a plain HTTP endpoint (`curl -X POST http://<host>/capability/call/<name>`), so shell scripts, Postman, and AI-agent tool-use just work. _New in `2.0.0-beta.0`._
103+
- **`rclnodejs/web`** — typed, allow-listed, `curl`-able browser SDK. A `web.json` file is your public API; the browser SDK types `call` / `publish` / `subscribe` end-to-end from your ROS 2 message types; every capability is also a plain HTTP endpoint (`curl -X POST http://<host>/capability/call/<name>`), with `subscribe` streaming as Server-Sent Events (`GET http://<host>/capability/subscribe/<name>`), so shell scripts, Postman, AI-agent tool-use, and a bare browser `fetch()` / `EventSource` (CORS-enabled) just work.
104104

105105
```ts
106106
import { connect } from 'rclnodejs/web';

web/README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ window.addEventListener('beforeunload', () => ros.close());
130130

131131
When `--http-port` is on, every `call` / `publish` is reachable from
132132
any HTTP client — curl, Postman, AI-agent tool-use, no SDK required.
133-
Subscribe stays on WebSocket.
133+
With `--http-sse` (or `"http": { "sse": true }`), `subscribe` is also
134+
reachable over HTTP as a Server-Sent Events stream.
134135

135136
```bash
136137
# Service call
@@ -143,6 +144,29 @@ curl -sS -X POST http://localhost:9001/capability/call/add_two_ints \
143144
curl -sS -X POST http://localhost:9001/capability/publish/chatter \
144145
-H 'content-type: application/json' \
145146
-d '{"data":"hi from curl"}'
147+
148+
# Subscribe over Server-Sent Events (needs --http-sse). Streams until
149+
# you disconnect; -N keeps curl from buffering the event stream.
150+
curl -N http://localhost:9001/capability/subscribe/chatter
151+
# event: ready
152+
# data: {"capability":"/chatter","subId":"sse"}
153+
#
154+
# event: message
155+
# data: {"data":"hello"}
156+
```
157+
158+
From a browser, the same SSE endpoint works with the built-in
159+
`EventSource` (cross-origin when `--http-cors` is set):
160+
161+
```js
162+
const es = new EventSource(
163+
'http://localhost:9001/capability/subscribe/chatter'
164+
);
165+
es.addEventListener('message', (e) => {
166+
const msg = JSON.parse(e.data);
167+
console.log(msg.data);
168+
});
169+
es.addEventListener('error', () => es.close());
146170
```
147171

148172
## 4. `rclnodejs/web` vs. `rosbridge` + `roslibjs`

0 commit comments

Comments
 (0)