-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
122 lines (109 loc) · 2.69 KB
/
index.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
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
let callFrame;
const backgroundPrefix = "backgrounds";
const backgroundsData = [
{
path: "cafe-table-with-coffee.jpg",
alt: "A round coffee table with a cup of coffee",
},
{
path: "northern-lights.jpg",
alt: "Northern lights",
},
{
path: "outdoor-cafe-with-cat.jpg",
alt: "An outdoor cafe with a cat",
},
{
path: "rocky-forest.jpg",
alt: "A rocky forest",
},
{
path: "snowy-mountains.jpg",
alt: "Snowy mountains",
},
{
path: "sunny-beach.jpg",
alt: "A sunny beach",
},
{
path: "warm-restaurant.jpg",
alt: "A warm restaurant",
},
];
window.addEventListener("DOMContentLoaded", () => {
initCall();
initBackgrounds();
});
function initBackgrounds() {
const resetBtn = document.getElementById("reset");
resetBtn.onclick = () => {
resetBackground();
};
loadBackgrounds();
}
function initCall() {
const container = document.getElementById("call");
callFrame = DailyIframe.createFrame(container, {
showLeaveButton: true,
iframeStyle: {
position: "fixed",
width: "500px",
height: "550px",
border: "1px solid #e6eaef",
borderRadius: "6px",
boxShadow: `0 1px 2px rgba(0, 0, 0, 0.02), 0 2px 4px rgba(0, 0, 0, 0.02),
0 4px 8px rgba(0, 0, 0, 0.02), 0 8px 16px rgba(0, 0, 0, 0.02),
0 16px 32px rgba(0, 0, 0, 0.02)`,
},
})
.on("nonfatal-error", (e) => {
console.warn("nonfatal error:", e);
})
.on("started-camera", () => {
const backgrounds = document.getElementById("backgrounds");
backgrounds.classList.remove("hidden");
})
.on("left-meeting", () => {
initCall();
});
// TODO: Replace the following URL with your own room URL.
callFrame.join({ url: "https://<your-domain>.daily.co/<room-name>" });
}
function setBackground(imgPath) {
callFrame.updateInputSettings({
video: {
processor: {
type: "background-image",
config: {
source: imgPath,
},
},
},
});
}
function resetBackground() {
callFrame.updateInputSettings({
video: {
processor: {
type: "none",
},
},
});
}
async function loadBackgrounds() {
const bgImages = document.getElementById("bgImages");
for (let i = 0; i < backgroundsData.length; i++) {
const data = backgroundsData[i];
const btn = document.createElement("button");
btn.className = "bg";
const imgPath = `${window.location.protocol}//${window.location.host}/${backgroundPrefix}/${data.path}`;
const img = document.createElement("img");
img.src = imgPath;
img.alt = data.alt;
btn.onclick = () => {
setBackground(imgPath);
};
btn.appendChild(img);
bgImages.appendChild(btn);
}
}