@@ -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
6464curl -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
7574curl -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
10498source /opt/ros/< distro> /setup.bash
10599node ../../../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
116102curl -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:
137116npx -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):
140120ros2 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`).
0 commit comments