Skip to content

Commit 7d96ed2

Browse files
committed
Address comments
1 parent b62ea95 commit 7d96ed2

90 files changed

Lines changed: 1918 additions & 2237 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmark/rclnodejs/service/client-stress-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
'use strict';
16-
1715
/* eslint-disable camelcase */
18-
const { program } = require('commander');
19-
const rclnodejs = require('../../../index.js');
16+
import { program } from 'commander';
17+
import rclnodejs from '../../../index.js';
2018

2119
program
2220
.option('-r, --run <n>', 'How many times to run', '1')

benchmark/rclnodejs/service/service-stress-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
'use strict';
16-
1715
/* eslint-disable camelcase */
18-
const { program } = require('commander');
19-
const rclnodejs = require('../../../index.js');
16+
import { program } from 'commander';
17+
import rclnodejs from '../../../index.js';
2018

2119
program
2220
.option('-s, --size <size_kb>', 'The block size in KB', '1')

benchmark/rclnodejs/topic/publisher-stress-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
'use strict';
16-
1715
/* eslint-disable camelcase */
18-
const { program } = require('commander');
19-
const rclnodejs = require('../../../index.js');
16+
import { program } from 'commander';
17+
import rclnodejs from '../../../index.js';
2018

2119
program
2220
.option('-s, --size <size_kb>', 'The block size', '1')

benchmark/rclnodejs/topic/subscription-stress-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
'use strict';
16-
17-
const rclnodejs = require('../../../index.js');
15+
import rclnodejs from '../../../index.js';
1816

