online

View as Markdown

online

  • online(options): Promise<Call>

Set the client to be online so it can receive call invites via WebRTC. The call invites can be accepted or rejected as per user input.

Parameters

options
objectRequired

Options object

options.incomingCallHandlers
IncomingCallHandlers

Callback functions for when a call is received. See IncomingCallHandlers.

Example

1// Receive calls using websocket notifications
2client.online({
3 incomingCallHandlers: {
4 all: __incomingCallHandler,
5 },
6});
7
8// Function to handle the incoming call notification and stores the invite
9window.__incomingCallHandler = (notification) => {
10 if (
11 !window.__invite ||
12 window.__invite.details.callID !== notification.invite.details.callID
13 ) {
14 // Store call invite
15 window.__invite = notification.invite;
16 }
17
18 // Trigger UI update here to convey the ringing state
19};
20
21// Function to answer the call
22window.answer = async () => {
23 // Accept the call invite
24 const call = await window.__invite.accept({
25 rootElement: document.getElementById("rootElement"),
26 });
27
28 // Trigger UI update here to convey the connected state
29};
30
31// Function to reject the call
32window.reject = async () => {
33 await window.__invite.reject();
34
35 // Trigger UI update here to convey the ready state
36};