-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
178 lines (159 loc) · 4.44 KB
/
index.js
File metadata and controls
178 lines (159 loc) · 4.44 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
const app = express();
const {
PORT = 3000,
APP_ID = 'dna-jitsi-app',
APP_SECRET,
JITSI_SUB = 'meet.datanusantara.com',
JITSI_DOMAIN = 'meet.datanusantara.com',
DEFAULT_ROOM = 'testingjwtroom'
} = process.env;
if (!APP_SECRET) {
console.warn('WARNING: APP_SECRET belum diset di .env. JWT tidak akan valid.');
}
// parse form x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// Simple HTML form
app.get('/', (req, res) => {
res.send(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Generate Jitsi JWT</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {
font-family: sans-serif;
max-width: 480px;
margin: 40px auto;
padding: 0 16px;
}
h1 {
font-size: 22px;
margin-bottom: 16px;
}
label {
display: block;
margin-bottom: 8px;
}
input[type="text"] {
width: 100%;
padding: 8px;
margin-top: 4px;
box-sizing: border-box;
}
.checkbox-group {
margin: 8px 0;
}
button {
padding: 10px 16px;
margin-top: 12px;
cursor: pointer;
}
.hint {
font-size: 12px;
color: #666;
margin-bottom: 16px;
}
</style>
</head>
<body>
<h1>Generate Jitsi JWT & Join</h1>
<div class="hint">
Domain Jitsi: <strong>${JITSI_DOMAIN}</strong><br/>
Default room: <strong>${DEFAULT_ROOM}</strong>
</div>
<form method="POST" action="/join">
<label>
Nama:
<input type="text" name="name" placeholder="Nama peserta" required />
</label>
<label>
Room (opsional, kalau kosong pakai default):
<input type="text" name="room" placeholder="${DEFAULT_ROOM}" />
</label>
<div class="checkbox-group">
<label>
<input type="checkbox" name="moderator" />
Moderator
</label>
<label>
<input type="checkbox" name="recording" />
Recording allowed
</label>
<label>
<input type="checkbox" name="livestreaming" />
Livestreaming allowed
</label>
<label>
<input type="checkbox" name="bypass_lobby" />
Bypass Lobby
</label>
</div>
<button type="submit">Generate Token & Join</button>
</form>
</body>
</html>`);
});
// Handle submit → generate token → redirect ke Jitsi
app.post('/join', (req, res) => {
try {
if (!APP_SECRET) {
return res
.status(500)
.send('APP_SECRET belum diset. Set di file .env lalu restart aplikasi.');
}
const name = (req.body.name || '').trim() || 'Guest';
const room = (req.body.room || '').trim() || DEFAULT_ROOM;
const isModerator = req.body.moderator === 'on';
const recording = req.body.recording === 'on';
const livestreaming = req.body.livestreaming === 'on';
const bypass_lobby = req.body.bypass_lobby === 'on';
const now = Math.floor(Date.now() / 1000);
const payload = {
aud: 'jitsi',
iss: APP_ID,
sub: JITSI_SUB,
room: room,
exp: now + 60 * 60, // token valid 1 jam
// moderator: isModerator, // dipake kalo module token_moderation aktif
context: {
user: {
name: name,
affiliation: isModerator ? "owner" : "member",
lobby_bypass: bypass_lobby || isModerator,
// bisa tambahkan email, avatar, dsb kalau mau
},
room: {
lobby_autostart: true
},
features: {
recording: recording,
livestreaming: livestreaming,
'screen-sharing': true // contoh selalu diizinkan
}
}
};
const token = jwt.sign(payload, APP_SECRET, { algorithm: 'HS256' });
const meetUrl = `https://${JITSI_DOMAIN}/${encodeURIComponent(
room
)}?jwt=${encodeURIComponent(token)}`;
console.log(
`[JWT] name=${name}, room=${room}, moderator=${isModerator}, rec=${recording}, live=${livestreaming}`
);
console.log(`[JWT] Redirect to: ${meetUrl}`);
// langsung redirect ke room Jitsi dengan token
return res.redirect(meetUrl);
} catch (err) {
console.error('Error generating token:', err);
return res
.status(500)
.send('Terjadi error saat generate token. Cek log server.');
}
});
app.listen(PORT, () => {
console.log(`Jitsi token app running on http://localhost:${PORT}`);
});