-
Notifications
You must be signed in to change notification settings - Fork 1
/
daily.js
41 lines (37 loc) · 955 Bytes
/
daily.js
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
const createRoom = async () => {
const expiry = Math.round(Date.now() / 1000) + 60 * 60;
const roomRes = await fetch('/api/rooms', {
method: 'POST',
body: JSON.stringify({
properties: {
enable_prejoin_ui: false,
start_audio_off: true,
exp: expiry,
},
}),
});
const { room } = await roomRes.json();
if (roomRes.status !== 200) {
throw new Error(room.error);
}
return room;
};
const createToken = async ({ isOwner, roomName }) => {
const expiry = Math.round(Date.now() / 1000) + 60 * 60;
const tokenRes = await fetch('/api/tokens', {
method: 'POST',
body: JSON.stringify({
properties: { room_name: roomName, exp: expiry, is_owner: isOwner },
}),
});
const tokenData = await tokenRes.json();
if (tokenRes.status !== 200) {
throw new Error(tokenData.error);
}
return tokenData.token;
};
const api = {
createToken,
createRoom,
};
export default api;