forked from ably-labs/LED-Matrix-Jumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (25 loc) · 1.27 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const JumperApi = require("./commands/JumperApi");
const express = require("express");
const bodyParser = require('body-parser');
const app = express();
// Configure express to support parsing base64 chunks of audio in json
// The default message body that can be parsed is ~100kb, and our audio
// snippets are going to be a little bit longer than that (200-300kb)
// 50mb is probably... somewhat gracious, but ¯\_(ツ)_/¯
app.use(bodyParser.json({limit: '50mb'}));
// Serve our front-end HTML for audio recording
app.use(express.static("public"));
app.use("/", express.static(__dirname + "/public", { index: "index.html" }));
// Create instance of the Jumper API and wire it up to our Urls
// /active-image maps to getActiveImageKey() - returns the most recently identified image-key.
// /what-song accepts a json wrapped base64 encoded ogg-opus audio snippet from the MediaRecorder browser API
const jumperApiSingleton = new JumperApi();
app.get("/active-image", async (request, response) => {
const result = await jumperApiSingleton.getActiveImageKey();
response.send(result.body);
});
app.post("/what-song", async (request, response) => {
const result = await jumperApiSingleton.detectSongFromClip(request.body.bytes);
response.send(result);
});
module.exports = app;