This is not an official Google product.
We decided to get a little crazy and build a real time, crowdsourced, and live streamed gaming platform.
Imagine players all over the world shouting "up! down! left! right!" into their computers and phones to control a common character while chatting in different languages.
Inspired by Twitch Plays Pokémon, this game uses Firebase to crowdsource input from thousands of players in real time, then a Node.js process running on a Google Compute Engine Windows VM sends these crowdsourced commands to a game, and live streams it all to YouTube.
The game's web front end uses the power of Google Cloud Machine Learning to enable realtime voice transcription and translation.
Finally, BigQuery gives us the power of big data to analyse all the commands and find interesting patterns.
This is originally presented at Google I/O 2016. You can watch the talk here:
There are three components of this demo that run in the cloud:
- Firebase handles all of the real-time data syncing between multiple players and the game server. Firebase will handle relaying commands from every player to the server, as well as syncing chat messages between players.
- The game server is a Windows virtual machine running on Google Compute Engine. It runs the game natively, relays user commands to the game, and streams everything to YouTube Live.
- BigQuery is the cloud data analytics platform that will receive all game events, and supports using SQL to query various reports.
- Create a new Firebase project.
- Click Add Firebase to your web app to get the Firebase and Google Cloud Platform connection settings:
- API key
- Database URL
- Project ID.
Follow the instructions here to extract your project ID.
The settings should look something like:
var config = {
apiKey: '...',
databaseURL: '...',
projectId: '...'
};
Replace the placeholders in frontend/config.js with these values.
We require users to be authenticated to write messages to the chat node or read from the commands queue. These rules will be automatically deployed as they are included in the firebase.json file.
{
"rules": {
"chat": {
".read": true,
".write": "auth != null"
},
"commands-archive": {
".read": false,
".write": "auth != null"
},
"commands": {
".read": "auth != null",
".write": true
}
}
}
Create a service account that you'll upload to your game server created in the next step.
- Create a service account for your Firebase project.
- Select Furnish a new private key and select type JSON. Rename this file
to
firebase-plays.json
. Save this file; you'll upload it to your game server in the next section.
- Click here to make sure the Cloud Speech API is enabled for your project.
- Click here to make sure the Cloud Translate API is enabled for your project.
Create a Windows virtual machine using the Cloud Launcher. Click Launch on Compute Engine and then click Create on the next page.
Install the following on the Windows virtual machine:
- Google Chrome
- gcloud - the Cloud SDK for Google Cloud Platform.
- Node.js
- Python
- Visual Studio Express 2013 to address this MSBUILD issue.
- Install git
- Set up YouTube live streaming on your YouTube channel, and install an encoder on your Windows virtual machine.
- Get your YouTube live stream channel URL and paste it into frontend/index.html.
- Go to the BigQuery page for your project.
- Create a new dataset named
firebase_plays
. - Create a new table named
commands
. Under schema, click Edit as Text and paste in the contents of the table-schema.json file.
Make sure you have the Firebase SDK installed. You can install it with this command:
npm install -g firebase-tools
To deploy, run the following command in the frontend
folder:
firebase deploy --project <YOUR-PROJECT-ID>
- Install and run whatever game you'd like to run on your game server. The script only supports the arrow keys on the keyboard by default.
- On the Windows game server, run the following commands in the git bash terminal:
git clone https://github.com/bretmcg/firebaseplays
cd backend/game-controller
- Copy the Firebase service account
firebase-plays.json
that you created in a previous step tobackend/game-controller
on the Windows game server. - Edit
config.js
to include the API key, Project ID, Auth Domain, and Database URL values from your Firebase project. npm install
node game-controller.js
- Click the running game to ensure it has focus so game-controller.js can relay keystrokes into the game.
SELECT command, count(command) FROM [social_gaming.game_commands] GROUP BY command
SELECT city, count(*) AS count FROM [social_gaming.game_commands] GROUP BY city
SELECT
STRFTIME_UTC_USEC([timestamp], '%I %p') AS hour, count(*) AS count
FROM
[social_gaming.game_commands]
GROUP BY
hour