Skip to content

Commit be2d0ea

Browse files
authored
Allow start_robot_browser.js to take a command line port (#117)
* Allow specifying robot browser port via command line to simplify startup instructions * Updated README * Add serve instructions to README
1 parent 8214158 commit be2d0ea

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

feedingwebapp/.env

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# from screens that would otherwise wait for ROS messages).
33
REACT_APP_DEBUG=false
44

5-
# The port to launch the app on
6-
REACT_APP_PORT=3000
75
# The port for the WebRTC signalling server
86
REACT_APP_SIGNALLING_SERVER_PORT=5000
97
# The port of the rosbridge server (default: 9090)

feedingwebapp/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The overall user flow for this robot can be seen below.
1212

1313
## Dependencies
1414
- [Node.js](https://nodejs.org/en/download/package-manager)
15+
- [`serve` must be globally installed](https://create-react-app.dev/docs/deployment/) (ideally with `sudo`): `sudo npm install -g serve`
1516

1617
## Getting Started in Computer
1718

@@ -33,7 +34,7 @@ If your workspace has already been built, you should run `source install/setup.b
3334
- If users will be accessing the app on a device other than the device running ROS, change `REACT_APP_ROS_SERVER_HOSTNAME` in `.env` to be the hostname of the device running ROS. Ensure that device is configured so that ports 8080 (web_video_server default) and 9090 (rosbridge default) can be accessed.
3435
3. Start the app: `npm start`
3536
4. Start the WebRTC signalling server: `node --env-file=.env server.js`
36-
5. Start the headless robot browser: `node --env-file=.env start_robot_browser.js`
37+
5. Start the headless robot browser: `node start_robot_browser.js`
3738
6. Use a web browser to navigate to `localhost:3000` to see the application.
3839

3940
#### Launching Dummy Nodes

feedingwebapp/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

feedingwebapp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"cors": "^2.8.5",
1414
"express": "^4.18.2",
1515
"mdb-react-ui-kit": "^3.0.0",
16+
"minimist": "^1.2.8",
1617
"playwright": "^1.40.1",
1718
"prop-types": "^15.8.1",
1819
"react": "^18.1.0",

feedingwebapp/start_robot_browser.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
const { chromium } = require('playwright')
44
const logId = 'start_robot_browser.js'
55

6-
let robotHostname = 'localhost:' + process.env.REACT_APP_PORT
7-
if (process.argv.length > 2) {
8-
robotHostname = process.argv[2]
6+
var argv = require('minimist')(process.argv.slice(2))
7+
let hostname = 'localhost'
8+
if (argv.hostname) {
9+
hostname = argv.hostname
10+
}
11+
let port = 3000
12+
if (argv.port) {
13+
if (!isNaN(parseInt(argv.port))) {
14+
port = parseInt(argv.port)
15+
}
916
}
1017

1118
;(async () => {
@@ -20,6 +27,9 @@ if (process.argv.length > 2) {
2027
}
2128
///////////////////////////////////////////////
2229

30+
let url = `http://${hostname}:${port}/robot`
31+
console.log(logId + ': Accessing URL: ' + url)
32+
2333
const browser = await chromium.launch({
2434
headless: true, // default is true
2535
ignoreHTTPSErrors: true, // avoid ERR_CERT_COMMON_NAME_INVALID
@@ -34,7 +44,7 @@ if (process.argv.length > 2) {
3444

3545
while (num_tries < max_tries) {
3646
try {
37-
await page.goto(`http://${robotHostname}/robot`)
47+
await page.goto(url)
3848
console.log(logId + ': finished loading')
3949
break
4050
} catch (e) {

0 commit comments

Comments
 (0)