Boilerplate for building multiplayer games for the tv.
TVPARTY is a react app/node server with some helpers on place for building real-time multiplayer games like kahoot or jackbox.
Take a look at the example game included for a super simple example.
For an idea of what you could do, check out the demo (source).
1: Clone the repo
2: Add config variables
TVPARTY uses firebase for the real-time database. Create a new firebase app and copy the config variables to the
/constants/config.js
file.
3: Start the client and server
npm install
npm start
node server
TVPARTY provides a few helper methods and events, but it's up to you to build your own games.
TIP: Have a look at the example repo inspiration.
To create a new game:
- 1: Create a new folder in the
/Games
directory to hold your game logic. - 2: Add any static assets (images etc) to the
/public/assets/[gameName]
folder. - 3: Add your game to the
/Games/games.js
file to make it available to the app. - 4: Go wild!
The GameWrapper
is a higher-order component that will provides the following props and API to your game.
Props:
isHost - (Bool) True if host, false if player
gameData - (Object) All game data (real-time)
gameCode - (String) 4-digit game code
currentPlayer - (Object) Current player data
currentPlayerId - (String) Current player id
socket - (Object) Socket.io object (for attaching event listeners)
Events:
Post updates to firebase
- gameCode (String) 4-digit code of game to modify
- data (Object) Data object (replaces old data)
Post updates to firebase
- gameCode (String) 4-digit code of game to modify
- playerId (String) playerId to modify
- data (Object) Data object (replaces old data)
Send generic websocket event from player. (Events are sent to players in current room only!)
- data (Object) Data to send
// In gamepad.js (player controller)
this.props.sendEvent({
type: 'submitClicked',
player: playerName,
});
// In splash.js (A game host scene)
this.props.socket.on('event', data => {
if (data.type === 'submitClicked') {
console.log('submit clicked!', data);
}
};
Text-to-speech output with queuing built in using the native webSpeechAPI.
- message (string) The text to read aloud
this.props.speak(`${data.name} has joined the game!`);
If you want automatic linting (using prettier), add the prettier ext to your editor and enable formatOnSave
.
The /Primitives
folder contains a bunch of useful UI elements you can use. These are built with styled components. You're free to create your own UI and style it however you like.