-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinbox.js
More file actions
40 lines (32 loc) · 1.16 KB
/
inbox.js
File metadata and controls
40 lines (32 loc) · 1.16 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
const express = require('express');
const { RtcTokenBuilder, RtcRole } = require('agora-token');
const app = express();
const PORT = process.env.PORT || 3000;
// IMPORTANT: Set these in your Render/Vercel Environment Variables
const APP_ID = process.env.APP_ID;
const APP_CERTIFICATE = process.env.APP_CERTIFICATE;
app.get('/rtc/:channelName', (req, res) => {
const channelName = req.params.channelName;
if (!channelName) {
return res.status(400).json({ 'error': 'channel name is required' });
}
// Use 0 for UID to allow any user to join with this token
const uid = 0;
const role = RtcRole.PUBLISHER;
// Token expires in 24 hours (86400 seconds)
const expirationTimeInSeconds = 86400;
const currentTimestamp = Math.floor(Date.now() / 1000);
const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds;
const token = RtcTokenBuilder.buildTokenWithUid(
APP_ID,
APP_CERTIFICATE,
channelName,
uid,
role,
privilegeExpiredTs
);
return res.json({ 'rtcToken': token });
});
app.listen(PORT, () => {
console.log(`Token server running on port ${PORT}`);
});