Functions

initialize()

Overview

Initialize the Twilio Client SDK.

Syntax

twilio.initialize()

shutdown()

Overview

Shuts down the Twilio Client SDK.

This will terminate all connections, release all Device objects, and release any resources used by the SDK.

Syntax

twilio.shutdown()

isInitialized()

Overview

Determines if the Twilio Client SDK has been initialized or not. Returns true or false

If you expect your application to run in the background when the user has switched to other applications, you will want to check the return value of this method on startup. The Android OS may have killed your application due to memory pressure, but the SDK may still be running in the background.

Syntax

twilio.isInitialized()

createDevice()

Overview

Create and initialize a new Device object.

If the incoming capabilities are defined, then the device will automatically begin listening for incoming connections.

Syntax

twilio.createDevice(capabilityToken)

capabilityToken (required)

String. A signed JSON Web Token that defines the features available to the Device. These may be created using the Twilio Helper Libraries available here.com. The capabilities are used to begin listening for incoming connections and provide the default parameters used for establishing outgoing connections. Please visit Capability Tokens for more information.

release()

Overview

Shuts down and releases the Device. This will terminate all connections and release resources immediately.

Syntax

twilio.release()

listen()

Overview

Start listening for incoming connections.

The Device will automatically listen for incoming connections on calls to twilio.createDevice() or twilio.updateCapabilityToken() if the token allows.

This method only needs to be called if twilio.unlisten() was previously called.

Syntax

twilio.listen()

unlisten()

Overview

Stop listening for incoming connections.

This could be used for a "silence" mode on the your Android application, for instance.

This method will do nothing if the Device is currently not listening, either because of a previous call to twilio.unlisten() or because the Device has not been granted the incoming capability.

Syntax

twilio.unlisten()

connect()

Overview

Creates a new connection to the Twilio application specified in the capability token of the Device.

Parameters are passed to the application unmodified.

Syntax

twilio.connect(params)

params (optional)

Table. An optional table containing parameters for the outgoing connection that get passed to your Twilio Application. These parameters are merged with any parameters supplied in the Capability Token. If there are any key collisions with the two Maps, the value(s) from the Capability Map will take precedence.

accept()

Overview

Accepts an incoming connection request.

When an incoming connection is received, calling this method will accept the incoming connection.

Syntax

twilio.accept()

ignore()

Overview

Ignores an incoming connection request.

The caller will receive no notification that the call was ignored.

When an incoming connection is received, calling ignore will close the incoming connection request and the connection may not be accepted.

Syntax

twilio.ignore()

reject()

Overview

Rejects an incoming connection request.

The caller may receive a notification that the call was rejected.

When an incoming connection is received, notifying the caller that the call was rejected.

Syntax

twilio.reject()

disconnect()

Overview

Disconnect the connection.

Syntax

twilio.disconnect()

disconnectAll()

Overview

Disconnects all current connections associated with the Device.

This a convenience routine that disconnects all current incoming and outgoing connections, including pending incoming connections.

Syntax

twilio.disconnectAll()

sendDigits()

Overview

Send a string of digits over the connection.

Syntax

twilio.sendDigits(digits)

digits (required)

String. a String of one or more valid digits and optional 'w' chars. Valid digits are '0' - '9', '*', '#', and 'w'. Each 'w' will cause a 500 ms pause between digits sent. If any invalid character is present, no digits will be sent.

getCapabilityToken()

Overview

Retrieves the capability token originally passed to twilio.createDevice().

Syntax

twilio.getCapabilityToken()

updateCapabilityToken()

Overview

Updates the capabilities of the Device.

There may be circumstances when the defined capabilities have expired or need to change. For example, the Device may enter the State because the capabilities have expired. In these cases, the capabilities will need to be updated. If the device is currently listening for incoming connections, it will restart the listening process (if permitted) using these updated capabilities.

Existing connections are not affected by updating the capability token.

Syntax

twilio.updateCapabilityToken(capabilityToken)

capabilityToken (required)

String. The new capability token string.

getCapabilities()

Overview

Current capabilities of the Device. Returns table

Syntax

