Skip to content

Commit c0a9f18

Browse files
committed
Address comments
1 parent b132967 commit c0a9f18

2 files changed

Lines changed: 38 additions & 65 deletions

File tree

demo/web/javascript/README.md

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,18 @@ can flip the SDK between the two without restarting.
5757

5858
## Same capability, no SDK
5959

60-
Every `call` / `publish` is also reachable as plain HTTP — drive the
61-
runtime from `curl`, Postman, or an AI agent without any JavaScript:
60+
Every `call` / `publish` is reachable as plain HTTP — drive the runtime
61+
from `curl`, Postman, or an AI agent, no JavaScript required:
6262

6363
```bash
6464
curl -sS -X POST http://localhost:9001/capability/call/add_two_ints \
65-
-H 'content-type: application/json' \
66-
-d '{"a":"7n","b":"35n"}'
65+
-H 'content-type: application/json' -d '{"a":"7n","b":"35n"}'
6766
# => {"sum":"42n"}
6867
```
6968

70-
This demo's `runtime.mjs` also enables SSE (`new HttpTransport({ sse: true })`),
71-
so `subscribe` is reachable over HTTP as a `text/event-stream`useful for
72-
clients that can't hold a WebSocket open:
69+
The demo also enables SSE (`new HttpTransport({ sse: true })`), so
70+
`subscribe` works over HTTP as a `text/event-stream`handy for clients
71+
that can't hold a WebSocket open:
7372

7473
```bash
7574
curl -N http://localhost:9001/capability/subscribe/web_demo_chatter
@@ -78,70 +77,50 @@ curl -N http://localhost:9001/capability/subscribe/web_demo_chatter
7877
#
7978
# event: message
8079
# data: {"data":"hi from curl"}
81-
# …one `message` event per published sample, until you ^C
8280
```
8381

84-
Browser apps should still prefer the WebSocket transport for `subscribe`
85-
(one connection multiplexes every topic). SSE subscribe targets the
86-
curl / AI-agent / server-side persona.
82+
The page's **native `EventSource` panel** (section 6) reads this same
83+
stream — no SDK, no WebSocket. It works cross-origin (`:8080``:9001`)
84+
because the demo also enables CORS (`new HttpTransport({ sse: true, cors:
85+
true })`); in production, pass your site's origin instead of `true`.
8786

88-
The page also has a **native `EventSource` panel** (section 6) that
89-
subscribes to `/web_demo_chatter` over the same SSE endpoint — no SDK, no
90-
WebSocket, just the browser primitive over plain HTTP. Because the page
91-
(`:8080`) and the HTTP transport (`:9001`) are different origins, the
92-
demo's `runtime.mjs` enables CORS (`new HttpTransport({ sse: true, cors:
93-
true })`) so the cross-origin `EventSource` is allowed. In production,
94-
pass your site's origin instead of `true`.
87+
> For browser apps, prefer the WebSocket transport for `subscribe` — one
88+
> connection multiplexes every topic. SSE targets the curl / AI-agent /
89+
> server-side persona.
9590
96-
### Pair it with the stock publisher example
91+
### Pair it with your own publisher
9792

98-
The EventSource panel's topic box defaults to `/web_demo_chatter` (the
99-
shared demo topic), but the runtime also exposes `/topic` so you can
100-
feed the demo from your own node. In a third shell, run the standard
101-
publisher example:
93+
The runtime also exposes `/topic`, so you can feed the demo from any ROS 2
94+
node instead of the in-page publisher. Run the stock publisher example in
95+
a third shell, then point the EventSource panel (or `curl`) at `/topic`:
10296

10397
```bash
10498
source /opt/ros/<distro>/setup.bash
10599
node ../../../example/topics/publisher/publisher-example.mjs
106-
# Publishing message: Hello ROS 0
107-
# Publishing message: Hello ROS 1
108-
#
109-
```
110-
111-
Then set the panel's topic box to `/topic` and click **open
112-
EventSource** — you'll see that node's `Hello ROS N` messages stream in.
113-
The same works over `curl`:
100+
# Publishing message: Hello ROS 0, 1, 2, …
114101

115-
```bash
116102
curl -N http://localhost:9001/capability/subscribe/topic
117103
# event: message
118104
# data: {"data":"Hello ROS 0"}
119105
```
120106

121-
This makes [`publisher-example.mjs`](../../../example/topics/publisher/publisher-example.mjs)
122-
and the web demo a ready-made publisher/subscriber pair for trying the
123-
web runtime against your own publishers.
124-
125107
## Without the bundled `runtime.mjs`
126108

127-
`runtime.mjs` bundles the rclnodejs/web runtime and the demo's sample
128-
ROS 2 nodes (the `/add_two_ints` service) into one process so the demo
129-
runs out of the box. In a real project you already have those ROS 2
130-
nodes running elsewhere, so you only need the runtime. **Replace shell
131-
1's `node runtime.mjs` with the CLI** — shell 2 (`node static.mjs`) and
132-
the browser code are unchanged:
109+
`runtime.mjs` bundles the runtime and the demo's sample nodes into one
110+
process so it runs out of the box. In a real project those nodes already
111+
run elsewhere, so you only need the runtime — replace shell 1 with the
112+
CLI (shell 2 and the browser code are unchanged):
133113

134114
```bash
135-
# shell 1 (instead of `node runtime.mjs`); the `-p rclnodejs` tells npx
136-
# the `rclnodejs-web` binary lives inside the `rclnodejs` package:
115+
# the `-p rclnodejs` tells npx the binary lives in the rclnodejs package:
137116
npx -p rclnodejs rclnodejs-web web.json
138117

