Skip to content

Add React App and Tele-operation Example #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
03b2298
Add React App and Tele-operation Example
edaniels Sep 17, 2024
3258b80
Update examples/connect-app-teleop-react/frontend/app.tsx
edaniels Sep 17, 2024
24c2c73
lint pass ty mc
edaniels Sep 18, 2024
cc747bc
mc feedback
edaniels Sep 18, 2024
bdbca96
whoops
edaniels Sep 18, 2024
6fedffd
ethan pr
edaniels Sep 18, 2024
4251d3a
Update examples/connect-app-teleop-react/src/components/locations-lis…
edaniels Sep 18, 2024
73de177
Update examples/connect-app-teleop-react/src/components/machine-part-…
edaniels Sep 18, 2024
a08e505
Update examples/connect-app-teleop-react/src/components/machine-parts…
edaniels Sep 18, 2024
6d59df0
Update examples/connect-app-teleop-react/src/components/machines-list…
edaniels Sep 18, 2024
5c37a47
Update examples/connect-app-teleop-react/src/components/motion-arrows…
edaniels Sep 18, 2024
3d50cd3
Update examples/connect-app-teleop-react/src/components/motion-arrows…
edaniels Sep 18, 2024
ea369e7
Update examples/connect-app-teleop-react/src/components/video-stream.tsx
edaniels Sep 18, 2024
e174266
Update examples/connect-app-teleop-react/src/env.ts
edaniels Sep 18, 2024
1a437e5
lint
edaniels Sep 18, 2024
d797813
Update examples/connect-app-teleop-react/README.md
edaniels Sep 18, 2024
9e6a290
Update examples/connect-app-teleop-react/README.md
edaniels Sep 18, 2024
c01fc65
Update examples/connect-app-teleop-react/README.md
edaniels Sep 18, 2024
283183c
fix
edaniels Sep 18, 2024
d948d91
fixes
edaniels Sep 18, 2024
6def974
np feedback
edaniels Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ docs/dist

# build-time outputs
src/api-version.ts

*.DS_Store
1 change: 1 addition & 0 deletions examples/connect-app-teleop-react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env.*
78 changes: 78 additions & 0 deletions examples/connect-app-teleop-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# React App and Tele-operation Example

This example project allows you to browse your machines and stream a video from a Viam Rover and control its movements with your keyboard or mouse.

## Authentication Setup

There are two authentication options for this app:
1. API key id and secret baked into the frontend
1. OAuth2 via FusionAuth

### API Key

Go to your organization settings and either create or copy the information for an API key listed under "API Keys". The environment variables you'll need in the next step from this are:

```ini
VITE_APP_API_KEY_ID=21d425b4-0aed-49da-82c9-1e9bda895863
VITE_APP_API_KEY_SECRET=somesecret
```

### FusionAuth

For FusionAuth, you'll need to have set up the [Viam CLI](https://docs.viam.com/cli/). Using the CLI, set up an auth app:

```shell
BASE_DEV_URI="http://localhost:5173"
BASE_PROD_URI="http://localhost:9000"
viam auth-app register --application-name my-app --org-id "yourorgid" --redirect-uris "$BASE_DEV_URI,$BASE_PROD_URI,$BASE_DEV_URI/app/callback,$BASE_PROD_URI/app/callback" --origin-uris "$BASE_DEV_URI,$BASE_PROD_URI" --logout-uri "$BASE_DEV_URI"
```

Note: If you want to use Firefox, you'll need a tool like [ngrok](https://ngrok.com/) since Firefox does not allow WebRTC on localhost hosted pages.
You will also need to update the URI list in the command above in addition to using the `VITE_BASE_URI` environment variable (or set it in .env) to use your ngrok (or other proxy) endpoint.

The response will look something like this:

```shell
Info: Successfully registered auth application
{
"application_id": "98c26d9a-435b-419f-b028-208e8d328e09",
"application_name": "my-app",
"client_secret": "somesecret"
}
```

The environment variables you'll need in the next step from this are:

```ini
VITE_AUTH_CLIENT_ID=98c26d9a-435b-419f-b028-208e8d328e09 # the application_id
VITE_AUTH_CLIENT_SECRET=somesecret # the client_secret
```

## Setup

First, install development dependencies for the demo and launch a dev server.

```shell
cd examples/connect-app-teleop-react
npm install
```

The organization id, api key, and or client id/secret fields can be pre-filled from a `.env` file in the `connect-app-teleop-react` directory. You have to set these before running npm start. Refer to the authentication section before for which environment variables to set.

```ini
# examples/connect-app-teleop-react/.env
VITE_AUTH_CLIENT_ID=98c26d9a-435b-419f-b028-208e8d328e09
VITE_AUTH_CLIENT_SECRET=somesecret
```

```shell
npm start
```

### Base Project Template

This example assumes that you are working inside the Viam TypeScript SDK repository. If you want to use this example as a base for your project, make the following changes:

* Remove the `preinstall: ...` line from `package.json`
* Install the SDK: `npm install @viamrobotics/sdk@latest`
* You will also need to rename the components in the example code to match the actual component names in your configuration, for example, the camera could be named "cam" here but "camera" in your configuration.
13 changes: 13 additions & 0 deletions examples/connect-app-teleop-react/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Viam App and Tele-operation Demo</title>
<link rel="stylesheet" href="/src/index.css" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading