-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (45 loc) · 1.61 KB
/
index.js
File metadata and controls
58 lines (45 loc) · 1.61 KB
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
48
49
50
51
52
53
54
55
56
57
58
const { v4: uuidv4 } = require('uuid');
require('dotenv').config()
const express = require("express");
const https = require("https");
const path = require('path');
const app = express();
const port = 5050;
const {RtcTokenBuilder, RtcRole} = require('agora-access-token')
app.use(express.static(path.join(__dirname + '/public')));
app.use(express.urlencoded({extended:true}));
app.get("/", function(req, res) {
res.sendFile(__dirname + "/public/html/home.html");
});
app.get("/404", function(req, res) {
res.sendFile(__dirname + "/public/html/404.html");
});
app.get("/call/:channel", function(req, res) {
res.sendFile(__dirname + "/public/html/call.html");
});
app.get("/sign", function(req, res) {
res.sendFile(__dirname + "/public/html/sign.html");
});
app.post("/getToken", function(req, res) {
var channel = req.body.channel
const appID = process.env.APP_ID;
const appCertificate = process.env.APP_CERTIF
const channelName = channel;
const uid = 0;
const role = RtcRole.PUBLISHER;
const expirationTimeInSeconds = 7200
const currentTimestamp = Math.floor(Date.now() / 1000)
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds
const token = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs);
res.json({token: token, appID: process.env.APP_ID})
});
app.get("/create", function(req, res) {
var uuid = uuidv4();
res.redirect(`/call/${uuid}`)
});
app.use(function(req, res, next) {
res.redirect('/404');
});
app.listen(process.env.PORT || port, function() {
console.log(`Server started on http://localhost:${port}`);
});