Class: NexmoClient

NexmoClient


new NexmoClient(params)

The parent NexmoClient class.

Parameters:
Name Type Description
params object

the settings to initialise the SDK

Properties
Name Type Argument Default Description
debug string 'silent'

set mode to 'debug', 'info', 'warn', or 'error' for customized logging levels in the console

url string 'nexmo_ws_url'

Nexmo Conversation Websocket url, default is wss://ws.nexmo.com (wss://ws-us-1.nexmo.com for WDC, wss://ws-us-2.nexmo.com for DAL, wss://ws-eu-1.nexmo.com for LON, wss://ws-sg-1.nexmo.com for SNG)

nexmo_api_url string Nexmo

Conversation Api url, default is https://api.nexmo.com (https://api-us-1.nexmo.com for WDC, https://api-us-2.nexmo.com for DAL, https://api-eu-1.nexmo.com for LON, https://api-sg-1.nexmo.com for SNG)

ips_url string 'ips_url'

Nexmo IPS url for image upload, default is https://api.nexmo.com/v1/image (https://api-us-1.nexmo.com/v1/image for WDC, https://api-us-2.nexmo.com/v1/image for DAL, https://api-eu-1.nexmo.com/v1/image for LON, https://api-sg-1.nexmo.com/v1/image for SNG)

path string '/v2/rtc'

Nexmo Conversation Websocket url path suffix

rtcstats RTCStatsConfig

set reporting for stream statistics (Internal event emit)

Properties
Name Type Default Description
emit_events Boolean false

receive rtcstats:report event (deprecated)

emit_rtc_analytics Boolean false

receive rtcstats:analytics event

emit_interval number 1000

interval in ms for rtcstats:report and rtcstats:analytics

remote_collection Boolean true

collect client logs internally

remote_collection_url Boolean 'gollum_url'

url for collecting client logs internally

remote_collection_interval number 5000

interval in ms to collect client logs internally

socket_io object

configure socket.io

Properties
Name Type Default Description
forceNew Boolean true

configure socket.io forceNew attribute

autoConnect Boolean true

socket.io autoConnect attribute

reconnection Boolean true

socket.io reconnection attribute

reconnectionAttempts number 5

socket.io reconnectionAttempts attribute

transports Array.<string> 'websocket'

socket.io transports protocols

sync string 'none'

{'none' || 'lite' || 'full'} after a successful session creation, synchronise conversations, include events or nothing

environment string 'production'

development / production environment

iceServers Array.<object> <optional>
[]

configure iceServers for RTCPeerConnection

log_reporter object

configure log reports for bugsnag tool

Properties
Name Type Default Description
enabled Boolean true
bugsnag_key string

your bugsnag api key / defaults to Nexmo api key

conversations_page_config object

configure paginated requests for conversations

Properties
Name Type Default Description
page_size number 10

the number of resources returned in a single request list

order string asc

'asc' or 'desc' ordering of resources (usually based on creation time)

cursor string

cursor parameter to access the next or previous page of a data set

events_page_config object

configure paginated requests for events

Properties
Name Type Default Description
page_size number 10

the number of resources returned in a single request list

order string asc

'asc' or 'desc' ordering of resources (usually based on creation time)

event_type string

the type of event used to filter event requests. Supports wildcard options with :* eg. 'members:*'

enableEventsQueue Boolean true

mechanism to guarantee order of events received during a session

enableInboundOffer Boolean false

configure receiving offer for faster inbound call setup

acknowledgeEvents Boolean true

send acknowledgment over websocket to server for received events

token string

the jwt token for network requests

Source:
Fires:

Members


<static, readonly> DISCONNECT_REASON :string

Enum for NexmoClient disconnection reason.

Type:
  • string
Properties:
Name Type Default Description
ClientDisconnected string ClientDisconnected
TokenExpired string TokenExpired
ConnectionError string ConnectionError
Source:

Methods


<async> checkMediaConnectivity(ip, port)

Return the connection health of a single media server including possible connectionTime in ms.

Parameters:
Name Type Description
ip string

ip address of the Media Server

port string

port number of the Media Server

Source:
Returns:
Type
Promise.<MediaConnectionReport>
Example

Return the connection health of a single media server

 rtc.checkMediaConnectivity('ip-address','1').then((response) => {
   console.log(`IP Address of media server: ${response.ip}`);
   console.log(`Able to connect: ${response.canConnect}`);
   console.log(`ConnectionTime in ms: ${resonse.connectionTime}`);
 }).catch((error) => {
   console.log(error);
 });

<async> checkMediaServers(token, nexmo_api_url, datacenter)

Return a list with the connection health of the media servers for a specific datacenter.

Parameters:
Name Type Description
token string

the JSON Web Token (JWT)

nexmo_api_url string

url of the nexmo api to be called

datacenter string

datacenter of interest

Source:
Returns:
Type
Promise.<Array.<MediaConnectionReport>>
Example

Return a list with the connection health of the media servers

 rtc.checkMediaServers('nexmo-api-url','dc').then((responseArray) => {
   console.log(responseArray);
 }).catch((error) => {
   console.log(error);
 });

connect()

Connect to the cloud.

Source:

<async> connectivityReport(token, options)

Get a connectivity report for all Vonage DCs and Media Servers.

Parameters:
Name Type Description
token string

the JSON Web Token (JWT)

options object

configure the connectivityReport

Properties
Name Type Description
dcListCallback function

a callback function to edit the list of datacenters before connectivity checks

Source:
Returns:
Type
Promise.<Report>
Example

Get a connectivity report

 rtc.connectivityReport(token, {
   dcListCallback: (dcList) => {...dcList, additionalDc}
 }).then((report) => {
   console.log(report);
 }).catch((error) => {
   console.log(error);
 });

createSession(token)

Create a new Session.

Parameters:
Name Type Description
token string

the user JSON Web Token (JWT)

Source:
Returns:
  • the application logged in to
Type
Promise.<Application>
Example

Create a session and return the Application

 rtc.createSession(token).then((application) => {
   console.log(application);
 }).catch((error) => {
   console.log(error);
 });

deleteSession()

Delete existing Session.

Source:
Returns:
  • response with rid and type
Type
Promise.<CAPIResponse>
Example

Delete existing session

 rtc.deleteSession().then((response) => {
   console.log(response);
 }).catch((error) => {
   console.log(error);
 });

disconnect()

Disconnect from the cloud.

Source:

Events


disconnect

Client listening for disconnect event.

Source:
Example

Listen for websocket disconnect event

    rtc.on("disconnect", (reason) => {
     console.log("disconnect", reason);
    });

error

Client listening for error event.

Source:
Example

Listen for websocket error event

    rtc.on("error", (error) => {
     console.log("error", error);
    });

ready

Client listening for ready event.

Source:
Example

Listen for websocket ready event

    rtc.on("ready", () => {
     console.log("connection ready");
    });

reconnect

Client listening for reconnect event.

Source:
Example

Listen for websocket reconnect event

    rtc.on("reconnect", (retry_number) => {
     console.log("reconnect", retry_number);
    });

reconnecting

Client listening for reconnecting event.

Source:
Example

Listen for websocket reconnecting event

    rtc.on("reconnecting", (retry_number): void => {
     console.log("reconnecting", retry_number);
    });