-
Notifications
You must be signed in to change notification settings - Fork 29
/
api.js
39 lines (34 loc) · 1019 Bytes
/
api.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
/*
We'll add a 30-min expiry (exp) so rooms won't linger too long on your account.
See other available options at https://docs.daily.co/reference#create-room
*/
async function createRoom() {
const exp = Math.round(Date.now() / 1000) + 60 * 30;
const options = {
properties: {
exp,
},
};
const isLocal =
process.env.REACT_APP_ROOM_ENDPOINT && process.env.REACT_APP_ROOM_ENDPOINT === 'local';
const endpoint = isLocal
? 'https://api.daily.co/v1/rooms/'
: `${window.location.origin}/api/rooms`;
/*
No need to send the headers with the request when using the proxy option:
netlify.toml takes care of that for us.
*/
const headers = isLocal && {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.REACT_APP_DAILY_API_KEY}`,
},
};
const response = await fetch(endpoint, {
method: 'POST',
body: JSON.stringify(options),
...headers,
});
return response.json();
}
export default { createRoom };