-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
67 lines (57 loc) · 1.93 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
import DailyCallContainer from "./js/daily-call-container.js";
import DailyCallWindow from "./js/daily-call-window.js";
import DailyTray from "./js/daily-tray.js";
import DailyLeaveCall from "./js/daily-call-leave.js";
import DailyToggleMic from "./js/daily-toggle-mic.js";
import DailyToggleCamera from "./js/daily-toggle-camera.js";
import DailyToggleScreen from "./js/daily-toggle-screen.js";
export {
DailyCallContainer,
DailyCallWindow,
DailyTray,
DailyLeaveCall,
DailyToggleMic,
DailyToggleCamera,
DailyToggleScreen,
};
async function initiateCall() {
const roomUrl = document.getElementById("roomId").value;
window.callObject = DailyIframe.createCallObject({ url: roomUrl });
buildWebComponents();
await window.callObject.join();
}
function handleJoinError(msg) {
const errorDiv = document.getElementById("error-msg");
errorDiv.innerText = `${msg}`;
document.getElementsByTagName("daily-tray")[0]?.remove();
document.getElementsByTagName("daily-call")[0]?.remove();
document.getElementsByTagName("daily-window")[0]?.remove();
}
function clearErrorMsg() {
const errorDiv = document.getElementById("error-msg");
if (errorDiv.innerText) {
errorDiv.innerText = "";
}
}
function buildWebComponents() {
const container = document.getElementById("daily-call-container");
const call = document.createElement("daily-call");
container.appendChild(call);
call.appendChild(document.createElement("daily-window"));
call.appendChild(document.createElement("daily-tray"));
}
const joinButton = document.getElementById("join");
function hideJoinButton() {
joinButton.disabled = true;
joinButton.style = "display:none;";
}
async function setupCall() {
clearErrorMsg();
initiateCall().then(hideJoinButton).catch(handleJoinError);
}
// Grab the first and only form on the page
const form = document.getElementsByTagName("form")[0];
form.addEventListener("submit", (e) => {
e.preventDefault();
setupCall();
});