Transitioning to the Vonage Client SDK

If you are familiar with or using the Nexmo Client SDK in your application there are some changes to consider when moving to the Vonage Client SDK.

Client Instantiation

For Android and iOS the SDK Client is no longer a singleton.

// Nexmo SDK
let client = new NexmoClient()

// Vonage SDK

// If loaded with a <script> tag:
const client = new vonageClientSDK.VonageClient();

// If loaded via import:
const client = new VonageClient();

Session Management

Previously, in the Nexmo Client SDK on Android and iOS you would call login/createSession and receive updates about creating your initial session via a listener.

In the JavaScript Vonage Client SDK you will no longer receive an app object, you will instead get a session ID.

The Vonage Client SDK has a callback to allow you to know if the initial session creation was successful or not. Further session updates, including reconnecting, are available on listeners/delegate methods.

// Nexmo SDK
client.createSession(token)
  .then(app => {
    ...
  })
  .catch(error => {
    ...
  });

// Vonage SDK
client.createSession(token)
  .then(sessionId => {
    ...
  })
  .catch(error => {
    ...
  });

Calls

In the Vonage Client SDK, server calls are the only type of calls you are able to make, the previous inApp call type has been deprecated. This means an NCCO webhook server is now mandatory for all call flows.

The parameters for making a server call have changed, the previous to and context field are now one parameter. For backwards compatibility with existing NCCO webhooks, you can specify to as apart of the context object, which will be forwarded to your webhook as before.

Otherwise, utilise the context param to send custom data to your answer_url webhook.

// Nexmo SDK
application.callServer("PHONE_NUMBER")
    .then(nxmCall => {
        ...
    })
    .catch(error => {
        ...
    });

// Vonage SDK
client.serverCall({ to: "PHONE_NUMBER" })
    .then(callId => {
        ...
    })
    .catch(error => {
        ...
    });

Call/Chat Actions

The Vonage Client SDK also no longer has methods on objects for performing action such and ending a call, muting a call, or sending a message. All these actions are available as method on the client. To perform these actions, you will need to store the call or conversation ID you would like to perform an action on.

For example to mute a call:

// Nexmo SDK
conversation.me.mute(true);

// Vonage SDK
client.mute(callId)
    .then(() => {
        // Mute successful
    })
    .catch(error => {
        // Handle muting error
    });

Or to sent a message:

// Nexmo SDK
conversation.sendMessage({
    "message_type": "text",
    "text": "Hello world!"
}).then((event) => {
    ...
}).catch((error)=>{
    ...
});


// Vonage SDK
client.sendMessageTextEvent("CONV_ID", "Hello world!")
    .then(timestamp => {
        ...
    }).catch(error => {
        ...
    });