Skip to content

Commit 0df855c

Browse files
committed
Address comments
1 parent ca1640b commit 0df855c

4 files changed

Lines changed: 41 additions & 8 deletions

File tree

web_bridge/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Notes:
5151
echo the same shape (`{"id":"c1","response":{...}}`).
5252
- Errors are reported as `{"error":"<message>"}` frames; fatal protocol errors
5353
cause the socket to close with a `1008`/`1011` code.
54-
- 64-bit integer fields may be sent as JSON numbers, BigInt-encoded strings
55-
(`"12n"`), or decimal strings; responses use the rclnodejs `toJSONSafe`
56-
encoding (BigInts become `"<n>n"` strings).
54+
- 64-bit integer fields may be sent as JSON numbers or BigInt-encoded
55+
strings (`"12n"`); responses use the rclnodejs `toJSONSafe` encoding
56+
(BigInts become `"<n>n"` strings).
5757
5858
## Server side
5959

web_bridge/bridge.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function parseResourcePath(pathname) {
7272
* @param {string} [options.host='0.0.0.0'] - Host to bind to.
7373
* @param {Object<string,string>} [options.topicTypes] - Optional default type per topic name (e.g. {"/chatter":"std_msgs/msg/String"}).
7474
* @param {Object<string,string>} [options.serviceTypes] - Optional default type per service name.
75-
* @param {(req: import('http').IncomingMessage) => boolean} [options.verifyClient] - Optional auth hook.
75+
* @param {(req: import('http').IncomingMessage) => boolean} [options.verifyClient] - Optional auth hook called with the raw HTTP upgrade request; return `false` to reject the connection.
7676
* @returns {Promise<{wss: WebSocketServer, close: () => Promise<void>, port: number}>}
7777
*/
7878
function startWebBridge(options = {}) {
@@ -87,8 +87,19 @@ function startWebBridge(options = {}) {
8787

8888
if (!node) throw new TypeError('startWebBridge: options.node is required');
8989

90+
// ws's verifyClient is invoked with `info = { origin, secure, req }`,
91+
// not the raw IncomingMessage. Wrap it so users can write a simple
92+
// `(req) => boolean` hook as documented above.
93+
const wsVerifyClient = verifyClient
94+
? (info) => verifyClient(info.req)
95+
: undefined;
96+
9097
return new Promise((resolve, reject) => {
91-
const wss = new WebSocketServer({ host, port, verifyClient });
98+
const wss = new WebSocketServer({
99+
host,
100+
port,
101+
verifyClient: wsVerifyClient,
102+
});
92103

93104
wss.on('error', reject);
94105

web_bridge/cli.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,19 @@ function parseArgs(argv) {
6969
process.exit(0);
7070
break;
7171
case '-p':
72-
case '--port':
73-
opts.port = Number(need(i, a));
72+
case '--port': {
73+
const raw = need(i, a);
74+
const p = Number(raw);
75+
if (!Number.isInteger(p) || p < 0 || p > 65535) {
76+
console.error(
77+
`error: ${a} expects an integer in 0–65535, got "${raw}"`
78+
);
79+
process.exit(2);
80+
}
81+
opts.port = p;
7482
i++;
7583
break;
84+
}
7685
case '-H':
7786
case '--host':
7887
opts.host = need(i, a);

web_bridge/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
// Copyright (c) 2026 RobotWebTools. Apache-2.0.
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+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
215
'use strict';
316

417
const { startWebBridge } = require('./bridge.js');

0 commit comments

Comments
 (0)