Hangup a Call

In this building block you will see how to hang up a Call.

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 "Hangup Call" 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 HangupCall.js:

Copy to Clipboard
call.hangUp();

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 "Hangup Call" 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 : NexmoRequestListener<NexmoCall> {

    override fun onError(nexmoApiError: NexmoApiError) {
        TODO("Handle error")
    }

    override fun onSuccess(nexmoCall: NexmoCall) {
        TODO("Handle success")
    }
}

call.hangup(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 "Hangup Call" 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
NexmoRequestListener<NexmoCall> listener = new NexmoRequestListener<>() {
        @Override
        public void onError(NexmoApiError nexmoApiError) {
            //Handle error
        }

        @Override
        public void onSuccess(NexmoCall call) {
            //Handle success
        }
};

call.hangup(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 "Hangup Call" 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.myCallMember.hangup()

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 "Hangup Call" 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
[myCall.myCallMember hangup];

View full source

Try it out

When you run the code you hang up the Call.