Start and Receive Calls

Overview

NOTE: A step-by-step tutorial to making a phone call from a web application is also available here. A step-by-step tutorial on receiving a phone call in your web application is also available here.

This guide covers the functionalities in your Nexmo Client application, in order to make and receive in-app voice calls.

Before you begin, make sure you added the SDK to your app.

Start a call

This method allows you to conduct in-app calls as well as phone calls while taking advantage of the rich Nexmo Voice API features.

When your client app calls this method, the answer_url webhook that is configured for your Nexmo Application will execute. That defines the logic and capabilities of the call.

On the client side, start the call as such:

new NexmoClient()
    .login(USER_JWT)
    .then(application => {
        ...
        application.callPhone();
    })

Receive incoming call events

To receive an incoming in-app call, you should listen to incoming call events:

...
application.on("member:call", (member, call) => {
    ...

The listener method receives a member object that contains information about the caller and a call object, that lets you interact with the call in progress. With the later, you’ll be able to perform methods such as answer, reject and hang up.

Answer

call.answer();

Reject

call.reject();

Hang Up

call.hangUp();

Listen For Call Status Events

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

application.on("call:status:changed",(call) => {
    ...
});

Overview

This guide covers the functionalities in your Nexmo Client application, in order to make and receive in-app voice calls.

Before you begin, make sure you added the SDK to your app.

Start a call

Start an In-App Call

The quickest way to start an in-app call is by conducting an in-app to in-app call, meaning between two users.

val callee = listOf(...)
var callListener = object: NexmoRequestListener<NexmoCall> {...}

NexmoClient.get().call(callees, NexmoCallHandler.IN_APP, callListener);

List<String> callee = ...;
NexmoRequestListener<NexmoCall> callListener = ...;

NexmoClient.get().call(callee, NexmoCallHandler.IN_APP, callListener);

The possible voice capabilities are very limited, as this doesn’t utilize Nexmo Voice API. This method is recommended mostly for onboarding. Later, it is recommended to use a server managed call.

Start a Server Managed Call

This method allows you to conduct in-app calls as well as phone calls while taking advantage of the rich Nexmo Voice API features.

When your client app calls this method, the answer_url webhook that is configured for your Nexmo Application will execute. That defines the logic and capabilities of the call.

On the client side, start the call as such:

val callee = "..."
var callListener = object: NexmoRequestListener<NexmoCall> {...}

NexmoClient.get().call(callee, NexmoCallHandler.SERVER, callListener);

String callee = ...;
NexmoRequestListener<NexmoCall> callListener = ...;

NexmoClient.get().call(callee, NexmoCallHandler.SERVER, callListener);

Receive incoming call

In order to receive an incoming in-app call, you should register and listen to incoming call events:

val incomingCallListener = NexmoIncomingCallListener { call ->
    currentCall = call
    startActivity(Intent(this@MainActivity, IncomingCallActivity::class.java))
}

NexmoClient.get().addIncomingCallListener(incomingCallListener)

Remove the listener when needed:

NexmoClient.get().removeIncomingCallListeners()


NexmoIncomingCallListener incomingCallListener = new NexmoIncomingCallListener() {
    @Override
    public void onIncomingCall(NexmoCall call) {
        ...
    }
};

nexmoCall.addIncomingCallListener(incomingCallListener);

Remove the listener when needed:

nexmoCall.removeIncomingCallListener(incomingCallListener);

Then, you’ll be able to perform methods such as answer and hang up.

Answer

nexmoCall?.answer(object : NexmoRequestListener<NexmoCall> {...})

nexmoCall.answer(new NexmoRequestListener<NexmoCall>(){...})

Hang Up

nexmoCall?.hangup(object : NexmoRequestListener<NexmoCall> {...})

nexmoCall.hangup(new NexmoRequestListener<NexmoCall>(){...})

Listen For Call Events

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

var callEventListener = NexmoCallEventListener(...)

nexmoCall?.addCallEventListener(callEventListener)

Remove the listener when needed:

nexmoCall?.removeCallEventListener(callEventListener)

NexmoCallEventListener callEventListener = ... ;

nexmoCall.addCallEventListener(callEventListener);

Remove the listener when needed:

nexmoCall.removeCallEventListener(callEventListener);

Overview

This guide covers the functionalities in your Nexmo Client application, in order to make and receive in-app voice calls.

Before you begin, make sure you added the SDK to your app.

Start a call

Start an In-App Call

The quickest way to start an in-app call is by conducting an in-app to in-app call, meaning between two users.

// delegate must conform to NXMCallDelegate
client?.call(["userId"], callHandler: .inApp, delegate: delegate) { (error, call) in
    guard let call = call else {
        // Handle create call failure
        return
    }
    // Handle call created successfully. 
    // methods on the `delegate` will be invoked with needed updates
})

// delegate must conform to NXMCallDelegate
[client call:@[@"userId"] callHandler:NXMCallHandlerInApp delegate:delegate 
  completion:^(NSError * _Nullable error, NXMCall * _Nullable call) {
    if (!call) {
        // Handle create call failure
        return
    }
    // Handle call created successfully. 
    // methods on the `delegate` will be invoked with needed updates
}];

The possible voice capabilities are very limited, as this doesn’t utilize Nexmo Voice API. This method is recommended mostly for onboarding. Later, it is recommended to use a server managed call.

Start a Server Managed Call

This method allows you to conduct in-app calls as well as phone calls while taking advantage of the rich Nexmo Voice API features.

When your client app calls this method, the answer_url webhook that is configured for your Nexmo Application will execute. That defines the logic and capabilities of the call.

On the client side, start the call as such:

// delegate must conform to NXMCallDelegate
client?.call(["userId"], callHandler: .server, delegate: delegate) { (error, call) in
    guard let call = call else {
        // Handle create call failure
        return
    }
    // Handle call created successfully. 
    // methods on the `delegate` will be invoked with needed updates
})

