Receive a Call

This guide covers how to receive a call with the Vonage Client SDK. Before you begin, make sure you added the SDK to your app and (Android, iOS, JS).

NOTE: On iOS it is expected that you use CallKit for incoming and outgoing calls. Please follow the push notification guide.

Receive a Call Invite

In order to receive an incoming in-app call, you should listen for incoming call invites:

To receive an incoming in-app call, listen for the callInvite event:

// After creating a session
client.on("callInvite", (callId, from, channelType) => {
  // Answer / Reject Call
  console.log( { callId, from, channelType } );
});

Then, you’ll be able to answer or reject the invite.

Answer

// After creating a session
client.answer(callId)
    .then(() => {
        console.log("Success answering call.");
    })
    .catch(error => {
        console.error("Error answering call: ", error);
    });

Reject

// After creating a session
client.reject(callId)
    .then(() => {
        console.log("Success rejecting call.");
    })
    .catch(error => {
        console.error("Error rejecting call: ", error);
    });

Hang Up

For an on-going call:

// After creating a session
client.hangup(callId)
    .then(() => {
        console.log("Success hanging up call.");
    })
    .catch(error => {
        console.error("Error hanging up call: ", error);
    });

Listen For Call Events

To see updates on the state of a call, for example, to know if the other member answered or hung up the call, you should listen to leg status events.

To see updates on the state of the call and its members:

// After creating a session
client.on("legStatusUpdate", (callId, legId, status) => {
    console.log({callId, legId, status});
});

Reference