twilio.getCapabilities()

Properties

INCOMING

Boolean. Indicates whether the device can receive incoming calls.

OUTGOING

Boolean. Indicates whether the device can make outgoing calls.

EXPIRATION

String. Represents the time the device's capability token expires (number of seconds relative to the UNIX epoch).

ACCOUNT_SID

String. Represents the account SID.

APPLICATION_SID

String. Represents the application SID used when making an outgoing call. Only present if OUTGOING is also present with a true value.

APPLICATION_PARAMETERS

Table. Parameters that are sent to the Twilio Application with each outgoing connection.

CLIENT_NAME

String. Represents the client name that should be used for incoming calls.

getState()

Overview

Retrieves the current state of the device. Returns a string. Possible values are OFFLINE, READY, and BUSY.

Syntax

twilio.getState()

setIncomingSoundEnabled()

Overview

Set whether the default Twilio sound should be played for an incoming connection.

By default, twilio.isIncomingSoundEnabled() is true.

Syntax

twilio.setIncomingSoundEnabled(bool)

bool (required)

Boolean. true to enable, false to disable

isIncomingSoundEnabled()

Overview

Return whether the default Twilio sound should be played for an incoming connection. Returns a boolean.

The default value is true.

Syntax

twilio.isIncomingSoundEnabled()

setOutgoingSoundEnabled()

Overview

Set whether the default Twilio sound should be played for an outgoing connection.

By default, twilio.isIncomingSoundEnabled() is true.

Syntax

twilio.setOutgoingSoundEnabled(bool)

bool (required)

Boolean. true to enable, false to disable

isOutgoingSoundEnabled()

Overview

Return whether the default Twilio sound should be played for an outgoing connection. Returns a boolean.

The default value is true.

Syntax

twilio.isOutgoingSoundEnabled()

setDisconnectSoundEnabled()

Overview

Set whether the default Twilio sound should be played when a connection is disconnected either normally or due to an error.

The disconnected sound will not be played if the connection is ignored or rejected.

By default, twilio.isDisconnectSoundEnabled() is true.

Syntax

twilio.setDisconnectSoundEnabled(bool)

bool (required)

Boolean. true to enable, false to disable

isDisconnectSoundEnabled()

Overview

Return whether the default Twilio sound should be played when a connection is disconnected either normally or due to an error. Returns a boolean.

The disconnected sound will not be played if the connection is ignored or rejected.

The default value is true.

Syntax

twilio.isDisconnectSoundEnabled()

getConnectionParameters()

Overview

Retrieves the set of application parameters associated with this connection. Returns a table.

Incoming connection parameters are defined by set of values described by the constants listed below.

Outgoing connection parameters are defined by the union of optional application parameters specified in the Capability Token and any additional parameters specified when the twilio.connect() method is called.

Syntax

twilio.getConnectionParameters()

Properties

From

String. Representa the calling party. If the caller is a telephone, it will be in the E.164 format. If the caller is another Twilio Client, it will be in a URI format "client:name".

To

String. Represents the client name of the called party. This is in a URI format "client:name".

AccountSID

String. Represents the account id making the incoming call.

APIVersion

String. Represents the version of the Twilio API used in the server application.

CallSID

String. Represents a unique identifier for the incoming call.

getConnectionState()

Overview

Retrieves the current state of the connection. Returns a string. Possible values are PENDING, CONNECTING, CONNECTED, and DISCONNECTED.

Syntax

twilio.getConnectionState()

setMuted()

Overview

Mutes or unmutes the microphone's audio for the connection.

Syntax

twilio.setMuted(bool)

bool (required)

Boolean. true to mute, false to unmute

isMuted()

Overview

Reports whether the microphone's audio for the connection is muted. Returns a boolean.

Syntax

twilio.isMuted()

setReceivePresenceEvents()

Overview

Sets whether or not the application wants to receive presence events.

Since bandwidth and battery life can both be precious resources on a mobile device, you may not want to incur the extra overhead of receiving and processing presence notifications.

Syntax

twilio.setReceivePresenceEvents(bool)

bool (required)

Boolean. true to enable, false to disable