├── .babelrc ├── .github └── workflows │ ├── main.yml │ └── size.yml ├── .gitignore ├── LICENSE ├── README.md ├── example ├── .npmignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── GridTest.js │ ├── RealGamepadDemo.js │ ├── SimGamepadDemo.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ ├── scss │ │ └── style.scss │ └── setupTests.js └── yarn.lock ├── package-lock.json ├── package.json ├── src ├── AxisBar.js ├── ImageStream.js ├── JoystickHelpers.js ├── RealGamepad.js ├── SimGamepad.js ├── SimJoystick.js └── index.js ├── test └── blah.test.tsx └── tsconfig.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/preset-react" 5 | ], 6 | "plugins": [ 7 | "@babel/plugin-proposal-class-properties" 8 | ] 9 | } -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: [push] 3 | jobs: 4 | build: 5 | name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }} 6 | 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | node: ['10.x', '12.x', '14.x'] 11 | os: [ubuntu-latest, windows-latest, macOS-latest] 12 | 13 | steps: 14 | - name: Checkout repo 15 | uses: actions/checkout@v2 16 | 17 | - name: Use Node ${{ matrix.node }} 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: ${{ matrix.node }} 21 | 22 | - name: Install deps and build (with cache) 23 | uses: bahmutov/npm-install@v1 24 | 25 | - name: Lint 26 | run: yarn lint 27 | 28 | - name: Test 29 | run: yarn test --ci --coverage --maxWorkers=2 30 | 31 | - name: Build 32 | run: yarn build 33 | -------------------------------------------------------------------------------- /.github/workflows/size.yml: -------------------------------------------------------------------------------- 1 | name: size 2 | on: [pull_request] 3 | jobs: 4 | size: 5 | runs-on: ubuntu-latest 6 | env: 7 | CI_JOB_NUMBER: 1 8 | steps: 9 | - uses: actions/checkout@v1 10 | - uses: andresz1/size-limit-action@v1 11 | with: 12 | github_token: ${{ secrets.GITHUB_TOKEN }} 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ros-ui-react 2 | A collection of React components for interacting with robotic systems running ROS. 3 | -------------------------------------------------------------------------------- /example/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .cache 3 | dist -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-react-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.9", 7 | "@testing-library/react": "^11.2.5", 8 | "@testing-library/user-event": "^12.8.1", 9 | "classnames": "^2.3.2", 10 | "react": "^17.0.1", 11 | "react-dom": "^17.0.2", 12 | "react-scripts": "4.0.3", 13 | "ros-ui-react": "../", 14 | "sass": "^1.32.8", 15 | "web-vitals": "^1.1.0" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": [ 25 | "react-app", 26 | "react-app/jest" 27 | ] 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | }, 41 | "babel": { 42 | "presets": [ 43 | "@babel/preset-env" 44 | ], 45 | "plugins": [ 46 | [ 47 | "@babel/plugin-proposal-class-properties", 48 | { 49 | "loose": true 50 | } 51 | ] 52 | ] 53 | }, 54 | "devDependencies": { 55 | "@babel/plugin-proposal-class-properties": "^7.13.0" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshnewans/ros-ui-react/60381c116416246dfb1a606041c91d00a374f90c/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /example/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshnewans/ros-ui-react/60381c116416246dfb1a606041c91d00a374f90c/example/public/logo192.png -------------------------------------------------------------------------------- /example/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshnewans/ros-ui-react/60381c116416246dfb1a606041c91d00a374f90c/example/public/logo512.png -------------------------------------------------------------------------------- /example/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /example/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /example/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /example/src/App.js: -------------------------------------------------------------------------------- 1 | import { BrowserRouter, Route, Switch } from 'react-router-dom'; 2 | import './scss/style.scss'; 3 | import RealGamepadDemo from './RealGamepadDemo'; 4 | import SimGamepadDemo from './SimGamepadDemo'; 5 | 6 | function App() { 7 | return ( 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | ); 16 | } 17 | 18 | 19 | function Home() { 20 | return ( 21 |
22 |

Home