1917
async function main() {
2018
try {

demo/rosocket/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ library required.
1111
- Subscribe to and publish on `/chatter` (`std_msgs/msg/String`).
1212
- Call `/add_two_ints` (`example_interfaces/srv/AddTwoInts`) — the
1313
service implementation lives in
14-
[`example/services/service/service-example.cjs`](../../example/services/service/service-example.cjs)
14+
[`example/services/service/service-example.mjs`](../../example/services/service/service-example.mjs)
1515
and is launched in a second terminal.
1616

1717
## Layout
1818

19-
- `server.cjs``rclnodejs` node + `startRosocket` bridge only.
19+
- `server.mjs``rclnodejs` node + `startRosocket` bridge only.
2020
- `index.html` — single-file browser client using only built-in
2121
`WebSocket` and `JSON`.
2222

@@ -27,12 +27,12 @@ library required.
2727
source /opt/ros/$ROS_DISTRO/setup.bash
2828

2929
# 2. Terminal A — start the WebSocket gateway
30-
node demo/rosocket/server.cjs
30+
node demo/rosocket/server.mjs
3131
# [rosocket-demo] listening on ws://localhost:9000 (bind=0.0.0.0)
3232

3333
# 3. Terminal B — start the AddTwoInts service so the browser has
3434
# something to call
35-
node example/services/service/service-example.cjs
35+
node example/services/service/service-example.mjs
3636
```
3737

3838
The server binds to `0.0.0.0:9000` so it is reachable from any host

demo/rosocket/server.cjs

Lines changed: 0 additions & 78 deletions
This file was deleted.

demo/rosocket/server.mjs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) 2026 RobotWebTools Contributors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
9+
// rosocket demo server.
10+
//
11+
// Bridges two ROS 2 endpoints to plain WebSocket URLs so a browser can
12+
// drive them with built-in `WebSocket` + `JSON`, no client library:
13+
//
14+
// ws://<host>:9000/topic/chatter std_msgs/msg/String
15+
// ws://<host>:9000/service/add_two_ints example_interfaces/srv/AddTwoInts
16+
//
17+
// Run inside WSL (where ROS 2 is sourced):
18+
// node demo/rosocket/server.mjs
19+
//
20+
// To exercise the service, start the existing AddTwoInts example in a
21+
// second terminal (it implements `/add_two_ints`):
22+
// node example/services/service/service-example.mjs
23+
//
24+
// Then open demo/rosocket/index.html on the Windows host browser. WSL2
25+
// forwards localhost so `ws://localhost:9000` works as-is. See README.md
26+
// for fallback instructions.
27+
28+
import rclnodejs from '../../index.js';
29+
import { startRosocket } from '../../rosocket/index.js';
30+
31+
const PORT = Number(process.env.PORT) || 9000;
32+
const HOST = process.env.HOST || '0.0.0.0';
33+
34+
await rclnodejs.init();
35+
const node = rclnodejs.createNode('rosocket_demo_node');
36+
rclnodejs.spin(node);
37+
38+
const bridge = await startRosocket({
39+
node,
40+
port: PORT,
41+
host: HOST,
42+
topicTypes: {
43+
'/chatter': 'std_msgs/msg/String',
44+
},
45+
serviceTypes: {
46+
'/add_two_ints': 'example_interfaces/srv/AddTwoInts',
47+
},
48+
});
49+
50+
const displayHost = HOST === '0.0.0.0' || HOST === '::' ? 'localhost' : HOST;
51+
const baseUrl = `ws://${displayHost}:${bridge.port}`;
52+
console.log(
53+
`[rosocket-demo] listening on ${baseUrl} (bind=${HOST}:${bridge.port})`
54+
);
55+
console.log('[rosocket-demo] endpoints:');
56+
console.log(` ${baseUrl}/topic/chatter`);
57+
console.log(` ${baseUrl}/service/add_two_ints`);
58+
console.log('Open demo/rosocket/index.html in the host browser to try it.');
59+
60+
const shutdown = () => {
61+
bridge.close().finally(() => {
62+
try {
63+
rclnodejs.shutdown();
64+
} catch (_) {}
65+
process.exit(0);
66+
});
67+
};
68+
process.on('SIGINT', shutdown);
69+
process.on('SIGTERM', shutdown);

demo/web/javascript/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ cd demo/web/javascript
1414

1515
```bash
1616
source /opt/ros/<distro>/setup.bash
17-
node runtime.cjs
17+
node runtime.mjs
1818
# rclnodejs/web : ws://localhost:9000/capability
1919
# also http://localhost:9001/capability (call/publish, curl-able)
2020
```
2121

22-
`runtime.cjs` exposes a tiny `/add_two_ints` service + 1 Hz
22+
`runtime.mjs` exposes a tiny `/add_two_ints` service + 1 Hz
2323
`/web_demo_tick` publisher so every panel has live data.
2424

2525
**Shell 2 — static-file server (hosts `index.html` + maps `/sdk/*` to
2626
the in-repo [`web/`](../../../web/) folder so the page can `import`
2727
the SDK from a plain URL):**
2828

2929
```bash
30-
node static.cjs
30+
node static.mjs
3131
# Static files : http://localhost:8080/
3232
```
3333

@@ -67,18 +67,18 @@ curl -sS -X POST http://localhost:9001/capability/call/add_two_ints \
6767

6868
Subscribe stays on WebSocket.
6969

70-
## Without the bundled `runtime.cjs`
70+
## Without the bundled `runtime.mjs`
7171

72-
`runtime.cjs` bundles the rclnodejs/web runtime and the demo's sample
72+
`runtime.mjs` bundles the rclnodejs/web runtime and the demo's sample
7373
ROS 2 nodes (the `/add_two_ints` service + the `/web_demo_tick`
7474
publisher) into one process so the demo runs out of the box. In a
7575
real project you already have those ROS 2 nodes running elsewhere,
76-
so you only need the runtime. **Replace shell 1's `node runtime.cjs`
77-
with the CLI** — shell 2 (`node static.cjs`) and the browser code are
76+
so you only need the runtime. **Replace shell 1's `node runtime.mjs`
77+
with the CLI** — shell 2 (`node static.mjs`) and the browser code are
7878
unchanged:
7979

8080
```bash
81-
# shell 1 (instead of `node runtime.cjs`); the `-p rclnodejs` tells npx
81+
# shell 1 (instead of `node runtime.mjs`); the `-p rclnodejs` tells npx
8282
# the `rclnodejs-web` binary lives inside the `rclnodejs` package:
8383
npx -p rclnodejs rclnodejs-web web.json
8484

0 commit comments

Comments
 (0)