Improved node application server

This commit is contained in:
Carlos Santos 2023-10-16 10:32:43 +02:00
parent 94ace9e355
commit dc1edc5b5b
2 changed files with 9 additions and 0 deletions

View File

@ -1,3 +1,4 @@
SERVER_PORT=5000
LIVEKIT_URL=ws://localhost:7880/
LIVEKIT_API_KEY=devkey
LIVEKIT_API_SECRET=secret

View File

@ -40,8 +40,16 @@ server.listen(SERVER_PORT, () => {
app.post('/token', (req, res) => {
const roomName = req.body.roomName;
const participantName = req.body.participantName;
if (!roomName || !participantName) {
res.status(400).send('roomName and participantName are required');
return;
}
const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
identity: participantName,
// add metadata to the token, which will be available in the participant's metadata
metadata: JSON.stringify({ livekitUrl: process.env.LIVEKIT_URL }),
});
at.addGrant({ roomJoin: true, room: roomName });
const token = at.toJwt();