23 | 36 |
37 | ); 38 | } 39 | 40 | export default App; 41 | -------------------------------------------------------------------------------- /example/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /example/src/GridTest.js: -------------------------------------------------------------------------------- 1 | // import { SimGamepad } from 'ros-ui-react'; 2 | import { RealGamepad } from 'ros-ui-react'; 3 | import { ImageStream } from 'ros-ui-react'; 4 | import './App.css'; 5 | import './scss/style.scss'; 6 | 7 | import React from "react"; 8 | // import _ from "lodash"; 9 | import RGL, { WidthProvider } from "react-grid-layout"; 10 | 11 | const ReactGridLayout = WidthProvider(RGL); 12 | 13 | export default class GridTest extends React.PureComponent { 14 | static defaultProps = { 15 | onLayoutChange: function() {}, 16 | }; 17 | 18 | // constructor(props) { 19 | // super(props); 20 | // } 21 | 22 | 23 | onLayoutChange(layout) { 24 | this.props.onLayoutChange(layout); 25 | } 26 | 27 | render() { 28 | return ( 29 | 37 |
38 |
39 |
40 | ); 41 | } 42 | } -------------------------------------------------------------------------------- /example/src/RealGamepadDemo.js: -------------------------------------------------------------------------------- 1 | import { RealGamepad } from 'ros-ui-react'; 2 | import { ImageStream } from 'ros-ui-react'; 3 | import './App.css'; 4 | import './scss/style.scss'; 5 | 6 | function RealGamepadDemo() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | 15 | export default RealGamepadDemo; 16 | -------------------------------------------------------------------------------- /example/src/SimGamepadDemo.js: -------------------------------------------------------------------------------- 1 | import { SimGamepad } from 'ros-ui-react'; 2 | import { ImageStream } from 'ros-ui-react'; 3 | import './App.css'; 4 | import './scss/style.scss'; 5 | 6 | function SimGamepadDemo() { 7 | return ( 8 |
9 | 10 | 11 |
12 | ); 13 | } 14 | 15 | export default SimGamepadDemo; 16 | -------------------------------------------------------------------------------- /example/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /example/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /example/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /example/src/scss/style.scss: -------------------------------------------------------------------------------- 1 | 2 | // Import CoreUI styles 3 | @import "~@coreui/coreui/scss/coreui.scss"; 4 | 5 | @import "~react-grid-layout/css/styles.css"; 6 | @import "~react-resizable/css/styles.css"; 7 | 8 | body { 9 | padding: 20px; 10 | } 11 | #content { 12 | width: 100%; 13 | } 14 | .react-grid-layout { 15 | background: #eee; 16 | margin-top: 10px; 17 | } 18 | .layoutJSON { 19 | background: #ddd; 20 | border: 1px solid black; 21 | margin-top: 10px; 22 | padding: 10px; 23 | } 24 | .columns { 25 | -moz-columns: 120px; 26 | -webkit-columns: 120px; 27 | columns: 120px; 28 | } 29 | .react-grid-item { 30 | box-sizing: border-box; 31 | } 32 | .react-grid-item:not(.react-grid-placeholder) { 33 | background: #ccc; 34 | border: 1px solid black; 35 | } 36 | .react-grid-item.resizing { 37 | opacity: 0.9; 38 | } 39 | .react-grid-item.static { 40 | background: #cce; 41 | } 42 | .react-grid-item .text { 43 | font-size: 24px; 44 | text-align: center; 45 | position: absolute; 46 | top: 0; 47 | bottom: 0; 48 | left: 0; 49 | right: 0; 50 | margin: auto; 51 | height: 24px; 52 | } 53 | .react-grid-item .minMax { 54 | font-size: 12px; 55 | } 56 | .react-grid-item .add { 57 | cursor: pointer; 58 | } 59 | .react-grid-dragHandleExample { 60 | cursor: move; /* fallback if grab cursor is unsupported */ 61 | cursor: grab; 62 | cursor: -moz-grab; 63 | cursor: -webkit-grab; 64 | } 65 | 66 | .toolbox { 67 | background-color: #dfd; 68 | width: 100%; 69 | height: 120px; 70 | overflow: scroll; 71 | } 72 | 73 | .hide-button { 74 | cursor: pointer; 75 | position: absolute; 76 | font-size: 20px; 77 | top: 0px; 78 | right: 5px; 79 | } 80 | 81 | .toolbox__title { 82 | font-size: 24px; 83 | margin-bottom: 5px; 84 | } 85 | .toolbox__items { 86 | display: block; 87 | } 88 | .toolbox__items__item { 89 | display: inline-block; 90 | text-align: center; 91 | line-height: 40px; 92 | cursor: pointer; 93 | width: 40px; 94 | height: 40px; 95 | padding: 10px; 96 | margin: 5px; 97 | border: 1px solid black; 98 | background-color: #ddd; 99 | } 100 | .droppable-element { 101 | width: 150px; 102 | text-align: center; 103 | background: #fdd; 104 | border: 1px solid black; 105 | margin: 10px 0; 106 | padding: 10px; 107 | } -------------------------------------------------------------------------------- /example/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "license": "MIT", 4 | "main": "dist/index.js", 5 | "typings": "dist/index.d.ts", 6 | "files": [ 7 | "dist", 8 | "src" 9 | ], 10 | "engines": { 11 | "node": ">=10" 12 | }, 13 | "scripts": { 14 | "start": "tsdx watch", 15 | "build": "tsdx build", 16 | "test": "tsdx test --passWithNoTests", 17 | "lint": "tsdx lint", 18 | "prepare": "tsdx build", 19 | "size": "size-limit", 20 | "analyze": "size-limit --why" 21 | }, 22 | "husky": { 23 | "hooks": { 24 | "pre-commit": "tsdx lint" 25 | } 26 | }, 27 | "prettier": { 28 | "printWidth": 80, 29 | "semi": true, 30 | "singleQuote": true, 31 | "trailingComma": "es5" 32 | }, 33 | "name": "ros-ui-react", 34 | "author": "Josh Newans", 35 | "module": "dist/ros-ui-react.esm.js", 36 | "size-limit": [ 37 | { 38 | "path": "dist/ros-ui-react.cjs.production.min.js", 39 | "limit": "10 KB" 40 | }, 41 | { 42 | "path": "dist/ros-ui-react.esm.js", 43 | "limit": "10 KB" 44 | } 45 | ], 46 | "devDependencies": { 47 | "@size-limit/preset-small-lib": "^4.10.0", 48 | "husky": "^5.1.3", 49 | "size-limit": "^4.10.0", 50 | "tsdx": "^0.14.1", 51 | "tslib": "^2.1.0", 52 | "typescript": "^4.2.3" 53 | }, 54 | "peerDependencies": { 55 | "@types/react": "^17.0.2", 56 | "@types/react-dom": "^17.0.2", 57 | "react": "^17.0.2", 58 | "react-dom": "^17.0.2" 59 | }, 60 | "dependencies": { 61 | "@babel/preset-env": "^7.13.9", 62 | "@babel/preset-react": "^7.12.13", 63 | "@coreui/coreui": "^4.2.2", 64 | "@coreui/react": "^4.4.0", 65 | "gamepads": "^1.2.2", 66 | "react-grid-layout": "^1.2.4", 67 | "react-joystick-component": "^1.4.0", 68 | "react-router-dom": "^5.2.0", 69 | "roslib": "^1.3.0" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/AxisBar.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react'; 3 | import classNames from 'classnames' 4 | import { 5 | CProgress 6 | } from '@coreui/react' 7 | 8 | 9 | 10 | 11 | class AxisBar extends Component { 12 | 13 | constructor(props) { 14 | super(props); 15 | } 16 | 17 | 18 | 19 | 20 | 21 | render() { 22 | 23 | 24 | return ( 25 | 31 | 32 | 33 | ); 34 | } 35 | } 36 | 37 | export default AxisBar; -------------------------------------------------------------------------------- /src/ImageStream.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react'; 3 | import { 4 | CCard, 5 | CCardHeader, 6 | CCardBody 7 | } from '@coreui/react' 8 | 9 | 10 | 11 | 12 | class ImageStream extends Component { 13 | 14 | constructor(props) { 15 | super(props); 16 | } 17 | 18 | 19 | render() { 20 | 21 | return ( 22 | 23 | 24 | 25 | Image Stream 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | ); 36 | } 37 | } 38 | 39 | export { ImageStream }; -------------------------------------------------------------------------------- /src/JoystickHelpers.js: -------------------------------------------------------------------------------- 1 | export function applyDeadzone(val, deadzone) { 2 | 3 | if (val > deadzone) 4 | { 5 | val -= deadzone; 6 | } 7 | else if (val < -deadzone) 8 | { 9 | val += deadzone; 10 | } 11 | else 12 | { 13 | val = 0; 14 | } 15 | return -val/(1.0 - deadzone); 16 | 17 | } -------------------------------------------------------------------------------- /src/RealGamepad.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react'; 3 | import classNames from 'classnames' 4 | import { 5 | CButton, 6 | CRow, 7 | CCol, 8 | CCard, 9 | CCardHeader, 10 | CCardBody 11 | } from '@coreui/react' 12 | import ROSLIB from 'roslib' 13 | import AxisBar from './AxisBar'; 14 | import { applyDeadzone } from './JoystickHelpers' 15 | import Gamepads from 'gamepads'; 16 | 17 | 18 | class RealGamepad extends Component { 19 | 20 | gamepadScanIntervalId = 0; 21 | rosSendIntervalId = 0; 22 | constructor(props) { 23 | super(props); 24 | this.controllers = {}; 25 | this.state = { 26 | buttons: [], 27 | axes: [], 28 | t: 0 29 | }; 30 | this.ros = new ROSLIB.Ros(); 31 | } 32 | 33 | static defaultProps = { 34 | deadzone: 0.25 35 | } 36 | 37 | 38 | 39 | connecthandler = (e) => { 40 | this.addgamepad(e.gamepad); 41 | } 42 | 43 | 44 | addgamepad = (gamepad) => { 45 | this.controllers[gamepad.gamepad.index] = gamepad; 46 | console.log("Gamepad Connected"); 47 | } 48 | 49 | 50 | disconnecthandler = (e) => { 51 | this.removegamepad(e.gamepad); 52 | } 53 | 54 | removegamepad = (gamepad) => { 55 | console.log("Gamepad Disconnected"); 56 | delete this.controllers[gamepad.gamepad.index]; 57 | } 58 | 59 | updateStatus = () => { 60 | for (const [key, value] of Object.entries(this.controllers)) { 61 | var controller = this.controllers[key].gamepad; 62 | for (var i = 0; i < controller.buttons.length; i++) { 63 | var val = controller.buttons[i]; 64 | var pressed = val == 1.0; 65 | var touched = false; 66 | if (typeof (val) == "object") { 67 | pressed = val.pressed; 68 | if ('touched' in val) { 69 | touched = val.touched; 70 | } 71 | val = val.value; 72 | } 73 | var pct = Math.round(val * 100) + "%"; 74 | } 75 | } 76 | } 77 | 78 | 79 | componentDidMount() { 80 | 81 | // If there is an error on the backend, an 'error' emit will be emitted. 82 | this.ros.on('error', function (error) { 83 | console.log(error); 84 | }); 85 | 86 | // Find out exactly when we made a connection. 87 | this.ros.on('connection', function () { 88 | console.log('Connection made!'); 89 | }); 90 | 91 | this.ros.on('close', function () { 92 | console.log('Connection closed.'); 93 | }); 94 | 95 | this.ros.connect(this.props.rosbridgeAddress); 96 | 97 | this.topic = new ROSLIB.Topic({ 98 | ros: this.ros, 99 | name: '/joy', 100 | messageType: 'sensor_msgs/Joy' 101 | }); 102 | 103 | Gamepads.start(); 104 | 105 | Gamepads.addEventListener("connect", this.connecthandler); 106 | Gamepads.addEventListener("disconnect", this.disconnecthandler); 107 | 108 | this.rosSendIntervalId = setInterval(this.timerEnd, 20); 109 | 110 | } 111 | 112 | componentWillUnmount () { 113 | this.ros.close(); 114 | Gamepads.stop(); 115 | clearInterval(this.rosSendIntervalId); 116 | } 117 | 118 | 119 | timerEnd = () => { 120 | this.updateStatus(); 121 | 122 | 123 | 124 | var joyMsg = { 125 | header: 126 | { 127 | // seq: 0, 128 | stamp: [0,0], 129 | frame_id: "" 130 | }, 131 | axes: [], 132 | buttons: [] 133 | }; 134 | 135 | if (this.controllers[0]) { 136 | var controller = this.controllers[0].gamepad; 137 | for (var i = 0; i < controller.axes.length; i++) { 138 | 139 | joyMsg.axes.push(applyDeadzone(controller.axes[i], this.props.deadzone)); 140 | } 141 | for (var i = 0; i < controller.buttons.length; i++) { 142 | joyMsg.buttons.push(controller.buttons[i].pressed ? 1 : 0); 143 | } 144 | this.topic.publish(joyMsg); 145 | 146 | var buttonVals = controller.buttons.map((item) => item.pressed); 147 | var axes = controller.axes; 148 | 149 | this.setState((prevState) => ({ t: prevState.t + 1, buttons: buttonVals, axes: axes })); 150 | 151 | } 152 | } 153 | 154 | 155 | 156 | 157 | 158 | render() { 159 | 160 | let cols = this.state.buttons.map((item, index) => 161 | 0 ? "primary" : "secondary"}>{index} 162 | ); 163 | 164 | 165 | let axisDisplays = this.state.axes.map((item, index) => 166 | 167 | ); 168 | 169 | return ( 170 | 171 | 172 | 173 | Real Controller 174 | 175 | 176 | 177 | {cols} 178 | 179 | 180 | {axisDisplays} 181 | 182 | 183 | 184 | 185 | ); 186 | } 187 | } 188 | 189 | export { RealGamepad }; -------------------------------------------------------------------------------- /src/SimGamepad.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react'; 3 | // import classNames from 'classnames' 4 | import { 5 | CButton, 6 | CRow, 7 | CCol, 8 | CCard, 9 | CCardHeader, 10 | CCardBody, 11 | CProgress, 12 | CProgressBar 13 | } from '@coreui/react' 14 | import ROSLIB from 'roslib' 15 | import AxisBar from './AxisBar'; 16 | import SimJoystick from './SimJoystick'; 17 | 18 | 19 | 20 | 21 | 22 | class SimGamepad extends Component { 23 | 24 | constructor(props) { 25 | super(props); 26 | this.controllers = {}; 27 | this.state = { 28 | buttons: [0,0,0,0], 29 | axes: [0,0,0,0], 30 | sticks: [0,0] 31 | }; 32 | this.ros = new ROSLIB.Ros(); 33 | } 34 | 35 | 36 | 37 | 38 | componentDidMount() { 39 | 40 | // If there is an error on the backend, an 'error' emit will be emitted. 41 | this.ros.on('error', function (error) { 42 | console.log(error); 43 | }); 44 | 45 | // Find out exactly when we made a connection. 46 | this.ros.on('connection', function () { 47 | console.log('Connection made!'); 48 | }); 49 | 50 | this.ros.on('close', function () { 51 | console.log('Connection closed.'); 52 | }); 53 | 54 | this.ros.connect(this.props.rosbridgeAddress); 55 | 56 | this.topic = new ROSLIB.Topic({ 57 | ros: this.ros, 58 | name: '/joy', 59 | messageType: 'sensor_msgs/Joy' 60 | }); 61 | 62 | setInterval(this.timerEnd, 20); 63 | 64 | } 65 | 66 | componentWillUnmount () { 67 | this.ros.close(); 68 | } 69 | 70 | 71 | timerEnd = () => { 72 | 73 | var joyMsg = new ROSLIB.Message({ 74 | header: 75 | { 76 | // seq: 0, 77 | stamp: [0,0], 78 | frame_id: "" 79 | }, 80 | axes: [], 81 | buttons: [] 82 | }); 83 | 84 | 85 | joyMsg.axes = this.state.axes; 86 | joyMsg.buttons = this.state.buttons; 87 | 88 | this.topic.publish(joyMsg); 89 | 90 | 91 | } 92 | 93 | buttonOn = (index) =>{ 94 | var buttonVals = this.state.buttons; 95 | buttonVals[index] = 1; 96 | this.setState({ buttons: buttonVals}); 97 | } 98 | 99 | buttonOff = (index) =>{ 100 | var buttonVals = this.state.buttons; 101 | buttonVals[index] = 0; 102 | this.setState({ buttons: buttonVals}); 103 | } 104 | 105 | joyStop = (index) =>{ 106 | var axisVals = this.state.axes; 107 | axisVals[2*index] = 0; 108 | axisVals[2*index+1] = 0; 109 | this.setState({ axes: axisVals}); 110 | } 111 | 112 | joyMove = (x, y, index) =>{ 113 | var axisVals = this.state.axes; 114 | axisVals[2*index] = x; 115 | axisVals[2*index+1] = y; 116 | this.setState({ axes: axisVals}); 117 | } 118 | 119 | 120 | 121 | 122 | 123 | render() { 124 | 125 | let cols = this.state.buttons.map((item, index) => 126 | 0 ? "primary" : "secondary"} onPointerDown={() => this.buttonOn(index)} onPointerUp={() => this.buttonOff(index)} >{index} 127 | ); 128 | 129 | let stickDisplays = this.state.sticks.map((item, index) => 130 | this.joyMove(x,y, index)} stop={() => this.joyStop(index)} /> 131 | 132 | ); 133 | 134 | let axisDisplays = this.state.axes.map((item, index) => 135 | 136 | ); 137 | 138 | return ( 139 | 140 | 141 | 142 | Simulated Controller 143 | 144 | 145 | 146 | {cols} 147 | 148 | 149 | {axisDisplays} 150 | 151 | 152 | {stickDisplays} 153 | 154 | 155 | 156 | 157 | ); 158 | } 159 | } 160 | 161 | export { SimGamepad }; -------------------------------------------------------------------------------- /src/SimJoystick.js: -------------------------------------------------------------------------------- 1 | 2 | import React, { Component } from 'react'; 3 | import classNames from 'classnames' 4 | import { Joystick } from 'react-joystick-component'; 5 | 6 | 7 | 8 | 9 | class SimJoystick extends Component { 10 | 11 | constructor(props) { 12 | super(props); 13 | } 14 | 15 | 16 | move = (event) => 17 | { 18 | this.props.move(event.x/this.props.size, event.y/this.props.size); 19 | } 20 | 21 | stop = () => 22 | { 23 | this.props.stop(); 24 | } 25 | 26 | 27 | render() { 28 | 29 | 30 | return ( 31 | 32 | 33 | 34 | ); 35 | } 36 | } 37 | 38 | export default SimJoystick; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | export { SimGamepad } from './SimGamepad'; 2 | export { RealGamepad } from './RealGamepad'; 3 | export { ImageStream } from './ImageStream'; -------------------------------------------------------------------------------- /test/blah.test.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import * as ReactDOM from 'react-dom'; 3 | import { SimGamepad } from '../src/SimGamepad'; 4 | import { RealGamepad } from '../src/SimGamepad'; 5 | 6 | describe('it', () => { 7 | it('renders without crashing', () => { 8 | const div = document.createElement('div'); 9 | ReactDOM.render(, div); 10 | ReactDOM.render(, div); 11 | ReactDOM.unmountComponentAtNode(div); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs 3 | "include": ["src", "types"], 4 | "compilerOptions": { 5 | "module": "esnext", 6 | "lib": ["dom", "esnext"], 7 | "importHelpers": true, 8 | // output .d.ts declaration files for consumers 9 | "declaration": true, 10 | // output .js.map sourcemap files for consumers 11 | "sourceMap": true, 12 | // match output dir to input dir. e.g. dist/index instead of dist/src/index 13 | "rootDir": "./src", 14 | // stricter type-checking for stronger correctness. Recommended by TS 15 | "strict": true, 16 | // linter checks for common issues 17 | "noImplicitReturns": true, 18 | "noFallthroughCasesInSwitch": true, 19 | // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | // use Node's module resolution algorithm, instead of the legacy TS one 23 | "moduleResolution": "node", 24 | // transpile JSX to React.createElement 25 | "jsx": "react", 26 | // interop between ESM and CJS modules. Recommended by TS 27 | "esModuleInterop": true, 28 | // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS 29 | "skipLibCheck": true, 30 | // error out if import and file system have a casing mismatch. Recommended by TS 31 | "forceConsistentCasingInFileNames": true, 32 | // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` 33 | "noEmit": true, 34 | } 35 | } 36 | --------------------------------------------------------------------------------