Listen to Call status

In this building block you will see how to listen to a Call's status.

Example

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Listen to Call Status" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Install dependencies

npm install nexmo-stitch

Write the code

Add the following to ListenToCallStatus.js:

Copy to Clipboard
application.on("call:status:changed",(call) => {
    //Handle the new call.status
});

View full source

Run your code

Save this file to your machine and run it:

Load in your browser

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Listen to Call Status" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
val listener = object : CallEventsListener {
    override fun CallEventsListener(event: CallEventsListener.CallStatusEvent) {
        TODO("handle call status changes")
        //event.status //CallStatusEvent.RINGING|CallStatusEvent.ANSWERED|...
    }
}

call.addCallEventListener(listener)

View full source

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Listen to Call Status" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
call.addCallEventListener(new CallEventsListener() {

   //...

   @Override
   public void onCallStatusChanged(@NotNull CallStatusEvent event) { }
        //Handle the new event.getStatus() 
});

View full source

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Listen to Call Status" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
extension ViewController: NXMCallDelegate {

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

View full source

Prerequisites

Create an application

A Nexmo application contains the required configuration for your project. You can create an application using the Nexmo CLI (see below) or via the dashboard. To learn more about applications see our Nexmo concepts guide.

Install the CLI

$ npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Nexmo application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Nexmo needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

$ nexmo app:create "Listen to Call Status" http://demo.ngrok.io/webhooks/answer http://demo.ngrok.io/webhooks/events --keyfile=private.key --type=rtc

Or to use your existing Nexmo application

You will need to use an existing Nexmo application and authenticate a User in order to achieve results here.

See the Conversation API docs for information on how to create an Application and Users on your backend server.

Alternatively you can review the tutorial on getting started with generating an Application and credentials.

Write the code

Add the following to your code:

Copy to Clipboard
@implementation ViewController
...

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

@end

View full source

Try it out

When you run the code you will listen to a Call's status.