├── .eslintrc.json ├── .gitignore ├── LICENSE ├── README.md ├── lerna.json ├── package.json ├── packages ├── hackbox-client │ ├── README.md │ ├── lib │ │ └── index.js │ ├── package.json │ └── yarn.lock ├── hackbox-demo │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ └── manifest.json │ ├── src │ │ ├── client │ │ │ ├── components │ │ │ │ ├── App.js │ │ │ │ ├── Boggle.js │ │ │ │ ├── Host.js │ │ │ │ ├── Landing.js │ │ │ │ └── Navbar.js │ │ │ ├── serviceWorker.js │ │ │ └── styles │ │ │ │ ├── Boggle.scss │ │ │ │ └── index.scss │ │ ├── index.js │ │ └── server │ │ │ ├── gameReference.js │ │ │ └── index.js │ └── yarn.lock └── hackbox-server │ ├── README.md │ ├── lib │ ├── attachListeners.js │ ├── index.js │ ├── objects │ │ ├── index.js │ │ ├── playerManager.js │ │ └── roomManager.js │ └── utils.js │ ├── package.json │ └── yarn.lock └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "extends": "standard", 9 | "globals": { 10 | "Atomics": "readonly", 11 | "SharedArrayBuffer": "readonly" 12 | }, 13 | "parserOptions": { 14 | "ecmaFeatures": { 15 | "jsx": true 16 | }, 17 | "ecmaVersion": 2018 18 | }, 19 | "plugins": ["react"], 20 | "rules": { 21 | "semi": [2, "always"] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .npmrc 3 | 4 | lerna-debug.log 5 | yarn-error.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Tommy Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hackbox 2 | 3 | Because the world needs more Jackbox-style games. 4 | 5 | ## About 6 | 7 | A duo of packages to aid in the development of party games that make use of mobile devices or any other device that can open a browser. 8 | 9 | ## Server 10 | 11 | Check out the source [here](https://github.com/tomalama/hackbox/tree/master/packages/hackbox-server), and install it via [npm](https://www.npmjs.com/package/hackbox-server). 12 | 13 | ## Client 14 | 15 | Check out the source [here](https://github.com/tomalama/hackbox/tree/master/packages/hackbox-client), and install it via [npm](https://www.npmjs.com/package/hackbox-client). 16 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "version": "0.0.3", 6 | "npmClient": "yarn" 7 | } 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hackbox", 3 | "description": "A Jackbox inspired framework for creating party games", 4 | "repository": "https://github.com/tomalama/hackbox", 5 | "author": "tomalama ", 6 | "license": "MIT", 7 | "private": true, 8 | "devDependencies": { 9 | "eslint": "^5.16.0", 10 | "eslint-config-standard": "^12.0.0", 11 | "eslint-plugin-import": "^2.17.2", 12 | "eslint-plugin-node": "^9.0.1", 13 | "eslint-plugin-promise": "^4.1.1", 14 | "eslint-plugin-react": "^7.13.0", 15 | "eslint-plugin-standard": "^4.0.0", 16 | "lerna": "^3.14.1" 17 | }, 18 | "scripts": { 19 | "publish:all": "lerna publish", 20 | "test": "lerna run test" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/hackbox-client/README.md: -------------------------------------------------------------------------------- 1 | # `hackbox-client` 2 | 3 | A Jackbox inspired framework for creating party games - client component. 4 | 5 | ## Usage 6 | 7 | ```javascript 8 | const hackboxClient = require("hackbox-client"); 9 | ``` 10 | 11 | ### Hosting 12 | 13 | ```javascript 14 | async componentDidMount() { 15 | const hackbox = await hackboxClient("http://localhost:8080"); 16 | const room = await hackbox.createRoom(); 17 | this.setState(() => ({ room })); 18 | 19 | hackbox.onPlayerJoin(room => { 20 | this.setState(() => ({ room })); 21 | }); 22 | } 23 | ``` 24 | 25 | ### Joining a Room 26 | 27 | ```javascript 28 | const hackbox = await hackboxClient("http://localhost:8080"); 29 | const playerId = await hackbox.joinRoom(roomId, name); 30 | ``` 31 | -------------------------------------------------------------------------------- /packages/hackbox-client/lib/index.js: -------------------------------------------------------------------------------- 1 | const io = require('socket.io-client'); 2 | 3 | const hackboxClient = async url => { 4 | const socket = await io.connect(url); 5 | 6 | /** 7 | * Room methods 8 | */ 9 | 10 | const createRoom = () => { 11 | return new Promise(resolve => { 12 | socket.emit('hb-createRoom'); 13 | socket.on('hb-roomData', data => { 14 | resolve(data); 15 | }); 16 | }); 17 | }; 18 | 19 | const onPlayerJoin = cb => { 20 | socket.on('hb-onPlayerJoin', room => { 21 | cb(room); 22 | }); 23 | }; 24 | 25 | const startGame = ({ roomId, gameType }) => { 26 | socket.emit('hb-startGame', { roomId, gameType }); 27 | }; 28 | 29 | /** 30 | * Player methods 31 | */ 32 | 33 | const joinRoom = ({ roomId, playerName }) => { 34 | return new Promise(resolve => { 35 | socket.emit('hb-joinRoom', { roomId, playerName }); 36 | socket.on('hb-roomConnectionSuccessful', playerId => { 37 | resolve(playerId); 38 | }); 39 | }); 40 | }; 41 | 42 | const onStartGame = cb => { 43 | socket.on('hb-gameStart', gameType => { 44 | cb(gameType); 45 | }); 46 | }; 47 | 48 | return { 49 | createRoom, 50 | onPlayerJoin, 51 | startGame, 52 | joinRoom, 53 | onStartGame 54 | }; 55 | }; 56 | 57 | module.exports = hackboxClient; 58 | -------------------------------------------------------------------------------- /packages/hackbox-client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hackbox-client", 3 | "version": "0.0.3", 4 | "description": "A Jackbox inspired framework for creating party games - client component", 5 | "keywords": [ 6 | "realtime", 7 | "framework", 8 | "websocket", 9 | "events", 10 | "socket", 11 | "client", 12 | "jackbox", 13 | "party", 14 | "games" 15 | ], 16 | "author": "tomalama ", 17 | "homepage": "https://github.com/tomalama/hackbox/tree/master/packages/hackbox-client", 18 | "license": "MIT", 19 | "main": "lib/index.js", 20 | "directories": { 21 | "lib": "lib" 22 | }, 23 | "files": [ 24 | "lib" 25 | ], 26 | "publishConfig": { 27 | "registry": "https://registry.npmjs.org/" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/tomalama/hackbox/tree/master/packages/hackbox-client" 32 | }, 33 | "scripts": { 34 | "test": "echo \"Not yet implemented\" && exit 0" 35 | }, 36 | "dependencies": { 37 | "socket.io-client": "^2.2.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/hackbox-client/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | after@0.8.2: 6 | version "0.8.2" 7 | resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f" 8 | integrity sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8= 9 | 10 | arraybuffer.slice@~0.0.7: 11 | version "0.0.7" 12 | resolved "https://registry.yarnpkg.com/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz#3bbc4275dd584cc1b10809b89d4e8b63a69e7675" 13 | integrity sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog== 14 | 15 | async-limiter@~1.0.0: 16 | version "1.0.0" 17 | resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" 18 | integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg== 19 | 20 | backo2@1.0.2: 21 | version "1.0.2" 22 | resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" 23 | integrity sha1-MasayLEpNjRj41s+u2n038+6eUc= 24 | 25 | base64-arraybuffer@0.1.5: 26 | version "0.1.5" 27 | resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz#73926771923b5a19747ad666aa5cd4bf9c6e9ce8" 28 | integrity sha1-c5JncZI7Whl0etZmqlzUv5xunOg= 29 | 30 | better-assert@~1.0.0: 31 | version "1.0.2" 32 | resolved "https://registry.yarnpkg.com/better-assert/-/better-assert-1.0.2.tgz#40866b9e1b9e0b55b481894311e68faffaebc522" 33 | integrity sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI= 34 | dependencies: 35 | callsite "1.0.0" 36 | 37 | blob@0.0.5: 38 | version "0.0.5" 39 | resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.5.tgz#d680eeef25f8cd91ad533f5b01eed48e64caf683" 40 | integrity sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig== 41 | 42 | callsite@1.0.0: 43 | version "1.0.0" 44 | resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20" 45 | integrity sha1-KAOY5dZkvXQDi28JBRU+borxvCA= 46 | 47 | component-bind@1.0.0: 48 | version "1.0.0" 49 | resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" 50 | integrity sha1-AMYIq33Nk4l8AAllGx06jh5zu9E= 51 | 52 | component-emitter@1.2.1: 53 | version "1.2.1" 54 | resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" 55 | integrity sha1-E3kY1teCg/ffemt8WmPhQOaUJeY= 56 | 57 | component-inherit@0.0.3: 58 | version "0.0.3" 59 | resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143" 60 | integrity sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM= 61 | 62 | debug@~3.1.0: 63 | version "3.1.0" 64 | resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" 65 | integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== 66 | dependencies: 67 | ms "2.0.0" 68 | 69 | engine.io-client@~3.3.1: 70 | version "3.3.2" 71 | resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-3.3.2.tgz#04e068798d75beda14375a264bb3d742d7bc33aa" 72 | integrity sha512-y0CPINnhMvPuwtqXfsGuWE8BB66+B6wTtCofQDRecMQPYX3MYUZXFNKDhdrSe3EVjgOu4V3rxdeqN/Tr91IgbQ== 73 | dependencies: 74 | component-emitter "1.2.1" 75 | component-inherit "0.0.3" 76 | debug "~3.1.0" 77 | engine.io-parser "~2.1.1" 78 | has-cors "1.1.0" 79 | indexof "0.0.1" 80 | parseqs "0.0.5" 81 | parseuri "0.0.5" 82 | ws "~6.1.0" 83 | xmlhttprequest-ssl "~1.5.4" 84 | yeast "0.1.2" 85 | 86 | engine.io-parser@~2.1.1: 87 | version "2.1.3" 88 | resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-2.1.3.tgz#757ab970fbf2dfb32c7b74b033216d5739ef79a6" 89 | integrity sha512-6HXPre2O4Houl7c4g7Ic/XzPnHBvaEmN90vtRO9uLmwtRqQmTOw0QMevL1TOfL2Cpu1VzsaTmMotQgMdkzGkVA== 90 | dependencies: 91 | after "0.8.2" 92 | arraybuffer.slice "~0.0.7" 93 | base64-arraybuffer "0.1.5" 94 | blob "0.0.5" 95 | has-binary2 "~1.0.2" 96 | 97 | has-binary2@~1.0.2: 98 | version "1.0.3" 99 | resolved "https://registry.yarnpkg.com/has-binary2/-/has-binary2-1.0.3.tgz#7776ac627f3ea77250cfc332dab7ddf5e4f5d11d" 100 | integrity sha512-G1LWKhDSvhGeAQ8mPVQlqNcOB2sJdwATtZKl2pDKKHfpf/rYj24lkinxf69blJbnsvtqqNU+L3SL50vzZhXOnw== 101 | dependencies: 102 | isarray "2.0.1" 103 | 104 | has-cors@1.1.0: 105 | version "1.1.0" 106 | resolved "https://registry.yarnpkg.com/has-cors/-/has-cors-1.1.0.tgz#5e474793f7ea9843d1bb99c23eef49ff126fff39" 107 | integrity sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk= 108 | 109 | indexof@0.0.1: 110 | version "0.0.1" 111 | resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" 112 | integrity sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10= 113 | 114 | isarray@2.0.1: 115 | version "2.0.1" 116 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.1.tgz#a37d94ed9cda2d59865c9f76fe596ee1f338741e" 117 | integrity sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4= 118 | 119 | ms@2.0.0: 120 | version "2.0.0" 121 | resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" 122 | integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= 123 | 124 | object-component@0.0.3: 125 | version "0.0.3" 126 | resolved "https://registry.yarnpkg.com/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291" 127 | integrity sha1-8MaapQ78lbhmwYb0AKM3acsvEpE= 128 | 129 | parseqs@0.0.5: 130 | version "0.0.5" 131 | resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d" 132 | integrity sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0= 133 | dependencies: 134 | better-assert "~1.0.0" 135 | 136 | parseuri@0.0.5: 137 | version "0.0.5" 138 | resolved "https://registry.yarnpkg.com/parseuri/-/parseuri-0.0.5.tgz#80204a50d4dbb779bfdc6ebe2778d90e4bce320a" 139 | integrity sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo= 140 | dependencies: 141 | better-assert "~1.0.0" 142 | 143 | socket.io-client@^2.2.0: 144 | version "2.2.0" 145 | resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-2.2.0.tgz#84e73ee3c43d5020ccc1a258faeeb9aec2723af7" 146 | integrity sha512-56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQWu92yyWICxB0u7wkVbYA== 147 | dependencies: 148 | backo2 "1.0.2" 149 | base64-arraybuffer "0.1.5" 150 | component-bind "1.0.0" 151 | component-emitter "1.2.1" 152 | debug "~3.1.0" 153 | engine.io-client "~3.3.1" 154 | has-binary2 "~1.0.2" 155 | has-cors "1.1.0" 156 | indexof "0.0.1" 157 | object-component "0.0.3" 158 | parseqs "0.0.5" 159 | parseuri "0.0.5" 160 | socket.io-parser "~3.3.0" 161 | to-array "0.1.4" 162 | 163 | socket.io-parser@~3.3.0: 164 | version "3.3.0" 165 | resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.0.tgz#2b52a96a509fdf31440ba40fed6094c7d4f1262f" 166 | integrity sha512-hczmV6bDgdaEbVqhAeVMM/jfUfzuEZHsQg6eOmLgJht6G3mPKMxYm75w2+qhAQZ+4X+1+ATZ+QFKeOZD5riHng== 167 | dependencies: 168 | component-emitter "1.2.1" 169 | debug "~3.1.0" 170 | isarray "2.0.1" 171 | 172 | to-array@0.1.4: 173 | version "0.1.4" 174 | resolved "https://registry.yarnpkg.com/to-array/-/to-array-0.1.4.tgz#17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890" 175 | integrity sha1-F+bBH3PdTz10zaek/zI46a2b+JA= 176 | 177 | ws@~6.1.0: 178 | version "6.1.4" 179 | resolved "https://registry.yarnpkg.com/ws/-/ws-6.1.4.tgz#5b5c8800afab925e94ccb29d153c8d02c1776ef9" 180 | integrity sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA== 181 | dependencies: 182 | async-limiter "~1.0.0" 183 | 184 | xmlhttprequest-ssl@~1.5.4: 185 | version "1.5.5" 186 | resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e" 187 | integrity sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4= 188 | 189 | yeast@0.1.2: 190 | version "0.1.2" 191 | resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" 192 | integrity sha1-AI4G2AlDIMNy28L47XagymyKxBk= 193 | -------------------------------------------------------------------------------- /packages/hackbox-demo/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /packages/hackbox-demo/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | 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. 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /packages/hackbox-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hackbox-demo", 3 | "version": "0.0.3", 4 | "private": true, 5 | "main": "src/index.js", 6 | "dependencies": { 7 | "express": "^4.17.0", 8 | "hackbox-client": "^0.0.3", 9 | "hackbox-server": "^0.0.3", 10 | "node-sass": "^4.13.0", 11 | "react": "^16.8.6", 12 | "react-dom": "^16.8.6", 13 | "react-router-dom": "^5.0.0", 14 | "react-scripts": "3.0.1", 15 | "socket.io-client": "^2.2.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 | "postinstall": "yarn link hackbox-server & yarn link hackbox-client", 23 | "start:server": "nodemon src/server" 24 | }, 25 | "eslintConfig": { 26 | "extends": "react-app" 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | }, 40 | "proxy": "http://localhost:8080", 41 | "devDependencies": { 42 | "nodemon": "^1.19.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/hackbox-demo/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomalama/hackbox/4f4daf30c6ab79a9ffbd76123d85210c5bb7c7ca/packages/hackbox-demo/public/favicon.ico -------------------------------------------------------------------------------- /packages/hackbox-demo/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | Hackbox Demo 23 | 24 | 25 | 26 |
27 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /packages/hackbox-demo/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 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/components/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { BrowserRouter, Switch, Route } from 'react-router-dom'; 3 | 4 | import Navbar from './Navbar'; 5 | import Landing from './Landing'; 6 | import Host from './Host'; 7 | 8 | function App() { 9 | return ( 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | ); 18 | } 19 | 20 | export default App; 21 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/components/Boggle.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | 3 | function Boggle() { 4 | const [letters, setLetters] = useState([]); 5 | 6 | useEffect(() => { 7 | const vowels = ['A', 'E', 'I', 'O', 'U']; 8 | const consonant = [ 9 | 'B', 10 | 'C', 11 | 'D', 12 | 'F', 13 | 'G', 14 | 'H', 15 | 'J', 16 | 'K', 17 | 'L', 18 | 'M', 19 | 'N', 20 | 'P', 21 | 'Q', 22 | 'R', 23 | 'S', 24 | 'T', 25 | 'V', 26 | 'W', 27 | 'X', 28 | 'Y', 29 | 'Z' 30 | ]; 31 | 32 | const letters = []; 33 | for (let i = 0; i < 16; i++) { 34 | if (i % 4 === 0) { 35 | letters.push(vowels[Math.floor(Math.random() * vowels.length)]); 36 | } else { 37 | letters.push(consonant[Math.floor(Math.random() * consonant.length)]); 38 | } 39 | } 40 | 41 | setLetters(letters); 42 | }, []); 43 | 44 | return ( 45 |
46 |
47 |
48 | {letters.map((letter, i) => ( 49 |
50 |
{letter}
51 |
52 | ))} 53 |
54 |
55 |
56 | ); 57 | } 58 | 59 | export default Boggle; 60 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/components/Host.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | import hackboxClient from 'hackbox-client'; 3 | 4 | function Host() { 5 | const [hackbox, setHackbox] = useState(false); 6 | const [room, setRoom] = useState({}); 7 | const [gameType, setGameType] = useState('demo'); 8 | 9 | useEffect(() => { 10 | const createRoom = async () => { 11 | const hackbox = await hackboxClient('http://localhost:8080'); 12 | setHackbox(hackbox); 13 | 14 | const room = await hackbox.createRoom(); 15 | console.log(room); 16 | setRoom(room); 17 | 18 | hackbox.onPlayerJoin(room => { 19 | console.log(room); 20 | setRoom(room); 21 | }); 22 | }; 23 | 24 | createRoom(); 25 | }, []); 26 | 27 | const onClickGameMode = gameType => { 28 | setGameType(gameType); 29 | } 30 | 31 | const onClickStartGame = () => { 32 | hackbox.startGame({roomId: room.id, gameType}); 33 | }; 34 | 35 | if (!Object.entries(room).length) { 36 | return
Loading...
; 37 | } 38 | 39 | return ( 40 |
41 |
42 |
43 |

Room ID: {room.id}

44 |
45 |
46 |

Game Mode

47 | 48 |
49 |
50 |

Players

51 |
    52 | {room.players.map(player => ( 53 |
  • {player.name}
  • 54 | ))} 55 |
56 |
57 |
58 |
59 | 60 |
61 |
62 | ); 63 | } 64 | 65 | export default Host; 66 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/components/Landing.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import hackboxClient from 'hackbox-client'; 3 | import Boggle from './Boggle'; 4 | 5 | function Landing() { 6 | const [roomId, setRoomId] = useState(''); 7 | const [playerName, setPlayerName] = useState(''); 8 | const [playerId, setPlayerId] = useState(''); 9 | const [gameType, setGameType] = useState(''); 10 | 11 | const onRoomIdChange = e => { 12 | const roomId = e.target.value; 13 | setRoomId(roomId); 14 | }; 15 | 16 | const onPlayerNameChange = e => { 17 | const playerName = e.target.value; 18 | setPlayerName(playerName); 19 | }; 20 | 21 | const onClickJoin = async () => { 22 | const hackbox = await hackboxClient('http://localhost:8080'); 23 | 24 | const playerId = await hackbox.joinRoom({ roomId, playerName }); 25 | setPlayerId(playerId); 26 | 27 | hackbox.onStartGame(gameType => { 28 | setGameType(gameType); 29 | }); 30 | }; 31 | 32 | if (gameType) { 33 | return ; 34 | } 35 | 36 | if (playerId) { 37 | return ( 38 |
39 |

Welcome {playerName}!

40 |
41 | ); 42 | } 43 | 44 | return ( 45 |
46 |
Landing
47 |
48 | 49 | 54 | 55 |
56 |
57 | ); 58 | } 59 | 60 | export default Landing; 61 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/components/Navbar.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Link } from 'react-router-dom'; 3 | 4 | function Navbar() { 5 | return ( 6 |
7 | 11 |
12 | ); 13 | } 14 | 15 | export default Navbar; 16 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl) 104 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/styles/Boggle.scss: -------------------------------------------------------------------------------- 1 | .Boggle { 2 | .Boggle__Wrapper { 3 | display: flex; 4 | justify-content: center; 5 | align-items: center; 6 | 7 | .Boggle__Grid { 8 | width: 400px; 9 | height: 400px; 10 | 11 | div { 12 | float: left; 13 | height: 25%; 14 | width: 25%; 15 | display: flex; 16 | justify-content: center; 17 | align-items: center; 18 | user-select: none; 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/client/styles/index.scss: -------------------------------------------------------------------------------- 1 | @import './Boggle.scss'; 2 | 3 | body { 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 6 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 7 | sans-serif; 8 | -webkit-font-smoothing: antialiased; 9 | -moz-osx-font-smoothing: grayscale; 10 | } 11 | 12 | code { 13 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 14 | monospace; 15 | } 16 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './client/styles/index.scss'; 4 | import App from './client/components/App'; 5 | import * as serviceWorker from './client/serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: https://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/server/gameReference.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | gameTypes: ['demo'], 3 | demo: { 4 | gameLength: 60000, 5 | validActionIds: [0, 1], 6 | description: `This is the description of the game. You have 60 seconds to compete` 7 | }, 8 | actions: { 9 | 0: { actionName: 'action1', threshold: 0 }, 10 | 1: { actionName: 'action2', threshold: 0 } 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /packages/hackbox-demo/src/server/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const path = require('path'); 3 | const hackbox = require('hackbox-server'); 4 | const gameReference = require('./gameReference'); 5 | 6 | const port = process.env.PORT || 8080; 7 | const app = express(); 8 | app.use(express.static('build')); 9 | 10 | app.get('/', function(req, res) { 11 | res.sendFile(path.join('build', 'index.html')); 12 | }); 13 | 14 | hackbox({ app, port }, gameReference); 15 | -------------------------------------------------------------------------------- /packages/hackbox-server/README.md: -------------------------------------------------------------------------------- 1 | # `hackbox-server` 2 | 3 | A Jackbox inspired framework for creating party games - server component. 4 | 5 | ## Usage 6 | 7 | ```javascript 8 | const hackbox = require("hackbox-server"); 9 | ``` 10 | 11 | ### Using Express 12 | 13 | ```javascript 14 | const express = require("express"); 15 | const path = require("path"); 16 | const hackbox = require("hackbox-server"); 17 | const gameReference = require("./gameReference"); 18 | 19 | const port = process.env.PORT || 8080; 20 | const app = express(); 21 | app.use(express.static("build")); 22 | 23 | app.get("/", function(req, res) { 24 | res.sendFile(path.join("build", "index.html")); 25 | }); 26 | 27 | hackbox({ app, port }, gameReference); 28 | ``` 29 | 30 | ### Game Reference 31 | 32 | ```javascript 33 | module.exports = { 34 | gameTypes: ["demo"], 35 | demo: { 36 | gameLength: 60000, 37 | validActionIds: [0, 1], 38 | description: `This is the description of the game. You have 60 seconds to compete` 39 | }, 40 | actions: { 41 | 0: { actionName: "action1" }, 42 | 1: { actionName: "action2" } 43 | } 44 | }; 45 | ``` 46 | -------------------------------------------------------------------------------- /packages/hackbox-server/lib/attachListeners.js: -------------------------------------------------------------------------------- 1 | const { PlayerManager, RoomManager } = require('./objects'); 2 | const { generateId } = require('./utils'); 3 | 4 | const players = new PlayerManager(); 5 | const roomManager = new RoomManager(); 6 | 7 | function attachListeners (io, gameReference) { 8 | io.on('connect', socket => { 9 | /** 10 | * Room events 11 | */ 12 | socket.on('hb-createRoom', () => { 13 | const id = generateId(); 14 | socket.join(id); 15 | const room = roomManager.addRoom(id, socket.id, 8); 16 | io.to(id).emit('hb-roomData', room); 17 | }); 18 | 19 | // socket.on('hb-setGameType', ({ roomId, gameType }) => { 20 | // const players = roomManager.getPlayers(roomId); 21 | 22 | // players.forEach(player => { 23 | // io.to(player.socketId).emit( 24 | // 'hb-setGameType', 25 | // gameReference[gameType] 26 | // ); 27 | // }); 28 | // }); 29 | 30 | socket.on('hb-startGame', ({ roomId, gameType }) => { 31 | const players = roomManager.getPlayers(roomId); 32 | 33 | players.forEach(player => { 34 | io.to(player.socketId).emit('hb-gameStart', gameType); 35 | }); 36 | 37 | setTimeout(() => { 38 | const players = roomManager.getPlayers(roomId); 39 | 40 | players.forEach(player => { 41 | io.to(player.socketId).emit('hb-gameOver'); 42 | }); 43 | }, gameReference[gameType].gameLength); 44 | }); 45 | 46 | /** 47 | * Player events 48 | */ 49 | socket.on('hb-joinRoom', ({ roomId, playerName }) => { 50 | if (roomManager.roomExists(roomId) === false) { 51 | io.to(socket.id).emit('hb-error', 'Room not found'); 52 | return; 53 | } 54 | 55 | const room = roomManager.getRoom(roomId); 56 | if (room.players.length >= room.maxPlayers) { 57 | io.to(socket.id).emit('hb-error', 'Room is full'); 58 | return; 59 | } 60 | 61 | const playerId = generateId(); 62 | const newPlayer = players.addPlayer({ id: playerId, roomId, socketId: socket.id, name: playerName }); 63 | roomManager.addPlayer(roomId, newPlayer); 64 | 65 | io.to(room.socketId).emit('hb-onPlayerJoin', room); 66 | io.to(socket.id).emit('hb-roomConnectionSuccessful', playerId); 67 | }); 68 | 69 | socket.on('hb-leaveRoom', () => {}); 70 | 71 | socket.on('hb-getUpdatedData', data => { 72 | const room = roomManager.getRoom(data.id); 73 | 74 | io.to(room.socketId).emit('hb-update', room); 75 | }); 76 | 77 | socket.on('hb-playerAction', data => { 78 | const room = roomManager.getRoom(data.id); 79 | 80 | switch (data.gameType) { 81 | case 'squatRace': 82 | if (data.actionType === 'squat') { 83 | roomManager.addToPlayerScore(data.id, data.playerId, 1); 84 | io.to(room.socketId).emit('hb-updateData', room); 85 | } 86 | break; 87 | default: 88 | break; 89 | } 90 | }); 91 | 92 | socket.on('hb-playerStatusUpdate', data => { 93 | const room = roomManager.getRoom(data.id); 94 | 95 | roomManager.updatePlayerStatus( 96 | data.id, 97 | data.playerId, 98 | data.playerIsReady 99 | ); 100 | 101 | if (roomManager.allReady(data.id)) { 102 | io.to(room.socketId).emit('hb-playersReady', true); 103 | } else { 104 | io.to(room.socketId).emit('hb-playersReady', false); 105 | } 106 | 107 | io.to(room.socketId).emit('hb-updateData', room); 108 | }); 109 | }); 110 | 111 | io.on('hb-disconnect', socket => {}); 112 | } 113 | 114 | module.exports = attachListeners; 115 | -------------------------------------------------------------------------------- /packages/hackbox-server/lib/index.js: -------------------------------------------------------------------------------- 1 | const attachListeners = require('./attachListeners'); 2 | 3 | const hackbox = ({ app, port, isSecure = false }, gameReference) => { 4 | const server = require(isSecure ? 'https' : 'http').Server(app); 5 | const io = require('socket.io').listen(server); 6 | 7 | attachListeners(io, gameReference); 8 | 9 | server.listen(port, () => console.log(`Hackbox online on port ${port}!`)); 10 | }; 11 | 12 | module.exports = hackbox; 13 | -------------------------------------------------------------------------------- /packages/hackbox-server/lib/objects/index.js: -------------------------------------------------------------------------------- 1 | const PlayerManager = require('./playerManager'); 2 | const RoomManager = require('./roomManager'); 3 | 4 | module.exports = { 5 | PlayerManager, 6 | RoomManager 7 | }; 8 | -------------------------------------------------------------------------------- /packages/hackbox-server/lib/objects/playerManager.js: -------------------------------------------------------------------------------- 1 | class PlayerManager { 2 | constructor () { 3 | this.players = []; 4 | } 5 | 6 | addPlayer ({ id, roomId, socketId, name }) { 7 | const player = { 8 | id, 9 | roomId, 10 | socketId, 11 | name, 12 | isReady: false, 13 | score: 0 14 | }; 15 | this.players.push(player); 16 | return player; 17 | } 18 | 19 | removePlayer (id) { 20 | const removedPlayer = this.players.find(player => player.id === id); 21 | 22 | if (removedPlayer) { 23 | this.players = this.players.filter(player => player.id !== id); 24 | } 25 | 26 | return removedPlayer; 27 | } 28 | 29 | getPlayer (id) { 30 | return this.players.find(player => player.id === id); 31 | } 32 | } 33 | 34 | module.exports = PlayerManager; 35 | -------------------------------------------------------------------------------- /packages/hackbox-server/lib/objects/roomManager.js: -------------------------------------------------------------------------------- 1 | class RoomManager { 2 | constructor () { 3 | this.rooms = []; 4 | } 5 | 6 | addRoom (id, socketId, maxPlayers) { 7 | const room = { id, socketId, maxPlayers, players: [] }; 8 | this.rooms.push(room); 9 | return room; 10 | } 11 | 12 | removeRoom (id) { 13 | const removedRoom = this.rooms.filter(room => room.id === id)[0]; 14 | 15 | if (removedRoom) { 16 | this.room = this.rooms.filter(room => room.id !== id); 17 | } 18 | 19 | return removedRoom; 20 | } 21 | 22 | getRoom (id) { 23 | return this.rooms.find(room => room.id === id); 24 | } 25 | 26 | addPlayer (roomId, player) { 27 | const room = this.getRoom(roomId); 28 | 29 | if (room.players.length >= room.maxPlayers) { 30 | return false; 31 | } 32 | 33 | room.players.push(player); 34 | } 35 | 36 | removePlayer (roomId, playerId) { 37 | const room = this.getRoom(roomId); 38 | 39 | room.players.filter(player => player.playerId !== playerId); 40 | } 41 | 42 | getPlayers (roomId) { 43 | const room = this.getRoom(roomId); 44 | return room.players; 45 | } 46 | 47 | updatePlayerStatus (roomId, playerId, playerIsReady) { 48 | const room = this.getRoom(roomId); 49 | const player = room.players.filter( 50 | player => player.playerId === playerId 51 | )[0]; 52 | 53 | if (player == null) { 54 | return false; 55 | } 56 | 57 | player.isReady = playerIsReady; 58 | } 59 | 60 | addToPlayerScore (roomId, playerId, amount) { 61 | const room = this.getRoom(roomId); 62 | const player = room.players.filter( 63 | player => player.playerId === playerId 64 | )[0]; 65 | 66 | if (player == null) { 67 | return false; 68 | } 69 | 70 | player.score += amount; 71 | } 72 | 73 | allReady (roomId) { 74 | const room = this.getRoom(roomId); 75 | room.players.forEach(player => { 76 | if (player.isReady === false) { 77 | return false; 78 | } 79 | }); 80 | 81 | return true; 82 | } 83 | 84 | roomExists (id) { 85 | const found = this.rooms.find(room => room.id === id); 86 | 87 | if (found) { 88 | return true; 89 | } 90 | 91 | return false; 92 | } 93 | } 94 | 95 | module.exports = RoomManager; 96 | -------------------------------------------------------------------------------- /packages/hackbox-server/lib/utils.js: -------------------------------------------------------------------------------- 1 | const generateId = () => { 2 | return Math.random() 3 | .toString(36) 4 | .substr(2, 5) 5 | .toUpperCase(); 6 | }; 7 | 8 | module.exports = { generateId }; 9 | -------------------------------------------------------------------------------- /packages/hackbox-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hackbox-server", 3 | "version": "0.0.3", 4 | "description": "A Jackbox inspired framework for creating party games - server component", 5 | "keywords": [ 6 | "realtime", 7 | "framework", 8 | "websocket", 9 | "events", 10 | "socket", 11 | "server", 12 | "jackbox", 13 | "party", 14 | "games" 15 | ], 16 | "author": "tomalama ", 17 | "homepage": "https://github.com/tomalama/hackbox/tree/master/packages/hackbox-server", 18 | "license": "MIT", 19 | "main": "lib/index.js", 20 | "directories": { 21 | "lib": "lib" 22 | }, 23 | "files": [ 24 | "lib" 25 | ], 26 | "publishConfig": { 27 | "registry": "https://registry.npmjs.org/" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/tomalama/hackbox/tree/master/packages/hackbox-server" 32 | }, 33 | "scripts": { 34 | "test": "echo \"Not yet implemented\" && exit 0" 35 | }, 36 | "dependencies": { 37 | "socket.io": "^2.2.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/hackbox-server/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | accepts@~1.3.4: 6 | version "1.3.7" 7 | resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd" 8 | integrity sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA== 9 | dependencies: 10 | mime-types "~2.1.24" 11 | negotiator "0.6.2" 12 | 13 | after@0.8.2: 14 | version "0.8.2" 15 | resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f" 16 | integrity sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8= 17 | 18 | arraybuffer.slice@~0.0.7: 19 | version "0.0.7" 20 | resolved "https://registry.yarnpkg.com/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz#3bbc4275dd584cc1b10809b89d4e8b63a69e7675" 21 | integrity sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog== 22 | 23 | async-limiter@~1.0.0: 24 | version "1.0.0" 25 | resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" 26 | integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg== 27 | 28 | backo2@1.0.2: 29 | version "1.0.2" 30 | resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" 31 | integrity sha1-MasayLEpNjRj41s+u2n038+6eUc= 32 | 33 | base64-arraybuffer@0.1.5: 34 | version "0.1.5" 35 | resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz#73926771923b5a19747ad666aa5cd4bf9c6e9ce8" 36 | integrity sha1-c5JncZI7Whl0etZmqlzUv5xunOg= 37 | 38 | base64id@1.0.0: 39 | version "1.0.0" 40 | resolved "https://registry.yarnpkg.com/base64id/-/base64id-1.0.0.tgz#47688cb99bb6804f0e06d3e763b1c32e57d8e6b6" 41 | integrity sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY= 42 | 43 | better-assert@~1.0.0: 44 | version "1.0.2" 45 | resolved "https://registry.yarnpkg.com/better-assert/-/better-assert-1.0.2.tgz#40866b9e1b9e0b55b481894311e68faffaebc522" 46 | integrity sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI= 47 | dependencies: 48 | callsite "1.0.0" 49 | 50 | blob@0.0.5: 51 | version "0.0.5" 52 | resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.5.tgz#d680eeef25f8cd91ad533f5b01eed48e64caf683" 53 | integrity sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig== 54 | 55 | callsite@1.0.0: 56 | version "1.0.0" 57 | resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20" 58 | integrity sha1-KAOY5dZkvXQDi28JBRU+borxvCA= 59 | 60 | component-bind@1.0.0: 61 | version "1.0.0" 62 | resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" 63 | integrity sha1-AMYIq33Nk4l8AAllGx06jh5zu9E= 64 | 65 | component-emitter@1.2.1: 66 | version "1.2.1" 67 | resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" 68 | integrity sha1-E3kY1teCg/ffemt8WmPhQOaUJeY= 69 | 70 | component-inherit@0.0.3: 71 | version "0.0.3" 72 | resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143" 73 | integrity sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM= 74 | 75 | cookie@0.3.1: 76 | version "0.3.1" 77 | resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" 78 | integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s= 79 | 80 | debug@~3.1.0: 81 | version "3.1.0" 82 | resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" 83 | integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== 84 | dependencies: 85 | ms "2.0.0" 86 | 87 | debug@~4.1.0: 88 | version "4.1.1" 89 | resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" 90 | integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== 91 | dependencies: 92 | ms "^2.1.1" 93 | 94 | engine.io-client@~3.3.1: 95 | version "3.3.2" 96 | resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-3.3.2.tgz#04e068798d75beda14375a264bb3d742d7bc33aa" 97 | integrity sha512-y0CPINnhMvPuwtqXfsGuWE8BB66+B6wTtCofQDRecMQPYX3MYUZXFNKDhdrSe3EVjgOu4V3rxdeqN/Tr91IgbQ== 98 | dependencies: 99 | component-emitter "1.2.1" 100 | component-inherit "0.0.3" 101 | debug "~3.1.0" 102 | engine.io-parser "~2.1.1" 103 | has-cors "1.1.0" 104 | indexof "0.0.1" 105 | parseqs "0.0.5" 106 | parseuri "0.0.5" 107 | ws "~6.1.0" 108 | xmlhttprequest-ssl "~1.5.4" 109 | yeast "0.1.2" 110 | 111 | engine.io-parser@~2.1.0, engine.io-parser@~2.1.1: 112 | version "2.1.3" 113 | resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-2.1.3.tgz#757ab970fbf2dfb32c7b74b033216d5739ef79a6" 114 | integrity sha512-6HXPre2O4Houl7c4g7Ic/XzPnHBvaEmN90vtRO9uLmwtRqQmTOw0QMevL1TOfL2Cpu1VzsaTmMotQgMdkzGkVA== 115 | dependencies: 116 | after "0.8.2" 117 | arraybuffer.slice "~0.0.7" 118 | base64-arraybuffer "0.1.5" 119 | blob "0.0.5" 120 | has-binary2 "~1.0.2" 121 | 122 | engine.io@~3.3.1: 123 | version "3.3.2" 124 | resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-3.3.2.tgz#18cbc8b6f36e9461c5c0f81df2b830de16058a59" 125 | integrity sha512-AsaA9KG7cWPXWHp5FvHdDWY3AMWeZ8x+2pUVLcn71qE5AtAzgGbxuclOytygskw8XGmiQafTmnI9Bix3uihu2w== 126 | dependencies: 127 | accepts "~1.3.4" 128 | base64id "1.0.0" 129 | cookie "0.3.1" 130 | debug "~3.1.0" 131 | engine.io-parser "~2.1.0" 132 | ws "~6.1.0" 133 | 134 | has-binary2@~1.0.2: 135 | version "1.0.3" 136 | resolved "https://registry.yarnpkg.com/has-binary2/-/has-binary2-1.0.3.tgz#7776ac627f3ea77250cfc332dab7ddf5e4f5d11d" 137 | integrity sha512-G1LWKhDSvhGeAQ8mPVQlqNcOB2sJdwATtZKl2pDKKHfpf/rYj24lkinxf69blJbnsvtqqNU+L3SL50vzZhXOnw== 138 | dependencies: 139 | isarray "2.0.1" 140 | 141 | has-cors@1.1.0: 142 | version "1.1.0" 143 | resolved "https://registry.yarnpkg.com/has-cors/-/has-cors-1.1.0.tgz#5e474793f7ea9843d1bb99c23eef49ff126fff39" 144 | integrity sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk= 145 | 146 | indexof@0.0.1: 147 | version "0.0.1" 148 | resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" 149 | integrity sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10= 150 | 151 | isarray@2.0.1: 152 | version "2.0.1" 153 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.1.tgz#a37d94ed9cda2d59865c9f76fe596ee1f338741e" 154 | integrity sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4= 155 | 156 | mime-db@1.40.0: 157 | version "1.40.0" 158 | resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.40.0.tgz#a65057e998db090f732a68f6c276d387d4126c32" 159 | integrity sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA== 160 | 161 | mime-types@~2.1.24: 162 | version "2.1.24" 163 | resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.24.tgz#b6f8d0b3e951efb77dedeca194cff6d16f676f81" 164 | integrity sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ== 165 | dependencies: 166 | mime-db "1.40.0" 167 | 168 | ms@2.0.0: 169 | version "2.0.0" 170 | resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" 171 | integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= 172 | 173 | ms@^2.1.1: 174 | version "2.1.1" 175 | resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" 176 | integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== 177 | 178 | negotiator@0.6.2: 179 | version "0.6.2" 180 | resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb" 181 | integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw== 182 | 183 | object-component@0.0.3: 184 | version "0.0.3" 185 | resolved "https://registry.yarnpkg.com/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291" 186 | integrity sha1-8MaapQ78lbhmwYb0AKM3acsvEpE= 187 | 188 | parseqs@0.0.5: 189 | version "0.0.5" 190 | resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d" 191 | integrity sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0= 192 | dependencies: 193 | better-assert "~1.0.0" 194 | 195 | parseuri@0.0.5: 196 | version "0.0.5" 197 | resolved "https://registry.yarnpkg.com/parseuri/-/parseuri-0.0.5.tgz#80204a50d4dbb779bfdc6ebe2778d90e4bce320a" 198 | integrity sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo= 199 | dependencies: 200 | better-assert "~1.0.0" 201 | 202 | socket.io-adapter@~1.1.0: 203 | version "1.1.1" 204 | resolved "https://registry.yarnpkg.com/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz#2a805e8a14d6372124dd9159ad4502f8cb07f06b" 205 | integrity sha1-KoBeihTWNyEk3ZFZrUUC+MsH8Gs= 206 | 207 | socket.io-client@2.2.0: 208 | version "2.2.0" 209 | resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-2.2.0.tgz#84e73ee3c43d5020ccc1a258faeeb9aec2723af7" 210 | integrity sha512-56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQWu92yyWICxB0u7wkVbYA== 211 | dependencies: 212 | backo2 "1.0.2" 213 | base64-arraybuffer "0.1.5" 214 | component-bind "1.0.0" 215 | component-emitter "1.2.1" 216 | debug "~3.1.0" 217 | engine.io-client "~3.3.1" 218 | has-binary2 "~1.0.2" 219 | has-cors "1.1.0" 220 | indexof "0.0.1" 221 | object-component "0.0.3" 222 | parseqs "0.0.5" 223 | parseuri "0.0.5" 224 | socket.io-parser "~3.3.0" 225 | to-array "0.1.4" 226 | 227 | socket.io-parser@~3.3.0: 228 | version "3.3.0" 229 | resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.0.tgz#2b52a96a509fdf31440ba40fed6094c7d4f1262f" 230 | integrity sha512-hczmV6bDgdaEbVqhAeVMM/jfUfzuEZHsQg6eOmLgJht6G3mPKMxYm75w2+qhAQZ+4X+1+ATZ+QFKeOZD5riHng== 231 | dependencies: 232 | component-emitter "1.2.1" 233 | debug "~3.1.0" 234 | isarray "2.0.1" 235 | 236 | socket.io@^2.2.0: 237 | version "2.2.0" 238 | resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-2.2.0.tgz#f0f633161ef6712c972b307598ecd08c9b1b4d5b" 239 | integrity sha512-wxXrIuZ8AILcn+f1B4ez4hJTPG24iNgxBBDaJfT6MsyOhVYiTXWexGoPkd87ktJG8kQEcL/NBvRi64+9k4Kc0w== 240 | dependencies: 241 | debug "~4.1.0" 242 | engine.io "~3.3.1" 243 | has-binary2 "~1.0.2" 244 | socket.io-adapter "~1.1.0" 245 | socket.io-client "2.2.0" 246 | socket.io-parser "~3.3.0" 247 | 248 | to-array@0.1.4: 249 | version "0.1.4" 250 | resolved "https://registry.yarnpkg.com/to-array/-/to-array-0.1.4.tgz#17e6c11f73dd4f3d74cda7a4ff3238e9ad9bf890" 251 | integrity sha1-F+bBH3PdTz10zaek/zI46a2b+JA= 252 | 253 | ws@~6.1.0: 254 | version "6.1.4" 255 | resolved "https://registry.yarnpkg.com/ws/-/ws-6.1.4.tgz#5b5c8800afab925e94ccb29d153c8d02c1776ef9" 256 | integrity sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA== 257 | dependencies: 258 | async-limiter "~1.0.0" 259 | 260 | xmlhttprequest-ssl@~1.5.4: 261 | version "1.5.5" 262 | resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e" 263 | integrity sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4= 264 | 265 | yeast@0.1.2: 266 | version "0.1.2" 267 | resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" 268 | integrity sha1-AI4G2AlDIMNy28L47XagymyKxBk= 269 | --------------------------------------------------------------------------------