Improved basic-node endpoint and refactored code
This commit is contained in:
parent
17fa0b7462
commit
e334902dc7
@ -1,3 +1,3 @@
|
||||
SERVER_PORT=5000
|
||||
OPENVIDU_URL=http://localhost:4443/
|
||||
OPENVIDU_SECRET=MY_SECRET
|
||||
LIVEKIT_API_KEY=devkey
|
||||
LIVEKIT_API_SECRET=secret
|
||||
@ -1,9 +1,11 @@
|
||||
require("dotenv").config(!!process.env.CONFIG ? { path: process.env.CONFIG } : {});
|
||||
var express = require("express");
|
||||
var bodyParser = require("body-parser");
|
||||
var http = require("http");
|
||||
require('dotenv').config(
|
||||
!!process.env.CONFIG ? { path: process.env.CONFIG } : {}
|
||||
);
|
||||
var express = require('express');
|
||||
var bodyParser = require('body-parser');
|
||||
var http = require('http');
|
||||
var AccessToken = require('livekit-server-sdk').AccessToken;
|
||||
var cors = require("cors");
|
||||
var cors = require('cors');
|
||||
var app = express();
|
||||
|
||||
// Environment variable: PORT where the node server is listening
|
||||
@ -15,9 +17,9 @@ var LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET || 'secret';
|
||||
|
||||
// Enable CORS support
|
||||
app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
})
|
||||
cors({
|
||||
origin: '*',
|
||||
})
|
||||
);
|
||||
|
||||
var server = http.createServer(app);
|
||||
@ -32,16 +34,18 @@ app.use(express.static(__dirname + '/public'));
|
||||
|
||||
// Serve application
|
||||
server.listen(SERVER_PORT, () => {
|
||||
console.log("Application started on port: ", SERVER_PORT);
|
||||
console.log('Application started on port: ', SERVER_PORT);
|
||||
});
|
||||
|
||||
app.post('/getToken', (req, res) => {
|
||||
const roomName = req.body.roomName;
|
||||
const participantName = req.body.participantName;
|
||||
const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, { identity: participantName });
|
||||
at.addGrant({ roomJoin: true, room: roomName });
|
||||
const token = at.toJwt();
|
||||
res.send(token);
|
||||
app.post('/token', (req, res) => {
|
||||
const roomName = req.body.roomName;
|
||||
const participantName = req.body.participantName;
|
||||
const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
|
||||
identity: participantName,
|
||||
});
|
||||
at.addGrant({ roomJoin: true, room: roomName });
|
||||
const token = at.toJwt();
|
||||
res.send(token);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', err => console.error(err));
|
||||
process.on('uncaughtException', (err) => console.error(err));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user