Start
AudioProps holds the voice lines of several games and serves them to the games. Every route is under
, answers JSON (errors: { "error": "…" }) and is open to any origin (CORS).
- Reading a game and its audio needs no key.
- Writing (events, lines, main files, languages…) needs a key: the admin key, or an API key limited to one game and some permissions.
- A web game can skip the routes and load
audioprops.js.
The data
A game is a voices.json. Its events and lines are written in its base language (jeu.lang);
only the audio is declined in its other languages (jeu.langs, the base one first).
{
"jeu": { "titre": "Future War 2029", "description": "…", "lang": "fr", "langs": ["fr", "en"] },
"global": { "voix": [1, 3], "intervalle": [1, 2], "volume": 1, "cooldown": 6 },
"evenements": {
"hk_detected": {
"titre": "HK patrol detected", "quand": "The siren…", "chance": 1,
"memeQue": "other_event", // optional: says the lines of another event
"desactive": true, // optional: never said
"lignes": [
{ "qui": "soldier", "texte": "Planquez vous", "ton": "Cri / alerte", "desactive": true,
"langs": {
"fr": { "fichier": "planquez_vous.ogg", "proposals": ["planquez_vous.ogg", "planquez_vous_p1a2b3c.ogg"] },
"en": { "fichier": false, "proposals": [] } } }
] } } }
fichier is the main file of the line in that language (false: not recorded yet).
proposals are the files proposed for it; the ones after fichier are the new ones.
A line is known by its event and its index in lignes — nothing is ever deleted, so the index never moves.
The write routes also take its texte, to check the file didn't change in between (else 409).
Read routes no key
GET /api/games | The games: [{ id, titre, description, lang, langs, legacy, events, lines, done, progress }] |
GET /api/games/game/info | One game: lang (base), langs, progress: { lang: { done, new } }… legacy: true for a voices.json from before the languages (its routes per language answer 409 until its base language is set). |
GET /api/games/game/lang | Its voices.json in one language: each line holds fichier and proposals of that language, lang is at the top. What a game reads. |
GET /api/games/game/lang/audio/fichier | An audio file of that language (ogg, wav…, supports Range). |
GET /api/games/game | The whole voices.json, every language. |
POST /api/games/game/lang/propose | Propose a file for a line — open to anyone. Query: event, line, texte, name (its file name, for the extension); body: the raw audio. With main=1 (permission audio), it's the main file at once. Answers { file, main, voices }. |
GET /api/perms | The permissions and the routes that need them. |
Keys
Send the key in a header — Authorization: Bearer key, or X-Api-Key: key.
- The admin key (
.admin_keynext toserver.js) can do everything, on every game. - An API key (
ap_…) is for one game, or for every game (*), with the permissions it was given. They are made and deleted on the server only, withkeys.js:
node keys.js create future_war_2029 --perms event,line,audio --name "Game build"
node keys.js create future_war_2029 --all # every permission, present and future
node keys.js create '*' --perms games,lang # every game
node keys.js list [game]
node keys.js delete <id or key>
node keys.js perms
The key is shown once, when it's made: the server keeps only its hash. A deleted key stops working at once.
GET /api/auth tells what the key you send can do: { admin, game, perms, id, name }
(401 without a valid key). A key with the wrong game or without the permission gets a 403.
The studio pages take an API key too (the Admin button): they can then do what it allows.
Permissions
| Loading… |
Write routes key
All POST with a JSON body (Content-Type: application/json). They answer the new
{ voices } (the whole voices.json) — except creating a game, which answers its info.
| Route | Permission | Body |
|---|---|---|
/api/admin/games | games | { id, titre, lang, description? } — a new game; lang is its base language. Answers its info. |
/api/games/game/admin/game | game | { titre, description?, global? } — global: the settings object, replaced whole. |
…/admin/migrate | lang | { lang } — gives an old voices.json its base language: its files become those of that language. |
…/admin/lang-add | lang | { lang } — a code like en, pt-br. |
…/admin/lang-remove | lang | { lang } — not the base one, and only while none of its lines has a file in it. |
…/admin/event | event | { key, titre, quand?, chance?, memeQue? } — key: lowercase, digits, _; what the game triggers. |
…/admin/event-edit | event | { event, titre, quand?, chance?, key? } — key renames the event (the events whose memeQue is it follow; the game code must trigger the new key). |
…/admin/line | line | { event, qui, texte, ton } — added at the end of the event. |
…/admin/disable | disable | { event, desactive } or { event, line, texte, desactive } |
…/admin/main | audio | { event, line, texte, lang, file } — file: one of its proposals in that language, or false to remove the main file (it stays a proposal). |
…/admin/proposal-delete | delete | { event, line, texte, lang, file } — not the main file; the file goes to trash/lang/. |
…/lang/propose?…&main=1 | audio | Upload a file straight as the main file (see propose). |
Errors
400 | A bad body or query (the message says which field). |
401 | No key, or an unknown one. |
403 | The key is for another game, or lacks the permission. |
404 | Unknown game, language, event, line or file. |
409 | voices.json changed under you (reload it), something already exists, or the game has no languages yet. |
413 / 415 | The audio is over 25 MB / not an audio type. |
Examples
audioprops.js
The client a web game loads from this server. It reads the game in a language and says its events the way
voices.json describes them: chance, global.cooldown, 1 to 3 lines
(global.voix) by different speakers, global.intervalle between them,
desactive, memeQue. The files are played as they are. Try it on the demo.
The language: the one given, else the first of the browser's languages the game has, else its base one.
Also: events(), lines(key), load() (read again), stop(),
volume, muted, lang, langs, baseLang,
on('trigger' | 'error', fn).