This section covers documentation on the protocol that is invariant between leagues. It describes the authorization, starting a new game, and the general game loop that each game will send the game state and how players should send their desired actions.
Once you sign up for a game, you can retrieve your credentials in your profile and use them to join games.
{"id": "123-123-1234","secret": "12323123123"}
Make an HTTP POST
request to https://brawl.dev/api/games
with a JSON formatted body containing the id
and secret
. You'll receive a websocket url in the response under the property url
.
Request Body:
{"id": "123-123-1234","secret": "12323123123","league": "xxxxx"}
Response Body:
{"url": "wss://xxx-xxx-xxx-xxx.game.brawl.dev/xxx/yyy/zzz"}
Examples:
const {data: { url }} = await axios.post("https://brawl.dev/api/games", {id: process.env.BRAWL_ID,secret: process.env.BRAWL_SECRET,league: process.env.BRAWL_LEAGUE};
Once you receive the URL, you have 3 seconds to join and play the game. Create a new websocket connection to the URL and start waiting for a message.
const ws = new WebSocket(url);ws.on("message", function(data) {const gameState = JSON.parse(data);// process gameState here and decide on what action to take.const action = {};ws.send(JSON.stringify(action));});
Once the game is complete the websocket connection will close automatically. You can see the outcome in your game history in your profile