// delegate must conform to NXMCallDelegate
[client call:@[@"userId"] callHandler:NXMCallHandlerServer delegate:delegate 
  completion:^(NSError * _Nullable error, NXMCall * _Nullable call) {
    if (!call) {
        // Handle create call failure
        return;
    }
    // Handle call created successfully. 
    // methods on the `delegate` will be invoked with needed updates
}];

Receive incoming call

In order to receive an incoming in-app call, you should register and listen to incoming call events:

extension ViewController: NXMClientDelegate {

    // ...

    func incomingCall(_ call: NXMCall) {
        // handle an incoming call
        ...
    }

}

@implementation ViewController
...

// implement NXMClientDelegate
// ...

- (void)incomingCall:(nonnull NXMCall *)call {
    // handle an incoming call
}

@end

Then, you’ll be able to perform methods such as answer, reject and hang up.

Answer

// delegate must conform to NXMCallDelegate
call.answer(delegate) { error in
    if let error = error {
        // Handle answer call failure
    } else {
        // Handle answer call success
    }
}

// delegate must conform to NXMCallDelegate
[call answer:delegate completionHandler:^(NSError * _Nullable error) {
    if (error) {
        // Handle answer call failure
    } else {
        // Handle answer call success
    }
}];

Reject

call.reject { error in
    if let error = error {
        // Handle reject call failure
    } else {
        // Handle reject call success
    }
}

[myCall reject:^(NSError * _Nullable error) {
    if (error) {
        // Handle reject failure
    } else {
        // Handle reject success
    }
}];

Hang Up

call.myCallMember.hangup()

[myCall.myCallMember hangup];

Listen For Call Events

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

extension ViewController: NXMCallDelegate {

    func statusChanged(_ member: NXMCallMember!) {
        // Handle the new call status for member
    }
}

@implementation ViewController
...

// implement NXMCallDelegate
- (void)statusChanged:(NXMCallMember *)callMember {
    // Handle the new call status for member
}

@end