|
| 1 | +# React App and Tele-operation Example |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## Authentication Setup |
| 6 | + |
| 7 | +There are two authentication options for this app: |
| 8 | +1. API key id and secret baked into the frontend |
| 9 | +1. OAuth2 via FusionAuth |
| 10 | + |
| 11 | +### API Key |
| 12 | + |
| 13 | +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: |
| 14 | + |
| 15 | +```ini |
| 16 | +VITE_APP_API_KEY_ID=21d425b4-0aed-49da-82c9-1e9bda895863 |
| 17 | +VITE_APP_API_KEY_SECRET=somesecret |
| 18 | +``` |
| 19 | + |
| 20 | +### FusionAuth |
| 21 | + |
| 22 | +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: |
| 23 | + |
| 24 | +```shell |
| 25 | +BASE_DEV_URI="http://localhost:5173" |
| 26 | +BASE_PROD_URI="http://localhost:9000" |
| 27 | +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" |
| 28 | +``` |
| 29 | + |
| 30 | +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. |
| 31 | +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. |
| 32 | + |
| 33 | +The response will look something like this: |
| 34 | + |
| 35 | +```shell |
| 36 | +Info: Successfully registered auth application |
| 37 | +{ |
| 38 | + "application_id": "98c26d9a-435b-419f-b028-208e8d328e09", |
| 39 | + "application_name": "my-app", |
| 40 | + "client_secret": "somesecret" |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +The environment variables you'll need in the next step from this are: |
| 45 | + |
| 46 | +```ini |
| 47 | +VITE_AUTH_CLIENT_ID=98c26d9a-435b-419f-b028-208e8d328e09 # the application_id |
| 48 | +VITE_AUTH_CLIENT_SECRET=somesecret # the client_secret |
| 49 | +``` |
| 50 | + |
| 51 | +## Setup |
| 52 | + |
| 53 | +First, install development dependencies for the demo and launch a dev server. |
| 54 | + |
| 55 | +```shell |
| 56 | +cd examples/connect-app-teleop-react |
| 57 | +npm install |
| 58 | +``` |
| 59 | + |
| 60 | +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. |
| 61 | + |
| 62 | +```ini |
| 63 | +# examples/connect-app-teleop-react/.env |
| 64 | +VITE_AUTH_CLIENT_ID=98c26d9a-435b-419f-b028-208e8d328e09 |
| 65 | +VITE_AUTH_CLIENT_SECRET=somesecret |
| 66 | +``` |
| 67 | + |
| 68 | +```shell |
| 69 | +npm start |
| 70 | +``` |
| 71 | + |
| 72 | +### Base Project Template |
| 73 | + |
| 74 | +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: |
| 75 | + |
| 76 | +* Remove the `preinstall: ...` line from `package.json` |
| 77 | +* Install the SDK: `npm install @viamrobotics/sdk@latest` |
| 78 | +* 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. |
0 commit comments