139-
# the publisher / service the demo expects:
118+
# plus the service the demo expects (and any std_msgs/String publisher
119+
# on /web_demo_chatter):
140120
ros2 run demo_nodes_cpp add_two_ints_server
141-
# (and a publisher of std_msgs/String on /web_demo_chatter from any source)
142121
```
143122

144-
> Note: this demo enables the SSE subscribe endpoint programmatically in
145-
> `runtime.mjs` via `new HttpTransport({ sse: true, cors: true })`. The
146-
> `rclnodejs-web` CLI can do the same with `--http-sse` and `--http-cors`
147-
> (or `"http": { "sse": true, "cors": "*" }` in `web.json`).
123+
> The bundled `runtime.mjs` enables SSE + CORS via
124+
> `new HttpTransport({ sse: true, cors: true })`. The CLI does the same
125+
> with `--http-sse` / `--http-cors` (or `"http": { "sse": true, "cors":
126+
> "*" }` in `web.json`).

demo/web/typescript/README.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ npm run server
2626
# also http://localhost:9001/capability
2727
```
2828

29-
`server.ts` runs the runtime *and* a tiny `/add_two_ints` service +
30-
1 Hz `/web_demo_tick` publisher so every panel has live data.
29+
`server.ts` runs the runtime *plus* a tiny `/add_two_ints` service and a
30+
1 Hz `/web_demo_tick` publisher, so every panel has live data.
3131

3232
> The HTTP transport here serves `call` / `publish` only; `subscribe`
3333
> uses WebSocket. HTTP `subscribe` over Server-Sent Events is an opt-in
@@ -44,26 +44,20 @@ npm run dev
4444

4545
## Without the bundled `server.ts`
4646

47-
`npm run server` is a convenience for this demo — it bundles the
48-
runtime **and** a tiny `/add_two_ints` service + `/web_demo_tick`
49-
publisher into one process so the demo works out of the box.
50-
51-
In a real project you already have those ROS 2 nodes running
52-
elsewhere, so you only need the runtime. **Replace shell 1's
53-
`npm run server` with the CLI** — shell 2 (`npm run dev`) and
54-
`src/main.ts` are unchanged:
47+
`npm run server` bundles the runtime and the demo's sample nodes into one
48+
process so it runs out of the box. In a real project those nodes already
49+
run elsewhere, so you only need the runtime — replace shell 1 with the
50+
CLI (shell 2 and `src/main.ts` are unchanged):
5551

5652
```bash
57-
# shell 1 (instead of `npm run server`)
5853
npx rclnodejs-web web.json
5954

60-
# the publisher / service the demo expects:
55+
# plus the nodes the demo expects:
6156
ros2 run demo_nodes_cpp add_two_ints_server
62-
# (and a publisher of std_msgs/String on /web_demo_tick from any source)
57+
# (and any std_msgs/String publisher on /web_demo_tick)
6358
```
6459

65-
The browser doesn't know or care which option is running — it only
66-
sees `ws://localhost:9000/capability` either way.
60+
The browser only sees `ws://localhost:9000/capability` either way.
6761

6862
## Other npm scripts
6963

0 commit comments

Comments
 (0)