forked from luiscuenca/Spatial-Audio-API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (39 loc) · 1.7 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
const { default: SignJWT } = require('jose/jwt/sign');
const express = require('express');
const crypto = require('crypto');
// This is your "App ID" as obtained from the High Fidelity Audio API Developer Console. Do not share this string.
const APP_ID = "";
// This is your "Space ID" as obtained from the High Fidelity Audio API Developer Console. Do not share this string.
const SPACE_ID = "";
// This is the "App Secret" as obtained from the High Fidelity Audio API Developer Console. Do not share this string.
const APP_SECRET = "";
const SECRET_KEY_FOR_SIGNING = crypto.createSecretKey(Buffer.from(APP_SECRET, "utf8"));
const app = express();
const PORT = 8080;
app.set('view engine', 'ejs');
async function generateJWT(userID) {
let hiFiJWT;
try {
hiFiJWT = await new SignJWT({
"user_id": userID,
"app_id": APP_ID,
"space_id": SPACE_ID
})
.setProtectedHeader({ alg: 'HS256', typ: 'JWT' })
.sign(SECRET_KEY_FOR_SIGNING);
return hiFiJWT;
} catch (error) {
console.error(`Couldn't create JWT! Error:\n${error}`);
return;
}
}
const RANDOM_NAMES = ['Steve', 'Lashawna', 'Erline', 'Connie', 'Keven', 'Tiesha', 'Hoyt', 'Sheldon', 'Jolyn', 'Dorcas', 'Young'];
app.get('/hackathon', async (req, res) => {
let providedUserID = `${RANDOM_NAMES[Math.floor(Math.random() * RANDOM_NAMES.length)]}${Math.floor(Math.random() * Math.floor(100))}`;
let hiFiJWT = await generateJWT(providedUserID);
res.render('index', { providedUserID, hiFiJWT });
});
app.listen(PORT, () => {
console.log(`The High Fidelity Sample App is ready and listening at http://localhost:${PORT}`)
});
app.use(express.static('public'));