-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
346 lines (299 loc) · 10.7 KB
/
index.html
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Background Transformer UI sample | Dyte UI Kit</title>
<!--
For the UI Kit and Web Core script tags,
make sure to use the latest versions in the URL when you're using this
-->
<!-- Import helper to load UI Kit components -->
<script type="module">
import { defineCustomElements } from 'https://cdn.jsdelivr.net/npm/@dytesdk/ui-kit@latest/loader/index.es2017.js';
defineCustomElements();
</script>
<!-- Import Web Core 2.x via CDN -->
<script src="https://cdn.dyte.in/core/dyte2.js"></script>
<!-- Video Background Transformer -->
<script src="https://cdn.jsdelivr.net/npm/@dytesdk/video-background-transformer@latest/dist/index.iife.js"></script>
<style>
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
html,
body {
-webkit-overflow-scrolling: touch !important;
height: 100% !important;
padding: 0;
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
#app {
font-family: var(--dyte-font-family);
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
color: var(--color-text);
--color-background: rgb(var(--dyte-colors-background-1000, 8 8 8));
--color-text: rgb(var(--dyte-colors-text-1000, 255 255 255));
--color-border: rgb(var(--dyte-colors-background-800, 24 24 24));
}
header {
display: flex;
align-items: center;
justify-content: end;
gap: 4px;
padding: 0.5rem 1rem;
background-color: var(--color-background);
color: var(--color-text);
border-bottom: 1px solid var(--color-border);
}
button {
display: inline-flex;
align-items: center;
justify-content: center;
background-color: transparent;
border: none;
color: inherit;
cursor: pointer;
}
header > button {
padding: 4px 12px;
border-radius: 4px;
border: 1px solid var(--color-border);
}
header > button:hover {
background-color: var(--color-border);
}
header > button > svg {
width: 1.5rem;
height: 1.5rem;
}
.icon-btn {
background-color: var(--color-border);
}
.icon-btn svg {
width: 64px;
height: 64px;
}
#main {
display: flex;
width: 100%;
height: 100%;
}
#sidebar {
display: none;
flex-direction: column;
align-items: center;
padding: 1rem;
width: 100%;
max-width: 320px;
background-color: var(--color-background);
color: var(--color-text);
border-left: 1px solid var(--color-border);
}
#sidebar.active {
display: flex;
}
#container {
flex: 1 0 0;
max-width: 320px;
display: flex;
flex-direction: column;
overflow-y: auto;
}
#backgrounds {
flex-grow: 1;
display: flex;
flex-direction: column;
gap: 12px;
}
h3 {
font-weight: 500;
margin: 0;
font-size: 18px;
padding: 0.5rem 0;
margin-bottom: 12px;
}
.bg-btn {
width: 100%;
padding: 0;
aspect-ratio: 16/9;
}
.bg-btn img {
width: 100%;
height: 100%;
object-fit: cover;
}
dyte-meeting {
flex-grow: 1;
height: auto;
}
@media screen and (max-width: 768px) {
#main {
flex-direction: column;
}
#sidebar {
flex-grow: 3;
max-width: 100%;
flex-shrink: 0;
border-left: none;
border-top: 1px solid var(--color-border);
}
}
</style>
</head>
<body>
<div id="app">
<header>
<button onclick="toggleBackgroundSidebar()">
<svg
fill="none"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M6 16.938v2.121L5.059 20h-2.12L6 16.938Zm16.002-2.503v2.122L18.56 20h-.566v-1.557l4.008-4.008ZM8.75 14h6.495a1.75 1.75 0 0 1 1.744 1.607l.006.143V20h-1.5v-4.25a.25.25 0 0 0-.193-.243l-.057-.007H8.75a.25.25 0 0 0-.243.193l-.007.057V20H7v-4.25a1.75 1.75 0 0 1 1.606-1.744L8.75 14Zm-.729-3.584c.06.579.243 1.12.523 1.6L2 18.56v-2.122l6.021-6.022Zm13.98-.484v2.123l-4.007 4.01v-.315l-.004-.168a2.734 2.734 0 0 0-.387-1.247l4.399-4.403ZM12.058 4 2 14.06v-2.121L9.936 4h2.12Zm9.945 1.432v2.123l-5.667 5.67a2.731 2.731 0 0 0-.86-.216l-.23-.009h-.6a4.02 4.02 0 0 0 .855-1.062l6.502-6.506ZM12 7a3 3 0 1 1 0 6 3 3 0 0 1 0-6Zm0 1.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3ZM7.559 4l-5.56 5.56V7.438L5.439 4h2.12Zm13.498 0-5.148 5.149a3.98 3.98 0 0 0-.652-1.47L18.935 4h2.122Zm-4.498 0-2.544 2.544a3.974 3.974 0 0 0-1.6-.522L14.438 4h2.122Z"
fill="currentColor"
/>
</svg>
</button>
</header>
<div id="main">
<dyte-meeting
id="my-meeting"
mode="fill"
show-setup-screen="true"
></dyte-meeting>
<div id="sidebar">
<div id="container">
<h3>Backgrounds</h3>
<div id="backgrounds">
<button
class="bg-btn icon-btn"
onclick="onVideoBackgroundChange('none')"
>
<svg
fill="none"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M2.22 2.22a.75.75 0 0 1 1.06 0l18.5 18.5a.75.75 0 0 1-1.06 1.06l-1.776-1.775H4.25A2.25 2.25 0 0 1 2 17.755V6.25a2.25 2.25 0 0 1 1.2-1.99l-.98-.98a.75.75 0 0 1 0-1.06Zm13.274 14.335L14.44 15.5H8.75a.25.25 0 0 0-.243.193l-.007.057-.001 2.754h6.995v-1.949ZM11.94 13a3 3 0 0 1-2.938-2.939L4.439 5.5H4.25a.75.75 0 0 0-.75.75v11.505c0 .414.336.75.75.75l2.749-.001L7 15.75a1.75 1.75 0 0 1 1.606-1.744L8.75 14h4.19l-1.001-1ZM11.71 8.528l-1.157-1.156a3 3 0 0 1 4.075 4.075l-1.156-1.157a1.503 1.503 0 0 0-1.762-1.762Z"
fill="currentColor"
/>
<path
d="M20.495 17.314V6.25a.75.75 0 0 0-.75-.75H8.682L7.182 4h12.563a2.25 2.25 0 0 1 2.25 2.25v11.505c0 .312-.063.61-.178.88l-1.322-1.321Z"
fill="currentColor"
/>
</svg>
</button>
<button
class="bg-btn icon-btn"
onclick="onVideoBackgroundChange('blur')"
>
<svg
fill="none"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M3 12a9 9 0 0 1 13.977-7.5H12a7.5 7.5 0 1 0 0 15V18h6.708A9 9 0 0 1 3 12Z"
fill="currentColor"
/>
<path
d="M18.225 5.5H12V7h7.485a9.05 9.05 0 0 0-1.26-1.5ZM12 8h8.064c.238.477.434.979.584 1.5H12V8ZM20.876 10.5H12V12h9c0-.511-.043-1.012-.124-1.5ZM12 13h8.945a8.963 8.963 0 0 1-.297 1.5H12V13ZM20.294 15.5H12V17h7.485a8.98 8.98 0 0 0 .81-1.5Z"
fill="currentColor"
/>
</svg>
</button>
</div>
</div>
</div>
</div>
</div>
<script>
function toggleBackgroundSidebar() {
sidebar.classList.toggle('active');
}
function loadBackgroundChangerUI() {
const backgroundImages = [
'https://assets.dyte.io/backgrounds/bg-dyte-office.jpg',
'https://assets.dyte.io/backgrounds/bg_0.jpg',
'https://assets.dyte.io/backgrounds/bg_1.jpg',
'https://assets.dyte.io/backgrounds/bg_2.jpg',
'https://assets.dyte.io/backgrounds/bg_3.jpg',
'https://assets.dyte.io/backgrounds/bg_4.jpg',
'https://assets.dyte.io/backgrounds/bg_5.jpg',
'https://assets.dyte.io/backgrounds/bg_6.jpg',
'https://assets.dyte.io/backgrounds/bg_7.jpg',
];
for (const image of backgroundImages) {
const btn = document.createElement('button');
btn.className = 'bg-btn';
btn.onclick = () => {
window.onVideoBackgroundChange('image', image);
};
const img = document.createElement('img');
img.src = image;
btn.append(img);
backgrounds.append(btn);
}
}
async function initMeeting() {
const searchParams = new URL(window.location.href).searchParams;
const authToken = searchParams.get('authToken');
if (!authToken) {
alert(
"An authToken wasn't passed, please pass an authToken in the URL query to join a meeting."
);
}
const meeting = await DyteClient.init({
authToken,
});
document.getElementById('my-meeting').meeting = meeting;
/**
* To customise DyteVideoBackgroundTransformer configs, please refer to https://www.npmjs.com/package/@dytesdk/video-background-transformer?activeTab=readme.
*/
const dyteVideoBackgroundTransformer =
await DyteVideoBackgroundTransformer.init({
meeting,
segmentationConfig: {
pipeline: 'canvas2dCpu', // 'webgl2' | 'canvas2dCpu'
}
});
let activeMiddleware;
async function onVideoBackgroundChange(type, url) {
if (activeMiddleware) {
// remove the last selected active middleware
await meeting.self.removeVideoMiddleware(activeMiddleware);
}
if (type === 'image') {
// set the selected image as background
activeMiddleware =
await dyteVideoBackgroundTransformer.createStaticBackgroundVideoMiddleware(
url
);
await meeting.self.addVideoMiddleware(activeMiddleware);
} else if (type === 'blur') {
// set background blur
activeMiddleware =
await dyteVideoBackgroundTransformer.createBackgroundBlurVideoMiddleware(
4
);
await meeting.self.addVideoMiddleware(activeMiddleware);
}
}
window.onVideoBackgroundChange = onVideoBackgroundChange;
}
window.onload = function () {
loadBackgroundChangerUI();
initMeeting();
};
</script>
</body>
</html>