// Receive calls using websocket notifications
client.online({
incomingCallHandlers: {
all: __incomingCallHandler,
},
});
// Function to handle the incoming call notification and stores the invite
window.__incomingCallHandler = (notification) => {
if (
!window.__invite ||
window.__invite.details.callID !== notification.invite.details.callID
) {
// Store call invite
window.__invite = notification.invite;
}
// Trigger UI update here to convey the ringing state
};
// Function to answer the call
window.answer = async () => {
// Accept the call invite
const call = await window.__invite.accept({
rootElement: document.getElementById("rootElement"),
});
// Trigger UI update here to convey the connected state
};
// Function to reject the call
window.reject = async () => {
await window.__invite.reject();
// Trigger UI update here to convey the ready state
};