7.6.0
The SDK creation factory. Create an instance of the SDK by calling this factory with the desired configurations. The SDK instance will be referred as 'api' throughout the rest of the documentation content.
Name | Description |
---|---|
config config
|
The configuration object. |
api
:
The SDK instance.
// Instantiate the SDK.
import { create } from '@rbbn/webrtc-js-sdk'
const client = create({
authentication: { ... },
logs: { ... },
...
});
// Use the SDK's API.
client.on( ... );
The configuration object. This object defines what different configuration values you can use when instantiating the SDK using the create function.
Configuration options for the Logs feature.
The SDK will log information about the operations it is performing. The amount of information will depend on how the Logs feature is configured.
The format of logs can also be customized by providing a LogHandler. This function will receive a LogEntry which it can handle as it sees fit. By default, the SDK will log information to the console. For more information, see the Logs feature description.
Name | Description |
---|---|
logs Object
|
Logs configs. |
logs.logLevel string
(default 'debug' )
|
Log level to be set. See logger.levels . |
logs.handler logger.LogHandler?
|
The function to receive log entries from the SDK. If not provided, a default handler will be used that logs entries to the console. |
logs.logActions (Object | boolean)
(default false )
|
Options specifically for action logs when logLevel is at DEBUG+ levels. Set this to false to not output action logs. |
logs.logActions.handler logger.LogHandler?
|
The function to receive action log entries from the SDK. If not provided, a default handler will be used that logs actions to the console. |
logs.logActions.actionOnly boolean
(default false )
|
Only output information about the action itself. Omits the SDK context for when it occurred. |
logs.logActions.collapsed boolean
(default false )
|
Whether logs should be minimized when initially output. The full log is still output and can be inspected on the console. |
logs.logActions.diff boolean
(default false )
|
Include a diff of what SDK context was changed by the action. |
logs.logActions.level string
(default 'debug' )
|
Log level to be set on the action logs |
logs.logActions.exposePayloads boolean
(default true )
|
Allow action payloads to be exposed in the logs, potentially displaying sensitive information. |
Configuration options for the Connectivity feature. The SDK can only use keepalive as the connectivity check.
Keep Alive: The client sends "keepalive" messages (to the server) on the websocket at regular intervals. This lets the server know that the client is still connected, and that it should "keep the connection alive".
For more information on keepalive see here: https://en.wikipedia.org/wiki/Keepalive
Name | Description |
---|---|
connectivity Object
|
Connectivity configs. |
connectivity.pingInterval Number
(default 30000 )
|
Time in between websocket ping attempts (milliseconds). |
connectivity.reconnectLimit Number
(default 5 )
|
Number of failed reconnect attempts before reporting an error. Can be set to 0 to not limit reconnection attempts. |
connectivity.reconnectDelay Number
(default 5000 )
|
Base time between websocket reconnect attempts (milliseconds). |
connectivity.reconnectTimeMultiplier Number
(default 1 )
|
Reconnect delay multiplier for subsequent attempts. The reconnect delay time will be multiplied by this after each failed reconnect attempt to increase the delay between attempts. eg. 5000ms then 10000ms then 20000ms delay if value is 2. |
connectivity.reconnectTimeLimit Number
(default 640000 )
|
Maximum time delay between reconnect attempts (milliseconds). Used in conjunction with the reconnect time multiplier to prevent overly long delays between reconnection attempts. |
connectivity.autoReconnect Boolean
(default true )
|
Flag to determine whether the SDK will attempt to automatically reconnect after connectivity disruptions. |
connectivity.checkConnectivity Boolean
(default true )
|
Flag to determine whether the SDK should check connectivity. |
connectivity.webSocketOAuthMode string
(default none )
|
When set to 'query', the OAuth bearer access token will be appended as a query string parameter to the websocket address. |
Configuration options for the notification feature.
Name | Description |
---|---|
notifications Object
|
The notifications configuration object. |
notifications.idCacheLength number
(default 100 )
|
Default amount of event ids to remember for de-duplication purposes. |
notifications.incomingCallNotificationMode string
(default 'any-channel' )
|
Communication channel mode used for incoming call notifications. Supported values are 'any-channel' or 'push-channel-only'. |
notifications.pushRegistration Object?
|
Object describing the server to use for push services. |
notifications.pushRegistration.server string?
|
Hostname for the push registration server. |
notifications.pushRegistration.port string?
|
Port for the push registration server. |
notifications.pushRegistration.protocol string?
|
Protocol for the push registration server. |
notifications.pushRegistration.version string?
|
Version for the push registration server. |
Configurable options for the Request plugin.
The SDK uses the Request plugin to make REST requests to the Gateway.
Configuration options for the Authentication feature.
Name | Description |
---|---|
authentication Object
|
Authentication configs. |
authentication.server Object
|
|
authentication.server.base string
|
Hostname of the server to be used for requests. |
authentication.server.protocol string
(default 'https' )
|
Protocol to be used for requests. |
authentication.server.port number
(default 443 )
|
Port to be used for requests. |
Configuration options for the Subscription feature.
Name | Description |
---|---|
subscription Object
|
Subscription config. |
subscription.expires number
(default 3600 )
|
The amount of time (in seconds) for which to keep subscription up and alive. Cannot be less than minimum threshold of 60 seconds. |
subscription.serviceUnavailableMaxRetries number
(default 3 )
|
The maximum number of times this client will retry in order to subscribe for a given service, while getting 'Service Unavailable' from backend. |
subscription.websocket Object
|
|
subscription.websocket.server string
|
Hostname of the server to be used for websocket notifications. |
subscription.websocket.protocol string
(default wss )
|
Protocol to be used for websocket notifications. |
subscription.websocket.port Number
(default 443 )
|
Port to be used for websocket notifications. |
Configuration options for the call feature.
Name | Description |
---|---|
call Object
|
The call configuration object. |
call.defaultPeerConfig call.RTCPeerConnectionConfig?
|
A key-value dictionary that corresponds to the available RTCPeerConfiguration which is normally passed when creating an RTCPeerConnection. See RTCPeerConnection's configuration parameters for more information. This is the recommended way of setting ICE servers and other RTCPeerConnection-related configuration. |
call.iceCollectionIdealTimeout number
(default 1000 )
|
The amount of time to wait for an ideal candidate in milliseconds.
The default is 1000ms. An ideal list of candidates is a complete list of candidates considering the RTCPeerConnection configuration.
Note that this values will not be considered if a custom function is passed through the
iceCollectionCheckFunction
, and
any timeouts must be handled by the custom function.
|
call.iceCollectionMaxTimeout number
(default 3000 )
|
The maximum amount of time to wait for ICE collection in milliseconds.
The default is 3000ms. After this time has been reached, the call will proceed with the currently gathered candidates.
Note that this values will not be considered if a custom function is passed through the
iceCollectionCheckFunction
, and
any timeouts must be handled by the custom function.
|
call.iceCollectionCheckFunction Function?
|
Override the default IceCollectionCheckFunction to manually decide when to proceed with operations, error out, or wait for the appropriate states and candidates. The function will receive an object containing the ice collection info. See IceCollectionInfo for more details. The function must return a results object with details on how to proceed with the ICE collection check or operatiaon. See IceCollectionResult object for details on the format of the return object. See IceCollectionCheckFunction for more information on the form of the function, as well as information about the default IceCollectionCheckFunction that is used if nothing is provided. |
call.serverTurnCredentials boolean
(default true )
|
Whether server-provided TURN credentials should be used. |
call.sdpHandlers Array<call.SdpHandlerFunction>?
|
List of SDP handler functions to modify SDP. Advanced usage. |
call.earlyMedia boolean
(default false )
|
Whether early media should be supported for calls. Not supported on Firefox. |
call.resyncOnConnect boolean
(default false )
|
Whether the SDK should re-sync all call states after connecting (requires WebRTC Gateway 4.7.1+). |
call.mediaBrokerOnly boolean
(default false )
|
Whether all Calls will be anchored on the MediaBroker instead of being peer-to-peer. Set to true if the backend is configured for broker only mode. |
call.removeBundling boolean
(default false )
|
Whether to remove a=group attributes to stop media bundling from incoming and outgoing SDP messages. |
call.ringingFeedbackMode string
(default 'auto' )
|
The mode for sending ringing feedback to the Caller ('auto', 'manual').
By default, feedback will be automatically sent when a call has been received. In 'manual' mode, the application
must initiate the feedback being sent. See the
call.sendRingingFeedback
API for more info.
|
call.callAuditTimer number
(default 25000 )
|
Time interval, in milliseconds between call audits. |
call.mediaConnectionRetryDelay number
(default 3000 )
|
Delay, in milliseconds for the passive side of a call to wait before trying a media reconnection. |
call.normalizeDestination boolean
(default true )
|
Specifies whether or not SIP address normalization will be applied. |
The 'api' is the type returned by the create function. It contains various top-level functions that pertain to SDK global instance as well as several nested namespaces that pertain to various features (e.g. call, contacts, presence, etc).
Returns the current version of the API.
Destroys the SDK, and removes its state, rendering the SDK unusable. Useful when a user logs out and their call data needs to be destroyed. The SDK must be recreated to be usable again. The destroy command is async, and will happen on the next tick so as not to interfere with any ongoing events.
// Instantiate the SDK.
import { create } from '@rbbn/webrtc-js-sdk'
const config = {
authentication: { ... },
logs: { ... },
...
}
let client = create(config);
client.on( ... )
// Use the SDK
...
// Destroy the SDK, then recreate on the next step
client.destroy()
client = create(config)
client.on( ... )
Update the configuration values for the SDK to use.
This API will only modify the configurations provided, leaving other configurations as they were originally set, by performing a merge of the new values into the previous values.
Please note that the object provided to the updateConfig
API may be different
than the object retrieved from the getConfig API. This may happen when a format
change has happened and the SDK modifies the provided format to alleviate
backwards-compatibility issues. We recommend ensuring the configurations you
provide are as described by the config section.
// Instantiate the SDK with certain configs.
const client = create({
authentication: { ... },
logs: { ... },
...
})
// Modify a subsection of the configs at a later time.
// This will only update the specified configurations.
client.updateConfig({
logs: {
loglevel: 'DEBUG'
}
})
Add an event listener for the specified event type. The event is emitted by the SDK instance.
// Listen for events of a specific type emitted by the SDK.
client.on('dummy:event', function (params) {
// Handle the event.
})
Retrieve information about the browser being used.
Browser information being defined indicates that the browser supports basic webRTC scenarios.
const details = client.getBrowserDetails()
log(`Browser in use: ${details.browser}, version ${details.version}.`)
Retrieves information about the current user.
Object
:
user The user data.
string
:
user.username The username of the current user. Note that this username can take different encoded forms.
It's not meant to be displayed to a user.
string
:
user.token The current access token.
Sets the user credentials necessary to make requests to the platform.
The SDK will emit an auth:change event when the credentials are set. If there was an issue with the credentials, an auth:error event will be emitted instead.
The currently set user information can be retrieved using the getUserInfo API.
If credentials have previously been set, they cannot be set again if there is an active subscription. An auth:error will be emitted in this scenario.
client.setCredentials({
username: 'alfred@example.com',
password: '********'
authname: '********'
});
Sets the user credentials necessary to make requests to the platform, using HMAC token authentication.
An HMAC token is used to verify a user via the user's authorization within an of organization. HMAC tokens
are generated by using the HmacSHA1 algorithm and a key on a data object containing an
authenticationTokenRequest
object with the following properties:
The SDK will emit an auth:change event when the credentials are set. If there was an issue with the credentials, an auth:error event will be emitted instead.
The currently set user information can be retrieved using the getUserInfo API.
If credentials have previously been set, they cannot be set again if there is an active subscription. An auth:error will be emitted in this scenario.
const hmacToken = HmacSHA1Algorithm({
authenticationTokenRequest: {
subscriberId: 'alfred',
organizationId: 'example.com'
}
}, key)
client.setCredentials({
username: 'alfred@example.com',
hmacToken
});
Sets the user credentials necessary to make requests to the platform, using bearer token authentication.
The bearerAccessToken provided establishes what can be accessed by the SDK. The bearerAccessToken can be set again after subscription as long as the subscribed username is passed with the updated bearerAccessToken.
The SDK will emit an auth:change event when the credentials are set. If there was an issue with the credentials, an auth:error event will be emitted instead.
The currently set user information can be retrieved using the getUserInfo API.
If credentials have previously been set, they cannot be set again if there is an active subscription. An auth:error will be emitted in this scenario.
client.setCredentials({
username: 'alfred@example.com',
bearerAccessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
});
An error occurred with server authorization.
This event will be emitted anytime a REST request to the server is rejected due to an authorization issue. This may occur for invalid credentials or expired tokens, depending on which form of authentication the application has chosen to use.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |
The authentication credentials have changed.
This event is triggered after calling the setCredentials API.
The current user information can be retrieved using the getUserInfo API.
Name | Description |
---|---|
params Object
|
There was an error with authentication credentials.
This event is triggered after calling the setCredentials API.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |
The 'call' namespace (within the 'api' type) is used to make audio and video calls to and from SIP users and PSTN phones.
Call functions are all part of the 'call' namespace.
The SIP URI ie: sip:joe@domain.com
Type: string
Information about a Call.
Can be retrieved using the call.getAll or call.getById APIs.
Type: Object
(string)
: The ID of the call.
(user.UserID)
: A unique identifier (uri) of the person who made the call.
(user.UserID)
: A unique identifier (uri) of the person who receives the call.
(string)
: The direction in which the call was created. Can be 'outgoing' or 'incoming'.
(string)
: The current status of the call's media connection. See
call.mediaConnectionStates
for possible states.
(boolean)
: Indicates whether this call is currently being held locally.
(boolean)
: Indicates whether this call is currently being held remotely.
(Array<string>)
: A list of Track IDs that the call is sending to the remote participant.
(Array<string>)
: A list of Track IDs that the call is receiving from the remote participant.
(call.MediaOffered?)
: Information about what media was offered by the person who made the call.
(Object)
: Information about the other call participant.
(call.BandwidthControls)
: The bandwidth limitations set for the call.
(Array<call.CustomParameter>)
: The locally set Custom Parameters for the call.
(number)
: The start time of the call in milliseconds since the epoch.
(number?)
: The end time of the call in milliseconds since the epoch.
The MediaConstraint type defines the format for configuring media options.
Either the exact
or ideal
property should be provided. If both are present, the
exact
value will be used.
When the exact
value is provided, it will be the only value considered for the option.
If it cannot be used, the constraint will be considered an error.
When the ideal
value is provided, it will be considered as the optimal value for the option.
If it cannot be used, the closest acceptable value will be used instead.
A string value can be provided directly instead of using the MediaConstraint format.
Using a string directly is not recommended, since behaviour may differ depending
on browser and media property. For most properties, a direct string value will be
handled as ideal
behaviour, but some properties may follow the exact
behaviour
(eg. deviceId
).
Type: Object
(string?)
: The required value for the constraint. Other values will not be accepted.
(string?)
: The ideal value for the constraint. Other values will be considered if necessary.
// Specify video resolution when making a call.
client.call.make(destination, {
audio: true,
video: true,
videoOptions: {
// Set height and width constraints to ideally be 1280x720.
height: { ideal: 720 },
width: { ideal: 1280 }
}
})
The AudioOptions type defines the format for specifying audio-related constraints.
Type: Object
(call.MediaConstraint)
: ID of the microphone to receive audio from.
// Specify what specific microphone device to use by providing its device ID.
client.call.make(destination, {
audio: true,
audioOptions: { deviceId: 'some unique device ID' }
})
The VideoOptions type defines the format for specifying video-related constraints.
Type: Object
(call.MediaConstraint)
: ID of the camera to receive video from.
(call.MediaConstraint?)
: The height of the video.
(call.MediaConstraint?)
: The width of the video.
(call.MediaConstraint?)
: The frame rate of the video.
client.call.make(destination, {
video: true,
videoOptions: {
deviceId: 'some unique device ID',
// Set height and width constraints to exactly be 1280x720.
height: { exact: 720 },
width: { exact: 1280 },
frameRate: { exact: 24 }
}
})
The ScreenOptions type defines the format for specifying screen capturing-related constraints.
Type: Object
(call.MediaConstraint?)
: The height of the screen capture.
(call.MediaConstraint?)
: The width of the screen capture.
(call.MediaConstraint?)
: The frame rate of the live screen share.
client.call.make(destination, {
screen: true,
screenOptions: {
// Set height and width constraints to exactly be 1280x720.
height: { exact: 720 },
width: { exact: 1280 },
frameRate: { exact: 24 }
}
})
The MediaOffered type defines what media capabilities are offered by the person making a call. This is an optional property and therefore may be null if it is not known or if it's associated with caller's side of the call.
Type: Object
(boolean)
: Specifies if any audio capability has been offered by the caller. If set to true, then the caller is capable of supporting at least one audio stream in the current call.
(boolean)
: Specifies if any video capability has been offered by the caller. If set to true, then the caller is capable of supporting at least one video stream in the current call.
The BandwidthControls type defines the format for configuring media and/or track bandwidth options. BandwidthControls only affect received remote tracks of the specified type.
Type: Object
(number?)
: The desired combined bandwidth bitrate in kilobits per second for all media in the call.
(number?)
: The desired bandwidth bitrate in kilobits per second for received remote audio.
(number?)
: The desired bandwidth bitrate in kilobits per second for received remote video.
// Specify received remote video bandwidth limits when making a call.
client.call.make(destination, mediaConstraints,
{
bandwidth: {
video: 5
}
}
)
The DSCPControls type defines the format for configuring network priorities (DSCP marking) for the media traffic.
If DSCPControls are not configured for a call the network priority of the traffic for all media kinds will be the default (i.e., "low").
Type: Object
(RTCPriorityType?)
: The desired network priority for audio traffic (see
RTCPriorityType Enum
for the list of possible values).
(RTCPriorityType?)
: The desired network priority for video traffic (see
RTCPriorityType Enum
for the list of possible values).
(RTCPriorityType?)
: The desired network priority for screen share traffic (see
RTCPriorityType Enum
for the list of possible values).
Configuration options for an RTCPeerConnection. It represents an RTCPeerConfiguration dictionary, whose parameters are documented here.
Type: Object
Name | Description |
---|---|
iceServers Array<RTCIceServer>?
|
The list of ICE servers to be used for calls. The full set of properties defined for an RTCIceServer, are mentioned here . |
sdpSemantics string
(default 'unified-plan' )
|
The sdpSemantics to use (
'unified-plan'
or
'plan-b'
).
As 'plan-b' has become a deprecated option, it will therefore be removed in the future.
|
iceCandidatePoolSize number?
|
An unsigned 16-bit integer value which specifies the size of the prefetched ICE candidate pool. The default value is 0 (meaning no candidate prefetching will occur). |
iceTransportPolicy string?
|
The current ICE transport policy; if the policy isn't specified, 'all' is assumed by default. Possible values are: 'all', 'public', 'relay'. |
bundlePolicy string?
|
For further description on this and other properties, see RTCPeerConnection's configuration parameters . |
Type: Object
((Array<string> | string))
: Either an array of URLs for reaching out several ICE servers or a single URL for reaching one ICE server. See
RTCIceServers.urls documentation
to learn more about the actual url format.
Starting with Chromium 110, TURN(S) urls must only contain a transport
parameter in the query section and STUN urls must not specify any query section.
(string?)
: The credential needed by the ICE server.
(string?)
: The credential needed by the ICE server.
This object is provided to the IceCollectionCheckFunction, and contains the necessary information about the call (i.e., call ID, current call operation), and information about the ongoing ICE collection, such as the list of all ICE candidates collected so far and the ICE gathering state.
Type: Object
(string)
: The ID of the call.
(string)
: The current operation of the call.
(string)
: The reason the check function was called. Three possible values:
'NewCandidate' - A new ICE candidate was collected. Note: there may be multiple new ICE candidates collected.
'IceGatheringStateChanged' - The ICE gathering state changed.
'Scheduled' - A scheduled call (for first invocation, and subsequent invocations based on
wait
value returned by
IceCollectionCheckFunction
.)
(Array<RTCIceCandidate>)
: An array of all ICE candidates collected so far.
(number)
: The time elapsed since the start of the ICE collection process.
(string)
: The current ICE gathering state.
See
RTCPeerConnection.iceGatheringState
.
(Object)
: The current configration for the RTCPeerConnection.
(string)
: The current local session description set on the peer.
The form of the ICE collection check function, the arguments that it receives, and the outputs expected.
This function is provided the necessary details of the current WebRTC session and ICE collection
(IceCollectionInfo), which it can use to dictate how to proceed with a call.
The function can be invoked for three different reasons:
a new ICE candidate was collected, the ICE gathering state changed, or a scheduled call based on the wait
time set after
an initial invocation of the function.
The function must then return an appropriate result object in the format of IceCollectionCheckResult
which will dictate how the call will proceed. An incorrect return object, or result type
, will cause the call to end with an error.
[Default] The default IceCollectionCheckFunction uses the following algorithm to determine if the call can proceed to negotiation:
iceGatheringState
is "complete" at any stage, then:
The ideal and max timeouts can be configured with the idealIceCollectionTimeout
and maxIceCollectionTimeout
properties of
the call config.
Type: Function
Name | Description |
---|---|
iceCollectionInfo call.IceCollectionInfo
|
Information about the current status of the ICE candidate collection. |
iceTimeouts Object
|
Configurations provided to the SDK for ICE collection timeout boundaries. |
iceTimeouts.iceCollectionIdealTimeout number
|
The amount of time to wait for ideal candidates, in milliseconds. See config.call for more information. |
iceTimeouts.iceCollectionMaxTimeout number
|
The maximum amount of time to wait for ICE collection, in milliseconds. See config.call for more information. |
call.IceCollectionCheckResult
:
Information on how to proceed with the call and/or ICE collection.
function isRelayCandidate (candidate) {
// NOTE: This would need to be different for Firefox since the `.type` property doesn't exist
// and we would need to parse it ourselves in the `.candidate` property.
return candidate.type === 'relay'
}
function myIceCollectionCheck ({ iceGatheringState, iceCandidates }, iceTimeouts) {
if (iceGatheringState === 'complete') {
if (iceCandidates.some(isRelayCandidate)) {
return { type: 'StartCall' }
} else {
return { type: 'Error', error: new Error('Failed to start call because there is no relay candidates.') }
}
} else {
return { type: 'Wait' }
}
}
Type: Object
(string)
: Indicates how the system should proceed with the call operation / ICE collection. The possible values are:
'StartCall' - instruct the system to start the call with the currently gathered ICE candidates and other information.
'Error' - instruct the system to fail the call with an error. The error to communicate to the user should be specified in the
error
property.
'Wait' - instruct the system to wait for the specified amount of time before triggering a new ICE collection check. The amount
of wait time should be specified in the
wait
property.
(string)
: An error to be sent the user when the
type
of the result is
IceCollectionCheckResultType.Error
(number)
: The amount of time (in milliseconds) to wait before triggering a new ICE collection check. This is only
valid if the
type
of result is
IceCollectionCheckResultType.Wait
. If a value is not provided, the ICE collection check function
will only be triggered for new candidates or when the ICE gathering state changes.
Type: Object
(string)
: The id corresponding to the call for which the handler is being run.
(RTCSdpType)
: The session description's type.
(string)
: The step that will occur after the SDP Handlers are run.
Will be either 'set' (the SDP will be set locally) or 'send' (the SDP will
be sent to the remote endpoint).
(string)
: Which end of the connection created the SDP.
The form of an SDP handler function and the expected arguments that it receives.
Type: Function
Name | Description |
---|---|
newSdp Object
|
The SDP so far (could have been modified by previous handlers). |
info call.SdpHandlerInfo
|
Additional information that might be useful when making SDP modifications. |
originalSdp Object
|
The SDP in its initial state. |
Object
:
The resulting modified SDP based on the changes made by this function.
The state representation of a Media object. Media is a collection of Track objects.
Type: Object
A Track is a stream of audio or video media from a single source.
Tracks can be retrieved using the Media module's getTrackById
API and manipulated with other functions of the Media module.
Type: Object
(boolean)
: Indicator of whether this Track is disabled or not. If disabled, it cannot be re-enabled.
(boolean)
: Indicator of whether this Track is a locally created one or is a remote one.
(string)
: The ID of the Track.
(string)
: The kind of Track this is (audio, video).
(string)
: The label of the device this Track uses.
(boolean)
: Indicator on whether this Track is muted or not.
(boolean)
: Indicator on whether this Track is receiving media from its source or not.
When true, the Track can be considered removed. This indicator is affected by actions outside the
control of the SDK, such as the remote endpoint of a Call stopping to send media for a remote Track,
or the browser temporarily disabling the SDK's access to a local Track's source.
(string)
: The state of this Track. Can be 'live' or 'ended'.
(string)
: The ID of the Media Stream that includes this Track.
A collection of media devices and their information.
Type: Object
(Array<call.DeviceInfo>)
: A list of camera device information.
(Array<call.DeviceInfo>)
: A list of microphone device information.
(Array<call.DeviceInfo>)
: A list of speaker device information.
Custom SIP headers can be used to convey additional information to a SIP endpoint.
These parameters must be configured on the server prior to making a request, otherwise the request will fail when trying to include the parameters.
These parameters can be specified with the call.make and call.answer APIs. They can also be set after a Call is established using the call.setCustomParameters API, and sent using the call.sendCustomParameters API.
Custom headers may be received anytime throughout the duration a call. A remote endpoint may send custom headers when starting a call, answering a call, or during call updates such as hold/unhold and addition/removal of media in the call. When these custom headers are received, the SDK will emit a call:customParameters event which will contain the custom parameters that were received.
A Call's custom parameters are stored on the Call's CallObject, which can be retrieved using the call.getById or call.getAll APIs. These are the parameters that will be sent to the remote endpoint of the Call. Parameters received from a Call are not stored as part of the CallObject and are only provided via the call:customParameters event.
Type: Object
// Specify custom parameters when making a call.
client.call.make(destination, mediaConstraints,
{
customParameters: [
{
name: 'X-GPS',
value: '42.686032,23.344565'
}
]
}
)
Starts an outgoing call to a SIP_URI or a TEL_URI.
The call will be tracked by a unique ID that is returned by the API. The application will use this ID to identify and control the call after it has been initiated.
The call.getById API can be used to retrieve the current information about the call.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:start event locally when the operation completes. When the remote participant receives the call, a call:receive event will be emitted remotely for them.
The SDK requires access to the machine's media devices (eg. microphone) in order to make a call. If it does not already have permissions to use the devices, the user may be prompted by the browser to give permissions.
Detached media can be used when starting a call. Detached media is created locally outside of a call and must be managed by the application. It can be used when making a call by passing an array of detached track ids in the media object. You can start a call with a mixture of detached and requested media, however, you can only use one of each type (audio, video, screen). For example, you could include a detached track id for video, and set MediaConstraint.audio: true, but you can't set MediaConstraint.video: true if you have passed in a detached track id of kind video.
Name | Description |
---|---|
destination (call.SIP_URI | call.TEL_URI)
|
The desired destination. |
media Object
|
The media options the call should be initialized with. |
media.audio boolean
(default false )
|
Whether the call should have audio on start. Currently, audio-less calls are not supported. |
media.audioOptions call.AudioOptions?
|
Options for configuring the call's audio. |
media.video boolean
(default false )
|
Whether the call should have video on start. |
media.videoOptions call.VideoOptions?
|
Options for configuring the call's video. |
media.screen boolean
(default false )
|
Whether the call should have screenshare on start. (Note: Screensharing is not supported on iOS Safari.) |
media.screenOptions call.ScreenOptions?
|
Options for configuring the call's screenShare. |
media.medias Array<media.DetachedMedia>?
|
List of detached medias containing tracks to be attached to this call. |
options Object?
|
|
options.bandwidth call.BandwidthControls?
|
Options for configuring media's bandwidth. |
options.displayName string?
|
Custom display name to be provided to the destination. Not supported in all environments and may use default display name. |
options.customParameters Array<call.CustomParameter>?
|
Custom SIP header parameters for the SIP backend. |
options.dscpControls call.DSCPControls?
|
Options for configuring DSCP markings on the media traffic |
string
:
The generated ID of the newly created call.
// Listen for the event emitted after making a call.
client.on('call:start', function (params) {
const { callId, error } = params
if (error) {
// Call failed to initialize.
} else {
// Call was initialized, and the recipient user will be notified.
}
})
// Make an audio-only call.
const newCallId = client.call.make(destination, { audio: true })
Answers an incoming call.
The specified call to answer must be in a ringing state with an incoming direction. The call will become connected as a result of the operation.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:stateChange event locally when the operation completes. This indicates that the call has connected with the remote participant. The call.getById API can be used to retrieve the latest call state after the change. Further events will be emitted to indicate that the call has received media from the remote participant. See the call:newTrack event for more information about this.
The SDK requires access to the system's media devices (eg. microphone) in order to answer a call. If it does not already have permissions to use the devices, the user may be prompted by the browser to give permissions.
Name | Description |
---|---|
callId string
|
The ID of the call to answer. |
media Object
|
The media options the call should be initialized with. |
media.audio boolean
(default false )
|
Whether the call should create an audio track, on start. Currently, audio-less calls are not supported. |
media.audioOptions call.AudioOptions?
|
Options for configuring the call's audio. |
media.video boolean
(default false )
|
Whether the call should create a video track, on start. |
media.videoOptions call.VideoOptions?
|
Options for configuring the call's video. |
media.screen boolean
(default false )
|
Whether the call should create a screenshare track, on start. (Note: Screensharing is not supported on iOS Safari.) |
media.screenOptions call.ScreenOptions?
|
Options for configuring the call's screenShare. |
media.medias Array<media.DetachedMedia>?
|
List of detached medias containing tracks that can also be used when answering the call. |
options Object?
|
|
options.bandwidth call.BandwidthControls?
|
Options for configuring media's bandwidth. |
options.customParameters Array<call.CustomParameter>?
|
Custom SIP header parameters for the SIP backend. |
options.dscpControls call.DSCPControls?
|
Options for configuring DSCP markings on the media traffic |
Rejects an incoming call.
The specified call to reject must be in a ringing or initiated state with an incoming direction. The call will be ended as a result of the operation.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:stateChange event locally when the operation completes. The remote participant will be notified, through their own call:stateChange event, that the call was rejected.
Name | Description |
---|---|
callId string
|
The ID of the call to reject. |
Ignores an incoming call.
The specified call to ignore must be in a ringing state with an incoming direction. The call will be ended as a result of the operation.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:stateChange event locally when the operation completes. The remote participant will not be notified that the call was ignored.
Name | Description |
---|---|
callId string
|
The ID of the call to ignore. |
Forwards an incoming call to another user.
The specified destination will receive the Call instead of the current user.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:stateChange event after the operation completes.
Name | Description |
---|---|
callId string
|
ID of the call being acted on. |
destination (call.SIP_URI | call.TEL_URI)
|
The destination to forward the call to. |
Ends an ongoing call.
The SDK will stop any/all local media associated with the call. Events will be emitted to indicate which media tracks were stopped. See the call:trackEnded event for more information.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:stateChange event locally when the operation completes. The remote participant will be notified, through their own call:stateChange event, that the call was ended.
Name | Description |
---|---|
callId string
|
The ID of the call to end. |
Puts a call on hold.
The specified call to hold must not already be locally held. Any/all media received from the remote participant will stop being received, and any/all media being sent to the remote participant will stop being sent.
Some call operations cannot be performed while the call is on hold. The call can be taken off hold with the call.unhold API.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:stateChange event locally when the operation completes. The remote participant will be notified of the operation through a call:stateChange event as well.
Name | Description |
---|---|
callId string
|
The ID of the call to hold. |
Takes a call off hold.
The specified call to unhold must be locally held. If the call is not also remotely held, call media will be reconnected as it was before the call was held.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:stateChange event locally when the operation completes. The remote participant will be notified of the operation through a call:stateChange event as well.
Name | Description |
---|---|
callId string
|
The ID of the call to unhold. |
Add new media tracks to an ongoing call. Will get new media tracks from the specific sources to add to the call.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:newTrack event both for the local and remote users to indicate a track has been added to the Call.
Name | Description |
---|---|
callId string
|
The ID of the call to add media to. |
media Object
(default {} )
|
The media options to add to the call. |
media.audio boolean
(default false )
|
Whether to add audio to the call. |
media.video boolean
(default false )
|
Whether to add video to the call. |
media.screen boolean
(default false )
|
Whether to add the screenshare to the call. (Note: Screensharing is not supported on iOS Safari.) |
media.medias Array<media.DetachedMedia>?
|
List of detached medias containing tracks to be attached to this call. |
media.audioOptions call.AudioOptions?
|
Options for configuring the call's audio. |
media.videoOptions call.VideoOptions?
|
Options for configuring the call's video. |
media.screenOptions call.ScreenOptions?
|
Options for configuring the call's screenShare. |
options Object?
(default {} )
|
|
options.bandwidth call.BandwidthControls?
|
Options for configuring media's bandwidth. |
options.dscpControls call.DSCPControls?
|
Options for configuring DSCP markings on the media traffic |
Remove tracks from an ongoing call.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:trackEnded event for both the local and remote users to indicate that a track has been removed.
Name | Description |
---|---|
callId string
|
The ID of the call to remove media from. |
tracks Array
|
A list of track IDs to remove. |
options Object?
(default {} )
|
|
options.bandwidth call.BandwidthControls?
|
Options for configuring media's bandwidth. |
Adds local video to an ongoing Call, to start sending to the remote participant.
Can only be used in a basic media scenario, where the Call does not already have video. For more advanced scenarios, the call.addMedia API can be used.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:tracksAdded event both for the local and remote users to indicate a track has been added to the Call.
Name | Description |
---|---|
callId string
|
ID of the call being acted on. |
videoOptions call.VideoOptions?
|
Options for configuring the call's video. |
options Object?
|
|
options.bandwidth call.BandwidthControls?
|
Options for configuring media's bandwidth. |
options.dscpControls call.DSCPControls?
|
Options for configuring DSCP markings on the media traffic. |
Removes local video from an ongoing Call, stopping it from being sent to the remote participant.
Can only be used in a basic media scenario, where the Call has only one video track. For more advanced scenarios, the call.removeMedia API can be used.
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:tracksRemoved event for both the local and remote users to indicate that a track has been removed.
Name | Description |
---|---|
callId string
|
ID of the call being acted on. |
Replace a call's track with a new track of the same media type.
The operation will remove the old track from the call and add a new track to the call. This effectively allows for changing the track constraints (eg. device used) for an ongoing call.
Because it completely replaces an old track with a new one, the old track's state characteristics are not carried over in the new track's state. (e.g. if an old track's state was 'muted' and replacement of this track has occured, the new track's state will be 'unmuted', as this is its default state)
The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:trackReplaced event locally when the operation completes. The newly added track will need to be handled by the local application. The track will be replaced seamlessly for the remote application, which will not receive an event.
Name | Description |
---|---|
callId string
|
The ID of the call to replace the track of. |
trackId string
|
The ID of the track to replace. |
media Object
(default {} )
|
The media options. |
media.audio boolean
(default false )
|
Whether to create an audio track. |
media.audioOptions call.AudioOptions?
|
Options for configuring the audio track. |
media.video boolean
(default false )
|
Whether to create a video track. |
media.videoOptions call.VideoOptions?
|
Options for configuring the video track. |
media.screen boolean
(default false )
|
Whether to create a screen share track. |
media.screenOptions call.ScreenOptions?
|
Options for configuring the call's screenShare. |
media.medias Array<media.DetachedMedia>?
|
The detached media containing the track to be attached to this call. Though this parameter is an array for consistency with other APIs, it should only contain one entry. |
const callId = ...
// Get the video track used by the call.
const videoTrack = ...
// Replace the specified video track of the call with a new
// video track.
client.call.replaceTrack(callId, videoTrack.id, {
// The track should be replaced with a video track using
// a specific device. This effectively changes the input
// device for an ongoing call.
video: true,
videoOptions: {
deviceId: cameraId
}
})
const callId = ...
// Get the video track used by the call.
const videoTrack = ...
// Can also replace the specified video track of the call with a new
// screen sharing track because screen sharing is delivered as a video stream to remote peer.
// User will then be prompted to pick a specific screen to share and thus the device id will be selected.
client.call.replaceTrack(callId, videoTrack.id, {
// The track should be replaced with a screen sharing track.
// Note that 'screenOptions' property is not mandatory, as API will use default values
// for properties like: width, height, frameRate.
screen: true
})
Attempt to re-establish a media connection for a call.
This API will perform a "refresh" operation on the call with the intention
of resolving media issues that may have been encountered. This API is only
necessary after the Call's mediaConnectionState
has entered the failed
state, but may be used in other scenarios.
After the operation completes successfully, the Call will be re-establishing
its media connection. By this time, or shortly after, the Call's
mediaConnectionState should have
transitioned to checking
(via a
call:mediaConnectionChange
event) to signify the re-establishment. It will then transition to either
connected
or failed
state, similar to during the initial Call establishment.
If this operation fails, then the Call will not attempt the re-establishment
and will remain in the failed
mediaConnectionState.
Behaviour during the operation may differ slightly based on the browser.
Notably, Firefox will always transition to the checking
mediaConnectionState no matter what
the previous state was. Whereas Chrome will skip the checking
state,
transitioning directly to either connected
or failed
. This has the
implication for Chrome that if the state does not change (for example,
the Call is in the failed
state before the media restart operation,
and media re-establishment fails), then there will be no
call:mediaConnectionChange
event emitted. For this reason, Chrome-based applications may need a
short delay after receiving the call:mediaRestart
event before checking the Call's updated
mediaConnectionState to ensure the
application is acting on the "latest" state.
The SDK will emit a call:mediaRestart event when the operation completes.
The progress of the operation will be tracked via the call:operation event.
Name | Description |
---|---|
callId string
|
The ID of the call to act on. |
Plays an audio file to the remote side of the Call. This API will temporarily replace the Call's local audio track with an audio file for the duration of the audio file.
The Call must be in Connected
state and have a local audio track for this operation.
This API will not affect media other than the local audio track. Other media on the Call, such as local video or remote audio, can be muted or unrendered during this operation if desired.
This operation will use the browser's
Audio constructor
to read in the audio file. The filePath
parameter will be used directly with Audio
, so
can be either a relative file path to your audio file or a URL pointing to a file.
This API returns a promise that can be used to track the progress of the operation.
The promise will resolve after the operation completes or reject if an error is
encountered. Additionally, an extra onPlaying
callback is provided on the Promise
to indicate when the audio file actually begins to play. See the code example below
for a sample.
The SDK will emit call:operation events locally as the operation progresses. The remote endpoint will not receive an event for this operation.
If an error is encountered during the operation and the SDK is unable to replace the original local audio track, then that track will be forcibly ended and an media:trackEnded event will be emitted for it. This will release the microphone and avoid losing access to the track while it is active, allowing the application to resolve the scenario by using the call.replaceTrack API to revert the local audio track.
Promise
:
Promise that resolves when the operation is complete.
// The API returns a promise which will provide feedback about the operation.
client.call.playAudioFile(callId, filePath)
.then(() => {
// Audio file has finished playing; call has reverted to previous audio.
})
.catch(err => {
// An error has occurred during the operation.
})
// The returned promise can optionally provide feedback midway through the
// operation. A chainable `onPlaying` method denotes when the audio file has
// started to play and the Call's audio has been replaced.
client.call.playAudioFile(callId, filePath)
.onPlaying(({ duration }) => {
// Audio file has started playing; call audio is now the file.
// Note: Calling `onPlaying` must be done before `then` and `catch` for it
// to be chainable.
})
.then(() => { ... })
.catch(err => { ... })
Performs a "direct" transfer on a call (also known as an unannounced or blind transfer). This allows the current user to transfer the remote participant of a call to another user, similar to a "forward" operation.
The specified call must be locally held. After the operation, this call will be ended, as indicated by a call:stateChange event.
The "destination" user will receive an incoming call, and when answered, they will be connected with the remote participant of the specified call.
The progression of the operation will be tracked via the call:operation event. The remote participant being transferred will receive it as if it were a "remote unhold" operation.
Name | Description |
---|---|
callId string
|
ID of the call being acted on. |
destination (call.SIP_URI | call.TEL_URI)
|
The destination to transfer the call to. |
Performs a "consultative" transfer between two ongoing calls (also known as an announced or warm transfer). This allows the current user to transfer the remote participant of a call to another user, after having spoken to both users.
Both calls used for the transfer must be locally held. After the operation, these calls will be ended, as indicated by a call:stateChange event.
Both remote participants will see their call be unheld by the operation, as indicated by a call:stateChange event, and will be connected to one another afterwards.
The progression of the operation will be tracked via the call:operation event. Both local calls will receive this event, since it is an operation on both calls, and the remote calls will receive it as if it were a "remote unhold" operation.
Performs a "join" on two ongoing calls. This allows the current user to establish a call with audio with two remote users.
Both specified calls must be locally held. The new, "joined" call will be audio-only, even if either previous call had video. Video cannot be added to the "joined" call. Both remote participants will see their call taken off hold, and will receive additional audio from other participants after the operation. Both previous calls for the current user will be ended after the operation, as indicated by a call:stateChange event.
If the first call specified has custom parameters set, these parameters will be carried over to the new call.
The progress of the operation will be tracked via the call:operation event. Both remote participants will also receive this event as if it were a "remote unhold" operation.
Retrieves the information of all calls made during the current session.
Array<call.CallObject>
:
Call objects.
let calls = client.call.getAll()
let currentCalls = calls.filter(call => {
return call.state === client.call.states.CONNECTED
})
Retrieves the information of a single call with a specific call ID.
Name | Description |
---|---|
callId string
|
The ID of the call to retrieve. |
call.CallObject
:
A call object.
Sends the "ringing feedback" notification to the remote participant of a call.
When using the 'manual' ringingFeedbackMode
configuration, the application
is responsible for transitioning the call into the Ringing
state. This
API will notify both ends of the call to enter Ringing
state at the same
time. The application may decide not to send the "ringing feedback"
notification by not using this API. The ringingFeedbackMode
configuration
must be set to 'manual' to use this API.
The specified call must be an incoming call in Initiated
state. The call
will enter Ringing
state as a result of the operation.
The SDK will emit a call:stateChange event locally when the operation completes. The remote participant will be notified of the operation through a call:stateChange event as well.
Name | Description |
---|---|
callId string
|
The ID of the call. |
Set the Custom Parameters of a Call, to be provided to the remote endpoint.
The specified parameters will be saved as part of the call's information throughout the duration of the call. All subsequent call operations will include these custom parameters. Therefore, invalid parameters, or parameters not previously configured on the server, will cause subsequent call operations to fail.
A Call's custom parameters are a property of the Call's CallObject, which can be retrieved using the call.getById or call.getAll APIs.
The custom parameters set on a call can be sent directly with the call.sendCustomParameters API.
Custom parameters can be removed from a call's information by setting them as undefined (e.g., call.setCustomParameters(callId)
).
Subsequent call operations will no longer send custom parameters.
Name | Description |
---|---|
callId string
|
The ID of the call. |
customParameters Array<call.CustomParameter>
|
The custom parameters to set. |
Send the custom parameters on an ongoing call to the server. The server may either consume the headers or relay them to another endpoint, depending on how the server is configured.
A Call's custom parameters are a property of the Call's CallObject, which can be retrieved using the call.getById or call.getAll APIs.
Before sending custom parameters, they need to be first set on the existing Call. To set, change or remove the custom parameters on a call, use the call.setCustomParameters API.
Name | Description |
---|---|
callId string
|
The ID of the call being acted on. |
Send DTMF tones to a call's audio.
The provided tone can either be a single DTMF tone (eg. '1') or a sequence of DTMF tones (eg. '123') which will be played one after the other.
The specified call must be either in Connected, Ringing, or Early Media state, otherwise invoking this API will have no effect.
The tones will be sent as out-of-band tones if supported by the call, otherwise they will be added in-band to the call's audio.
The progress of the operation will be tracked via the call:operation event.
Name | Description |
---|---|
callId string
|
ID of the call being acted on. |
tone string
|
DTMF tone(s) to send. Valid characters are ['0','1','2','3','4','5','6','7','8','9','#','*' and ',']. |
duration number
(default 100 )
|
The amount of time, in milliseconds, that each DTMF tone should last. |
intertoneGap number
(default 70 )
|
The length of time, in milliseconds, to wait between tones. |
Retrieve a snapshot of the low-level information of the Call through statistical report.
The data retrieved is a RTCStatsReport object, which contains many individual RTCStats. These are advanced statistics gathered by the browser providing insights into the Call at a certain point in time. Aggregating reports over a period of time would allow a low-level analysis of the Call for that period. As an example, this could be done to determine the media quality during the Call.
A Track ID can optionally be provided to get a report for a specific local Track of the Call.
This API will return a promise which, when resolved, will contain the report of the particular call. The progress of the operation will be tracked via the call:operation event.
The SDK will emit a call:statsReceived event, after the operation completes, that has the report.
Promise
:
A promise that will resolve with the stats report or an error if it fails.
// Get a snapshot of the Call's stats.
// This may be done on a regular interval to collect data over time.
try {
// The API will return a promise that resolves with the stats.
const result = await client.call.getStats(callId)
result.forEach(stats => {
// Handle the data on its own or collate with previously gathered stats
// for analysis.
...
})
} catch (err) {
// Handle the error.
const { code, message } = err
...
}
Retrieve the list of available and supported codecs based on the browser's capabilities for sending media.
This API will return a promise which, when resolved, it will contain the list of available and supported codecs. In addition, the SDK emits a call:availableCodecs event upon retrieving that list of codecs.
This API is a wrapper for the static method RTCRtpSender.getCapabilities().
Name | Description |
---|---|
kind string
|
The kind of media, i.e., 'audio' or 'video', to get the list of available codecs of. |
Promise
:
A promise that will resolve with an object containing the available codecs, along with the
kind
parameter, that was supplied in the first place.
If there was an error, it will return undefined.
try {
// The API will return a promise that resolves with the codecs.
const result = await client.call.getAvailableCodecs('audio')
result.forEach(codec => {
// Inspect the codec supported by browser by looking at its properties.
...
})
} catch (err) {
// Handle the error.
const { code, message } = err
...
}
Retrieve the call metrics report for a call.
The object returned from this API will be in JSON format. The top level object is the report and will include a timeline of events that were recorded during a call as well as a map object containing computed metrics.
Any event in a timeline will have it's own timeline that may have recorded events. Events in a timeline are scoped to that timelines event or report.
The report and some events may have additional data included in a data property.
See event documentation here. See metrics documentation here.
Name | Description |
---|---|
callId string
|
The id of the call to retrieve the report on. |
Object
:
An object containing all metrics and data tracked against this call.
Set SDP Handler Functions that will be run as part of a pipeline for all future calls. This will replace any SDP Handlers that were previously set.
SDP handlers can be used to make modifications to the SDP (e.g., removing certain codecs) before they are processed or sent to the other side.
This is an advanced feature, changing the SDP handlers mid-call may cause unexpected behaviour in future call operations for that call.
Name | Description |
---|---|
sdpHandlers Array<call.SdpHandlerFunction>
|
The list of SDP handler functions to modify SDP. |
Possible states that a Call can be in.
A Call's state describes the current status of the Call. An application should use the state to understand how the Call, and any media associated with the Call, should be handled. Which state the Call is in defines how it can be interacted with, as certain operations can only be performed while in specific states, and tells an application whether the Call currently has media flowing between users. Unless stated otherwise, the Call's state pertains to both caller & callee.
The Call's state is a property of the CallObject, which can be retrieved using the call.getById or call.getAll APIs.
The SDK emits a call:stateChange event when a Call's state changes from one state to another.
Type: Object
(string)
: The (outgoing) call is being started. While in this state, no Call operations can be performed until Call gets into Initiated state.
(string)
: A call has been started and both the callee and caller may now perform further operations on the call object.
(string)
: The call has been received by both parties, and is waiting to be answered.
(string)
: The call has not been answered, but media
is already being received. This may be network-ringing media, IVR
system media, or other pre-answer medias. When early media is
supported, this state may replace the Ringing state. This is a state valid only for caller's side.
(string)
: The call was disconnected before it could be answered. This is a state valid only for callee's side.
(string)
: Both parties are connected and media is flowing.
(string)
: Both parties are connected but no media is flowing.
(string)
: The call has ended.
// Use the call states to know how to handle a change in the call.
client.on('call:stateChange', function (params) {
const call = client.call.getById(params.callId)
// Check if the call now has media flowing.
if (call.state === client.call.states.CONNECTED) {
// The call is now active, and can perform midcall operations.
}
})
Possible states that a Call's media connection can be in.
A Call's media connection state describes the current status of media within the call. An application should use this state to understand whether the Call participants are able to see/hear each other or may be experiencing connection issues. The media connection state can be used alongside the Call state to determine if media issues are occurring while the participants are expecting to be connected.
An important state to check for is the FAILED
state. This state signifies that there is no
media connection between the call participants and an action must be taken to resolve the
problem. Using the call.restartMedia API will attempt to reconnect the media. See
the call.restartMedia API description for more information.
These states are direct reflections of the possible RTCPeerConnection.iceConnectionState values.
The Call's media connection state is a property of the CallObject, which can be retrieved using the call.getById or call.getAll APIs.
The SDK emits a call:mediaConnectionChange event when a Call's media connection state changes from one state to another.
Type: Object
(string)
: The Call is initializing the local side of the connection and waiting on information from the remote side.
When the information is received, the state will transition into
checking
as the Call automatically begins the connection process.
(string)
: The Call has received information from the remote endpoint and is working to establish the media connection.
When finished, the state will transition to either
connected
or
failed
.
(string)
: A usable connection has been made and the Call will now have media.
The connection may not be optimal, though, so the Call will continue establishment to improve the connection before going into the
completed
state.
(string)
: The media connection process has fully completed and the optimal connection has been established. While in this state,
the Call endpoints will receive each other's media.
(string)
: Media has become disconnected and the Call endpoints have stopped receiving each other's media.
The Call will automatically attempt to reconnect, transitioning back to
completed
if successful or to
failed
if not.
(string)
: The connection has failed and cannot be recovered automatically. A full media connection refresh is required to reestablish a connection. See the
call.restartMedia
API.
(string)
: The connection has been shut down and is no longer in use.
// Use the media connection states to check the status of the media connection of the Call.
client.on('call:mediaConnectionChange', function (params) {
// Retrieve the state of the Call this event is for.
const call = client.call.getById(params.callId)
const mediaConnectionStates = client.call.mediaConnectionStates
// Check the mediaConnectionState to determine which scenario the call is in.
switch (call.mediaConnectionState) {
case mediaConnectionStates.CONNECTED:
case mediaConnectionStates.COMPLETED:
// Media established: The Call's media is connected. The Call's participants
// are able to see/hear each other.
// These states will occur after Call establishment.
...
break
case mediaConnectionStates.NEW:
case mediaConnectionStates.CHECKING:
case mediaConnectionStates.DISCONNECTED:
// Media pending: The Call's media is not connected. The Call is working
// to connect media automatically.
// These states will occur during Call establishment and may occur midcall if there are
// connection issues (eg. poor network quality) or a Call participant has changed (eg. transfer).
...
break
case mediaConnectionStates.FAILED:
// Media has failed. The call requires a media refresh to reestablish.
// This state will occur after the `DISCONNECTED` state is encountered.
...
break
case mediaConnectionStates.CLOSED:
// Media ended due to the Call being ended.
// This state will occur after Call establishment.
...
break
}
}
Events used in the SDK's call reports.
As a call progresses, the operation(s)/function(s) being performed throughout the duration of a call are recorded as events in a call report. The call report can be retrieved via the call.getReport API. An application can use these event names to find the associated event(s) in the call report for more information on the event. See Call Reports tutorial for more information on call reports and events.
Type: Object
(string)
: Starts when the make operation starts. Ends when the make operation finishes.
(string)
: Starts when the send ringing feedback operation starts. Ends when the ringing feedback operation finishes.
(string)
: Starts when the SDK receives a call and ends when the incoming call is setup.
(string)
(string)
: Starts when the answer operation starts. Ends when the answer operation finishes.
(string)
: Starts when user media is requested from the browser and ends when the media is created.
(string)
: Starts when the local media begins processing, and ends when the offer is set and ice collection completes.
(string)
: Starts when the remote response is received, and ends when the remote media is set.
(string)
: Starts when ice candidate collection starts and ends when collection is complete.
(string)
: Starts and ends when a relay candidate is collected. Event data contains info on the candidate.
(string)
: Starts when the ignore operation starts. Ends when the ignore operation finishes.
(string)
: Starts when the reject operation starts. Ends when the reject operation finishes.
(string)
: Starts when the forward call operation starts. Ends when the forward operation finishes.
(string)
: Starts when the end operation starts. Ends when the end operation finishes.
(string)
: Starts when the call status update ended operation starts. Ends when the call status update ended operation finishes.
(string)
: Starts when the add basic media operation starts. Ends when the add basic media operation finishes.
(string)
: Starts when the add media operation starts. Ends when the add media operation finishes.
(string)
: Starts when a remote add media notification is received and ends when the operation is handled.
(string)
: Starts when the remove basic media operation starts. Ends when the remove basic operation finishes.
(string)
: Starts when the remove media operation starts. Ends when the remove media operation finishes.
(string)
: Starts when a remote remove media notification is received and ends when the operation is handled.
(string)
: Starts when the media restart operation starts. Ends when the media restart operation finishes.
(string)
: Starts when the replace track operation starts. Ends when the replace track operation finishes.
(string)
: Starts when the hold operation starts. Ends when the hold operation finishes.
(string)
: Starts when a remote hold notification is received and ends when the operation is handled.
(string)
: Starts when the unhold operation starts. Ends when the unhold operation finishes.
(string)
: Starts when a remote unhold notification is received and ends when the operation is handled.
(string)
: Starts when a REST request is to be made for an operation and ends when a response is received, or it times out.
(string)
: Starts when the play audio operation starts. Ends when the play audio operation finishes.
(string)
: Starts when the start music on hold operation starts. Ends when the start music on hold operation finishes.
(string)
: Starts when the stop music on hold operation starts. Ends when the stop music on hold operation finishes.
(string)
: Starts when the send custom parameters operation starts. Ends send custom parameters operation finishes.
(string)
: Starts when the get stats operation starts. Ends when the get stats operation finishes.
(string)
: Starts when the send DTMF operation starts. Ends when the DTMF operation finishes.
(string)
: Starts when the resync operation starts. Ends when the resync operation finishes.
(string)
: Starts when the direct transfer operation starts. Ends when the direct transfer operation finishes.
(string)
: Starts when the consultative transfer operation starts. Ends when the consultative transfer operation finishes.
(string)
: Starts when the join operation starts. Ends when the join operation finishes.
(string)
: Starts when the get available codecs operation starts. Ends when the get available codecs operation finishes.
(string)
: Starts when the slow start operation starts. Ends when the slow stop operation finishes.
const report = client.call.getReport('callId')
const getAvailableCodecsEvent = report.timeline.find(event => event.type === client.call.reportEvents.GET_AVAILABLE_CODECS)
log(`Took ${getAvailableCodecsEvent.end - getAvailableCodecsEvent.start}ms to get available codecs.`)
List of metrics available as part of a Call Report. Metrics are calculated only for the successful scenarios.
As a call progresses, timings are calculated for the duration of operations and other events. They are recorded in a call report that can be retrieved via the call.getReport API.
Type: Object
(string)
: The duration of a completed call starting from the make call API call or incoming call notification until the call ends.
(string)
: The amount of time it takes from when the
make call
operation starts up until right before we set local description.
(string)
: The amount of time it takes from when a call is made until the call is setup locally. This does not include any remote session creation.
(string)
: The amount of time it takes from when the create session request is sent until the SDK processes the response.
(string)
: The amount of time it takes from when the
answer call
operation starts until it is setup locally.
(i.e. from the time an incoming call is answered until media is connected)
(string)
: The amount of time it takes from when the
answer call
operation starts up until right before we set local description.
(string)
: For incoming calls, the time from the call first being received until it has been answered. Includes call processing and setup, as well as time for the answer API to have been called.
(string)
: For incoming calls, the time from the call first being received until media is connected. Similar to
TIME_FROM_RECEIVE_TO_ANSWER
, but without the
answer
REST request.
(string)
: The amount of time it takes from when a call is made until the SDK recieves the remote ringing notification.
(string)
: The amount of time it takes for the ignore call to complete.
(string)
: The amount of time it takes for the reject call to complete.
(string)
: The amount of time it takes from when the local
add media
operation starts until it has finished.
(string)
: The amount of time it takes from when the SDK receives a remote
add media
notification until it is handled and operation completes.
(string)
: The amount of time it takes from when the local
remove media
operation starts until it has finished.
(string)
: The amount of time it takes from when the SDK receives a remote
remove media
notification until it is handled and operation completes.
(string)
: The amount of time it takes from when the
restart media
operation starts until it has finished.
(string)
: The amount of time it takes from when the local
hold
operation starts until it has finished.
(string)
: The amount of time it takes from when the SDK receives a remote
hold
notification until it is handled and operation completes.
(string)
: The amount of time it takes from when the local
unhold
operation starts until it has finished.
(string)
: The amount of time it takes from when the SDK receives a remote
unhold
notification until it is handled and operation completes.
(string)
: The amount of time it takes from when the local description is set to when all ICE candidates have been collected.
(string)
: The amount of time it takes from when the
ice collection
operation starts until each relay candidate has been recieved.
(string)
: The amount of time it takes from when the
send custom parameters
operation starts until it has finished.
(string)
: The amount of time it takes from when the
forward call
operation starts until it has finished.
(string)
: The amount of time it takes from when the
direct transfer
operation starts until it has finished.
(string)
: The amount of time it takes from when the
consultative transfer
operation starts until it has finished.
(string)
: The amount of time it takes from when the
join call
operation starts until it has finished.
const report = client.call.getReport(callId)
const callDuration = report.metrics.find(metric => metric.type === client.call.metrics.CALL_DURATION)
log(`Call duration was ${callDuration.data}ms.`)
A call operation has either started, been updated, or finished.
Information about ongoing call operations are stored on the CallObject. This event indicates that an operation's information has changed.
The status of an operation indicates whether the local or remote side of the call is currently processing it, with values being 'ONGOING' or 'PENDING', respectively. All operations will begin as 'ONGOING' status with an event indicating the 'START' transition. Operations that require a response from the remote side will have an 'UPDATE' transition to the 'PENDING' status once it starts to wait for the response. Once complete, an event will indicate a 'FINISH' transition and the operation will be removed from the call state.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID for the call being operated on. |
params.operation string
|
The type of operation causing this event. |
params.operationId string
|
The unique ID of the call operation. |
params.transition string
|
The transition reason for the operation change. |
params.isLocal boolean
|
Flag indicating whether the operation was local or not. |
params.previous Object?
|
The operation information before this change. If the transition is to "start" the operation, there will be no previous information. |
params.previous.operation string?
|
The operation that was ongoing. |
params.previous.status string?
|
The operation status before this change. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
client.on('call:operation', (params) => {
const { callId, operationId } = params
// Get the operation from the call's state that this event is about.
const call = client.call.getById(callId)
const operation = call.currentOperations.find(op => op.id === operationId)
log(`${operation.type} operation is now ${operation.status} for call ${callId}.`)
})
An outgoing call has been started.
Information about the Call can be retrieved using the call.getById API.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the call. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
A new joined call has been started.
Information about the Call can be retrieved using the call.getById API.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the call. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
A new incoming call has been received.
Information about the Call can be retrieved using the call.getById API.
NOTE: Upon receiving this notification the call is in "Initiating" state. In order to answer calls, they must be in either "Ringing" or "Initiated" states. Therefore, this event should not be used to prompt the user to respond. Instead, the call:stateChange event should be used for this purpose.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the call. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
client.on('call:receive', function(params) {
// We have received a call
promptUser(client.call.getById(params.callId));
});
A Call's state has changed.
See call.states for information about call states.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the Media object that was operated on. |
params.previous Object
|
The call's properties before the operation changed it. |
params.previous.state string
|
The previous state of the call. |
params.previous.localHold boolean?
|
The previous local hold state. Present when the state change was a hold/unhold operation. |
params.previous.remoteHold boolean?
|
The previous remote hold state. Present when the state change was a hold/unhold operation. |
params.transition Object?
|
Contains more detailed information about the state change. |
params.transition.statusCode number?
|
The status code associated with the particular state change's reason. |
params.transition.reasonText string?
|
The reason for the state change. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
client.on('call:stateChange', function (params) {
const call = client.call.getById(params.callId)
const prevState = params.previous.state
log(`Call changed from ${prevState} to ${call.state} state.`)
// Handle the event depending on the new call state.
switch (call.state) {
case client.call.states.CONNECTED:
// Handle being on call with media.
break
case client.call.states.ENDED:
// Handle call ending.
break
...
}
})
New media has been added to the call.
Tracks have been added to the Call after an SDK operation. Both sides of the Call are now able to render these tracks.
Tracks are added to a Call when either the local or remote user adds new media to the Call, using the call.addMedia API for example, or when the Call is unheld with the call.unhold API.
Remote tracks are similarly added to a Call when new tracks are added by the remote user or either user unholds the call.
This event can indicate that multiple tracks have been removed by the same operation. For example, if the remote user added video to the call, this event would indicate a single, remote video track was added. If the local user unheld the call, this event would indicate that any tracks previously on the call have been re-added, both local and remote.
Information about a Track can be retrieved using the media.getTrackById API.
client.on('call:tracksAdded', function (params) {
// Get the information for each track.
const tracks = params.trackIds.map(client.media.getTrackById)
tracks.forEach(track => {
const { id, kind, isLocal } = track
// Handle the track depending whether it is audio vs. video and local vs. remote.
...
})
})
Tracks have been removed from the Call after an SDK operation. The tracks may still exist, but the media is not available to both sides of the Call any longer.
Tracks are removed from a Call when either the local or remote user stops the tracks, by using the call.removeMedia API for example, or when the Call is held with the call.hold API.
This event can indicate that multiple tracks have been removed by the same operation. For example, if the remote user removed video from the call, this event would indicate a single, remote video track was removed. If the local user held the call, this event would indicate that all tracks on the call have been removed, both local and remote.
Information about a Track can be retrieved using the media.getTrackById API.
client.on('call:tracksRemoved', function (params) {
// Get the information for each track.
const tracks = params.trackIds.map(client.media.getTrackById)
tracks.forEach(track => {
const { id, kind, isLocal } = track
// Handle the track depending whether it is audio vs. video and local vs. remote.
...
})
})
Stats have been retrieved for a Call or specific Track of a Call.
See the call.getStats API for more information.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the Call to retrieve stats for. |
params.trackId string?
|
The ID of the Track to retrieve stats for. |
params.result Map?
|
The RTCStatsReport. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
client.on('call:statsReceived', function (params) {
if (params.error) {
// Handle the error from the operation.
const { code, message } = params.error
...
} else {
// Iterate over each individual statistic inside the RTCPStatsReport Map.
// Handle the data on its own or collate with previously gathered stats
// for analysis.
params.result.forEach(stat => {
...
})
}
})
A local Track has been replaced by the call.replaceTrack API.
This event is a combination of a track being removed from the Call and a new track being added to the Call. The previous Track's media is no longer available, similar to the call:tracksRemoved event, and the new Track is available in its place, similar to the call:tracksAdded event. The event includes information about the Track that was replaced to help an application replace it seamlessly.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the call where a track was replaced. |
params.newTrackId string?
|
The ID of the new track that replaced the old track. |
params.oldTrack call.TrackObject?
|
State of the replaced track. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
client.on('call:trackReplaced', function (params) {
const { callId, oldTrack, newTrackId } = params
// Unrender the removed track.
handleTrackGone(oldTrack, callId)
// Render the added track.
const track = client.media.getTrackById(newTrackId)
handleTrackAdded(track, callId)
})
Custom Parameters have been received for a Call.
These are parameters set by the remote endpoint of the Call. Please refer to CustomParameter for more information.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the Call in which custom parameters were received. |
params.customParameters Array<call.CustomParameter>
|
The custom parameters received. |
The list of available and supported codecs by the browser have been retrieved.
This event is emitted as a result of the call.getAvailableCodecs API. Please refer to the API for more information.
client.on('call:availableCodecs', function (codecs) {
// Iterate over each codec.
codecs.forEach(codec => {
// Handle the data by analysing its properties.
// Some codec instances may have the same name, but different characteristics.
// (i.e. for a given audio codec, the number of suported channels may differ (e.g. mono versus stereo))
...
})
})
A Call's media connection state has been changed.
This event is emitted as a result of changes to the media connection of the Call. These state changes occur during call establishment, connection loss/re-establishment, call completion, etc.
To check the media connection state of a call, retrieve the call's information using the call.getById API,
and check the mediaConnectionState
property of the call.
See call.mediaConnectionStates for the list of possible values and descriptions.
A media restart operation for a Call has been attempted.
This event is emitted as a result of the call.restartMedia API being called. See the description for call.restartMedia for information about its usage.
The call:mediaConnectionChange event will also be emitted alongside this event when the media restart operation is successful.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
The ID of the Call that was acted on. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
client.on('call:mediaRestart', function (params) {
if (params.error) {
// The operation failed. May want to determine whether to re-attempt the
// operation (if the failure was simply a connectivity issue) or to
// consider the call's media irrecoverable.
...
} else {
// The call should be re-establishing media, with the call's
// `mediaConnectionState` being updated.
const mediaState = client.call.getById(params.callId).mediaConnectionState
...
}
})
The 'call.history' namespace is used to retrieve and inspect the authenticated users call logs.
Functions below are all part of this namespace.
Gets the list of call logs cached locally. The event
callHistory:changed
is used to indicate the local state of logs
has been updated.
Array
:
A list of call log records, ordered by latest first.
client.on('callHistory:change', function() {
// Get all call logs when they've been updated.
let callLogs = client.call.history.get();
});
Fetches the list of call logs and stores them locally. The API CallHistory.get can then be used to get the logs from local state after it has been updated.
Deletes all call logs.
Gets the cached call history data and returns stringified data.
The data is provided in a format that can be used directly with the call.history.setCache API. This allows an application to persist the information across SDK instances when the backend environment does not support the CallHistory feature.
string
:
A stringified list of call log records from the cache, ordered by latest first.
Sets the cached call history data, expects stringified data as it will be parsed.
The data can be retrieved from the call.history.getCache API. This allows an application to persist the information across SDK instances when the backend environment does not support the CallHistory feature.
Name | Description |
---|---|
data string
|
The stringified call history data to store in the cache. |
Call history state has been updated. See CallHistory.get to retrieve new state.
An error occurred while performing a call history operation.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |
Call history cached state has been updated
The clickToCall namespace is used to bridge a call between two specified devices
ClickToCall had an error.
Name | Description |
---|---|
params Object
|
|
params.callId string
|
A unique id representing the call made |
params.error api.BasicError
|
The Basic error object. |
The 'connection' namespace is used to connect and maintain connections between the SDK and one or more backend servers.
Information about a websocket connection.
Can be retrieved using the connection.getSocketState API.
Type: Object
(boolean)
: The state of the websocket connection.
(boolean)
: True if the client has sent a ping to the server and is still waiting for a pong response.
(number)
: How often the client will ping the server to test for websocket connectivity.
(number)
: How many times the SDK will try to reconnect a disconnected websocket.
(number)
: How long the SDK will wait before retrying websocket reconnection.
(number)
: Reconnect delay multiplier for subsequent attempts. The reconnect delay time will be multiplied by this after each failed reconnect attempt to increase the delay between attempts. eg. 5000ms then 10000ms then 20000ms delay if value is 2.
(number)
: Maximum time delay between reconnect attempts (milliseconds). Used in conjunction with
reconnectTimeMultiplier
to prevent overly long delays between reconnection attempts.
(boolean)
: Indicates if the SDK should automatically try reconnecting a disconnected websocket.
(string)
: The mode used for authenticating with the server.
(Object)
: Information required to connect a websocket to the server.
wsInfo.protocol
string?
The protocol to use to connect a websocket.
wsInfo.server
string?
The domain name or IP address of the server to connect to.
wsInfo.port
number?
The port of the server to connect to.
wsInfo.url
string?
The URL path to use to request a websocket connection.
wsInfo.params
string?
Any additional params that might be required by the server to establish the websocket connection.
Get the state of the websocket.
connection.WSConnectionObject
:
Details about the current websocket connection, including state and configuration.
Enables or disables connectivity checking.
This API will change the connectivity.checkConnectivity
configuration set during SDK initialization. If there
was a connected websocket while it is changed, the change will take affect immediately.
Name | Description |
---|---|
enable boolean
|
Whether the websocket should be pinging to check for connectivity issues or not. |
Resets the connected websocket by manually disconnecting then reconnecting.
This API will simulate the SDK receiving a websocket disconnect from the browser, which will trigger its recovery functionality. This API can be used if the application is aware of a network issue before the SDK is notified by the browser.
If there is no websocket connected, this API has no effect. If the SDK is not configured
to autoreconnect (see connectivity.autoReconnect
configuration property), then this
API will not attempt to reconnect the websocket automatically.
The normal websocket and lifecycle events will be emitted during this operation, notably the ws:change event.
The WebSocket to the server has changed state.
This event is only emitted when the WebSocket is connected, or has lost connection.
The 'contacts' namespace allows users to store personal contacts to their account.
Add a contact to a user's personal address book.
Will trigger the contacts:new
event.
Name | Description |
---|---|
contact Object
|
The contact object. |
contact.primaryContact string
|
The primary userId for the contact |
contact.contactId string
|
The contact's unique contact ID |
contact.firstName string?
|
The contact's first name |
contact.lastName string?
|
The contact's last name |
contact.photoUrl string?
|
The URL address identifying location of user's picture |
contact.emailAddress string?
|
The contact's email address |
contact.homePhone string?
|
The contact's home phone number |
contact.workPhone string?
|
The contact's business phone number |
contact.mobilePhone string?
|
The contact's mobile phone number |
contact.conferenceURL string?
|
Conference URL and access code for this user's address book entry |
contact.fax string?
|
The user's fax number |
contact.pager string?
|
The user's pager number |
contact.groupList string?
|
The name of the contact list for which to add this contact to ("friends" by default) |
contact.friendStatus boolean?
|
Indicates whether or not the contact is a friend of the user |
Refreshes the local information about contacts. This will get new contacts from the platform.
Will trigger the contacts:change
event.
Update a contact from the user's personal address book.
Will trigger the contacts:change
event.
Name | Description |
---|---|
contact Object
|
The contact object. |
contact.primaryContact string
|
The primary userId for the contact |
contact.contactId string
|
The contact's unique contact ID |
contact.firstName string?
|
The contact's first name |
contact.lastName string?
|
The contact's last name |
contact.photoUrl string?
|
The URL address identifying location of user's picture |
contact.emailAddress string?
|
The contact's email address |
contact.homePhone string?
|
The contact's home phone number |
contact.workPhone string?
|
The contact's business phone number |
contact.mobilePhone string?
|
The contact's mobile phone number |
contact.conferenceURL string?
|
Conference URL and access code for this user's address book entry |
contact.fax string?
|
The user's fax number |
contact.pager string?
|
The user's pager number |
contact.groupList string?
|
The name of the contact list for which to add this contact to ("friends" by default) |
contact.friendStatus boolean?
|
Indicates whether or not the contact is a friend of the user |
A new contact has been added to the address book.
Name | Description |
---|---|
contact Object
|
The new contact. |
The contacts list has changed.
client.on('contacts:change', function () {
// Get the updated list of contacts.
const contacts = client.contacts.getAll()
...
})
The messaging feature revolves around a 'conversation' namespace. It is responsible to store the conversations and its messages, and return conversation objects when requested.
See the "Conversation" and "Message" sections of the documentation for more details.
Messaging functions are all part of the 'conversation' namespace. Ex: client.conversation.get('id').
A Conversation object represents a conversation between two users. A Conversation can create messages via the conversation's createMessage() function.
Type: Object
(string)
: The id of the remote user with which the current user is having a conversation.
Create and return a message object. You must provide a text
part as demonstrated in the example.
conversation.Message
:
The newly created Message object.
conversation.createMessage({type: 'text', text: 'This is the message'});
Clears all messages in this conversation from local state.
Get the messages associated with this conversation.
Function
:
messages.markRead Marks the message as read.
Function
:
messages.forward Forward the message to another user.
string
:
messages.messageId The Id of the message.
string
:
messages.sender The user Id of the user who sent the message.
number
:
messages.timestamp The time at which the message was sent.
boolean
:
messages.read Whether the message has been marked as read.
boolean
:
messages.isPending Whether the message has finished being sent to the server.
Array
:
messages.parts The parts of the message.
A Message object is a means by which a sender can deliver information to a recipient.
Creating and sending a message:
A message object can be obtained through the Conversation.createMessage API on an existing conversation.
Messages have Parts which represent pieces of a message. Currently, only a 'text' part is suported. Once all the desired parts have been added to the message using the Message.addPart function, the message can then be sent using the Message.send function.
Once the sender sends a message, this message is saved in sender's state as an object. Similarly, once the recipient gets a message, this message is saved in recipient's state.
Retrieving a delivered message:
Once a message is delivered successfully, it can be obtained through the Conversation.getMessages or Conversation.getMessage API on an existing conversation.
Below are the properties pertaining to the message object, returned by Conversation.getMessage(s) APIs, for either sender or recipient.
Type: Object
(number)
: A Unix timestamp in seconds marking the time when the message was created by sender.
(Array<conversation.Part>)
: An array of Part Objects.
(string)
: The primary contact address of the sender.
(Array<string>)
: An array of primary contact addresses associated with various destinations to which the message is meant to be delivered. Currently, only one destination is supported.
(string)
: The unique id of the message. The message object (stored in sender's state) has a different id
than the one associated with the message object stored in recipient's state.
(string)
: The type of message that was sent. See
conversation.chatTypes
for valid types.
This property applies only to message objects stored in sender's state.
Sends the message.
Get a conversation object matching the user ID provided in the 'destination' parameter. If successful, the event 'conversations:change' will be emitted.
This API will retrieve a conversation already existing in the store.
Name | Description |
---|---|
destination string
|
The destination for messages created in this conversation. This will be a user's sip address. |
options Object?
|
An optional configuration object to query for more specific results. If this object is not passed, the function will query for "im" conversation with that recipient. |
options.type string?
|
The type of conversation to retrieve. Can be one of "im", "sms" or "other". |
conversation.Conversation
:
A Conversation object matching the passed destination, otherwise undefined is returned.
Returns all conversations currently tracked by the SDK
Array<conversation.Conversation>
:
An array of conversation objects.
A new conversation has been created and added to the state.
A change has occurred in the conversation list.
A change has occurred in a specific conversations message list.
If a single message was affected/created, messageId
will be present
as part of the event argument.
Name | Description |
---|---|
params Object
|
|
params.destination string
|
The destination for messages created in this conversation. |
params.type string
|
The type of conversation to create. Can be one of "chat", "im", "sms". |
params.messageId string?
|
The ID of the message affected. |
params.sender string?
|
The username of the sender of the message which caused the
messages:change
event to be triggered.
|
An error occurred with messaging.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |
The SDK has an internal logging system for providing information about its behaviour. The SDK will generate logs, at different levels for different types of information, which are routed to a "Log Handler" for consumption. An application can provide their own Log Handler (see config.logs) to customize how the logs are handled, or allow the default Log Handler to print the logs to the console.
The SDK's default Log Handler is merely a thin wrapper around the browser's
console API (ie. window.console
). It receives the log generated by the
SDK, called a "Log Entry", formats a
human-readable message with it, then uses the console to log it at the
appropriate level. This is important to be aware of, since your browser's
console may affect how you see the SDK's default log messages. Since the
default Log Handler uses the console's levels, the browser may filter
which messages are shown depending on which levels it has configured. For
a user that understands console log levels, this can be helpful for
filtering the logs to only the relevant information. But it can equally
be a hindrance by hiding the more detailed log messages (at the 'debug'
level), since browser can have this level hidden by default. For this
reason, we recommend providing a custom Log Handler to the SDK that is
better suited for your application and its users.
A LogEntry object is the data that the SDK compiles when information is logged. It contains both the logged information and meta-info about when and who logged it.
A LogHandler provided to the SDK (see config.logs) will need to handle LogEntry objects.
Type: Object
(number)
: When the log was created, based on UNIX epoch.
(string)
: The log function that was used to create the log.
(string)
: The level of severity the log.
(Object)
: The subject that the log is about.
(Array)
: The logged information, given to the Logger
method as parameters.
(Object?)
: Timing data, if the log method was a timer method.
function defaultLogHandler (logEntry) {
// Compile the meta info of the log for a prefix.
const { timestamp, level, target } = logEntry
let { method } = logEntry
const logInfo = `${timestamp} - ${target.type} - ${level}`
// Assume that the first message parameter is a string.
const [log, ...extra] = logEntry.messages
// For the timer methods, don't actually use the console methods.
// The Logger already did the timing, so simply log out the info.
if (['time', 'timeLog', 'timeEnd'].includes(method)) {
method = 'debug'
}
console[method](`${logInfo} - ${log}`, ...extra)
}
A LogHandler can be used to customize how the SDK should log information. By default, the SDK will log information to the console, but a LogHandler can be configured to change this behaviour.
A LogHandler can be provided to the SDK as part of its configuration (see config.logs). The SDK will then provide this function with the logged information.
Type: Function
Name | Description |
---|---|
LogEntry Object
|
The LogEntry to be logged. |
// Define a custom function to handle logs.
function logHandler (logEntry) {
// Compile the meta info of the log for a prefix.
const { timestamp, level, target } = logEntry
let { method } = logEntry
const logInfo = `${timestamp} - ${target.type} - ${level}`
// Assume that the first message parameter is a string.
const [log, ...extra] = logEntry.messages
// For the timer methods, don't actually use the console methods.
// The Logger already did the timing, so simply log out the info.
if (['time', 'timeLog', 'timeEnd'].includes(method)) {
method = 'debug'
}
console[method](`${logInfo} - ${log}`, ...extra)
}
// Provide the LogHandler as part of the SDK configurations.
const configs = { ... }
configs.logs.handler = logHandler
const client = create(configs)
Possible levels for the SDK logger.
The SDK will provide Log Entries to the Log Handler for all logs at or above the set log level. 'debug' is considered the lowest level and 'silent' the highest level. For example, if the current level is 'info', then the Log Handler will receive Log Entries for logs at 'info', 'warn', and 'error', but not for the 'debug' level.
(string)
: Nothing will be logged.
(string)
: Unhandled error information will be logged. If
the SDK encounters an issue it cannot resolve, the error will be included
in the logs. This likely points to an issue with the SDK itself or an
issue with how the SDK is being used.
(string)
: Warning messages for the application developer will
be logged. If the SDK encounters an issue that it can recover and continue,
a warning about the issue will be included in the logs. These logs point
to issues that need to be handled by the application. For example, providing
an invalid configuration to the SDK will cause a warning log that explains
the issue.
(string)
: General information about the SDK's operations will
be logged, outlining how the SDK is handling the operations. Reading through
these logs should provide a high-level view of what the SDK is doing,
and why it is doing it.
(string)
: Detailed information about the SDK's operations,
meant for debugging issues, will be logged. Specific information and relevant
operation data are provided for understanding the scenario that the SDK
was in during the operation.
The 'media' namespace provides an interface for interacting with Media that the SDK has access to. Media is used in conjunction with the Calls feature to manipulate and render the Tracks sent and received from a Call.
Media and Track objects are not created directly, but are created as part of Call operations. Media and Tracks will either be marked as "local" or "remote" depending on whether their source is the local user's machine or a remote user's machine.
The Media feature also keeps track of media devices that the user's machine can access. Any media device (eg. USB headset) connected to the machine can be used as a source for media. Available devices can be found using the media.getDevices API.
Detached Media is a special type of call.MediaObject that is created outside the scope of a call. A DetachedMedia object is a call.MediaObject that is wrapped with the contained call.TrackObject's media type for convenience.
The APIs for managing detached media are available in the media namespace. They are media.createLocalMedia, media.getLocalMedia, and media.disposeLocalMedia. Unlike media that is created as part of a call, the application is responsible for the lifecycle for a detached media object.
Accessing local media before a call is made can be used to implement a "media preview" feature, allowing an end-user to check their media devices before joining a call.
Detached Media can also be used as part of a call, rather than new media being created as part of the call operations. This can be done as an optimization, to avoid the overhead of creating new media objects during the call setup process. The same Detached Media objects can be used for multiple calls, as well.
Type: Object
(call.MediaObject)
: The media object.
(string)
: The type of the media object ('audio', 'video', or 'screen').
// Create new detached media objects.
const medias = await client.media.createLocalMedia({ audio: true, video: true })
// medias === [ { type: 'audio', media: <call.MediaObject> }, { type: 'video', media: <call.MediaObject> } ]
// where medias[x].type === client.media.getTrackById(medias[x].media.tracks[0].id).type)
// Render the local video as a preview.
client.media.renderTracks([ medias[1].media.tracks[0].id ], '#localVideoPreview')
// Use the Detached Media in a call, instead of creating new media for it.
const call = client.call.make('destination', { audio: false, video: false, medias: medias })
Retrieves the available media devices for use.
The devices:change event will be emitted when the available media devices have changed.
Object
:
The lists of camera, microphone, and speaker devices.
Retrieves an available Media object with a specific Media ID.
Name | Description |
---|---|
mediaId string
|
The ID of the Media to retrieve. |
call.MediaObject
:
A Media object.
Retrieve an available Track object with a specific Track ID.
Name | Description |
---|---|
trackId string
|
The ID of the Track to retrieve. |
call.TrackObject
:
A Track object.
Requests permission to access media devices on the end-user's machine.
This API will trigger the browser to ask the end-user for permission to access their camera and/or microphone. These permissions are needed for the SDK to read information about the devices (the label, for example) and for using the devices for a call.
If the browser does not yet have permission, it will prompt the end-user with a small pop-up window, giving the user a chance to allow/deny the permissions. The behaviour of this pop-up window differs slightly based on the browser; it may automatically save the user's decision (such as in Chrome and Safari) or it may require the user to choose whether their decision should be saved (such as in Firefox).
This API is not required for proper usage of media and/or calls, but helps to prepare a user before a call is made or received. It allows an application to prompt the user for device permissions when it is convenient for them, rather than during call setup. If the user saves their decision, they will not be prompted again when the SDK accesses those devices for a call.
For device information, the media.getDevices API will retrieve the list of media devices available for the SDK to use. If this list is empty, or is missing information, it is likely that the browser does not have permission to access the device's information. We recommend using the media.initializeDevices API in this scenario if you would like to allow the end-user to select which device(s) they would like to use when they make a call, rather than using the system default.
The SDK will emit a devices:change event when the operation is successful or a devices:error event if an error is encountered.
// The SDK will ask for both audio and video permissions by default.
client.media.initializeDevices()
// The SDK will only ask for audio permissions.
client.media.initializeDevices({ audio: true, video: false })
Create local media Tracks.
Name | Description |
---|---|
mediaConstraints Object
|
Collection of constraints for each media type. |
mediaConstraints.audio boolean?
|
Native media constraints for audio. |
mediaConstraints.video boolean?
|
Native media constraints for video. |
mediaConstraints.screen boolean?
|
Native media constraints for display (screen). |
Promise<Array<media.DetachedMedia>>
:
Resolves with an array of objects containing both a media type and a media object.
// Create detached media for your local video
const medias = await client.media.createLocalMedia({ video: true })
Get local media Tracks.
Array<media.DetachedMedia>
:
An array of detached media objects.
await client.media.createLocalMedia({ video: true })
// Get all detached tracks
const medias = client.media.getLocalMedia()
Dispose local media Tracks.
Name | Description |
---|---|
localMedia (media.DetachedMedia | string)
|
An object representing the local media to dispose or a string representing a trackId. |
Render Media Tracks in a container.
The container is specified by providing a CSS selector string that corresponds to the HTMLElement to act as the container.
Name | Description |
---|---|
trackIds Array<string>
|
List of Track IDs to be rendered. |
cssSelector string
|
A CSS selector string that uniquely identifies an element. Ensure that special characters are properly escaped. |
options Object?
|
Additional options for rendering the tracks. |
options.speakerId string?
|
The speaker's Device ID to use for audio tracks. |
// When a Call receives a new track, render it.
client.on('call:tracksAdded', function (params) {
params.trackIds.forEach(trackId => {
const track = client.media.getTrackById(trackId)
const container = track.isLocal ? localContainer : remoteContainer
// Render the Call's new track when it first becomes available.
client.media.renderTracks([ trackId ], container)
}
})
Remove Media Tracks from a container.
The container is specified by providing a CSS selector string that corresponds to the HTMLElement to act as the container.
Mutes the specified Tracks.
This API prevents the media of the specified Tracks from being rendered. Audio Tracks will become silent and video Tracks will be a black frame. This does not stop media from being received by those Tracks. The media simply cannot be used by the application while the Track is muted.
If a local Track being sent in a Call is muted, the Track will be noticeably muted for the remote user. If a remote Track received in a call is muted, the result will only be noticeable locally.
This mute operation acts on those specified Tracks directly. It does not act on the active Call as a whole.
The SDK will emit a media:muted event when a Track has been muted.
Unmutes the specified Tracks.
Media will resume its normal rendering for the Tracks. Like the 'muteTracks' API, this unmute operation acts on those specified Tracks directly. Therefore it does not act on active Call as a whole.
The SDK will emit a media:unmuted event when a Track has been unmuted.
The media devices available for use have changed.
Information about the available media devices can be retrieved using the media.getDevices API.
// Listen for changes to available media devices.
client.on('devices:change', function () {
// Retrieve the latest media device lists.
const devices = client.media.getDevices()
})
An error occurred while trying to access media devices.
The most common causes of this error are when the browser does not have permission from the end-user to access the devices, or when the browser cannot find a media device that fulfills the MediaConstraint(s) that was provided.
The specified Tracks have been muted.
A Track can be muted using the media.muteTracks API.
The specified Tracks have been unmuted.
A Track can be unmuted using the media.unmuteTracks API.
The specified Track has had its media source muted.
The Track is still active, but is not receiving media any longer. An audio track will be silent and a video track will be a black frame. It is possible for the track to start receiving media again (see the media:sourceUnmuted event).
This event is generated outside the control of the SDK. This will predominantly happen for a remote track during network issues, where media will lose frames and be "choppy". This may also happen for a local track if the browser or end-user stops allowing the SDK to access the media device, for example.
The specified Track has started receiving media from its source once again.
The Track returns to the state before it was muted (see the media:sourceMuted event), and will be able to display video or play audio once again.
This event is generated outside the control of the SDK, when the cause of the media source being muted had been undone.
The specified Track has been rendered into an element.
Name | Description |
---|---|
params Object
|
|
params.trackIds Array<string>
|
The list of track id's that were rendered. |
params.selector string
|
The css selector used to identify the element the track is rendered into. |
params.error api.BasicError?
|
An error object, if the operation was not successful. |
A local Track has ended unexpectedly. The Track may still be part of a Call but has become disconnected from its media source and is not recoverable.
This event is emitted when an action other than an SDK operation stops the track. The most comon scenarios are when a device being used for a Call disconnects, any local tracks (such as audio from a bluetooth headset's microphone or video from a USB camera) from that device will be ended. Another scenario is for screensharing, where some browsers provide the ability to stop screensharing directly rather than through an SDK operation.
When a local track ends this way, it will still be part of the Call but will not have any media. The track can be removed from the call with the call.removeMedia API so the remote side of the Call knows the track has stopped, or the track can be replaced with a new track using the call.replaceTrack API to prevent any interruption.
The 'notification' namespace allows user to register/deregister for/from push notifications as well as enabling/disabling the processing of websocket notifications.
Provides an external notification to the system for processing.
An error occurred with push notifications.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |
params.channel string
|
The channel for the notification. |
The 'presence' namespace provides an interface for an application to set the User's presence information and to track other Users' presence information.
Presence information is persisted by the server. When the SDK is initialized, there will be no information available. Presence information will become available either by using presence.fetch or by subscribing for updates about other Users, using presence.subscribe.
Available presence information can be retrieved using presence.get or presence.getAll.
The PresenceStatus type defines the user's current status in terms of the user's availability to communicate/respond to other users in the network. An instance of this type can be obtained by invoking the presence.get function.
Reporting when a user is on the phone is enabled (by default), which means that presence update notifications will be sent whenever a user is in a call, as well as when the call has ended. This is a user preference enabled or disabled on server side, and it can only be changed on the server side.
The status is set to open as soon as a user subscribes for the presence service.
Type: Object
(string)
: The unique identifier for the user associated with this presence status.
(string)
: The current status the user has set for themselves. For supported values see
presence.statuses
.
(string)
: The current activity of the user.
For supported values see
presence.activities
.
(string)
: Additional message accompanying the status & activity.
(boolean)
: Whether the presence information has been loaded or is in the process of loading.
Updates the presence information for the current user.
See presence.statuses and presence.activities for valid values.
The SDK will emit a presence:selfChange event when the operation completes. The updated presence information is available and can be retrieved with presence.getSelf.
Other users subscribed for this user's presence will receive a presence:change event.
Fetches presence information for the given users. This will refresh the available information with any new information from the server.
Available presence information an be retrieved using the presence.get or presence.getAll APIs.
Retrieves the presence information for the current user.
This information is set using the presence.update API.
Object
:
Presence information for the current user.
A presence update about a subscribed user has been received.
This event is generated as a result of presence.fetch or presence.update operations.
For the latter operation, the current user receives a presence update of another user that the current user is subscribed to.
The changed information can be retrieved using the presence.get API.
The current user's presence information has changed.
The changed information can be retrieved using the presence.getSelf API.
An error occurred with presence.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |
The 'proxy' namespace allows for a secondary mode for making calls: proxy mode. When proxy mode is enabled, the SDK will redirect webRTC / media operations from the current machine to a remote machine using a channel.
This is an advanced feature that enables support for Calls in particular scenarios that would otherwise not support them.
The Channel object that the Proxy module needs to be provided.
Type: Object
// The channel the application uses for communicating with a remote endpoint.
const appChannel = ...
// The channel the application will provide to the Proxy module for use.
const channel = {
send: function (data) {
// Any encoding / wrapping needed for a Proxy message being sent
// over the channel.
appChannel.sendMessage(data)
},
// The Proxy module will set this function.
receive: undefined
}
appChannel.on('message', data => {
// Any decoding / unwrapping needed for the received message.
channel.receive(data)
})
client.proxy.setChannel(channel)
Sets whether Call functionality should be proxied to the Remote SDK or not.
When set to true
, WebRTC operations will be proxied over a channel. When
set to false
, WebRTC operation will occur as normal on the local machine.
Setting proxy mode is a required step for being able to use the Proxy functionality. It is recommended that this is the last step, after setting a channel and initializing the remote endpoint. Proxy mode cannot be changed if there is an on-going call.
On completion, this API will trigger a proxy:change event on success. The proxy.getProxyMode or proxy.getInfo APIs can be used to verify that proxy mode has been changed. If an error is encountered, this API will trigger a proxy:error event.
Name | Description |
---|---|
value boolean
|
Whether proxy mode should be enabled. |
// On success, the `proxy.setProxyMode` API will trigger a `proxy:change` event.
client.on('proxy:change', params => {
const isProxied = client.proxy.getProxyMode()
log(`Proxy mode set to ${isProxied}.`)
})
// On error, the `proxy.setProxyMode` API will trigger a `proxy:error` event.
client.on('proxy:error', params => {
const { code, message } = params.error
log(`Failed to set proxy mode due to ${code}: ${message}.`)
})
// Get the current proxy state to ensure we can set proxy mode to `true`.
const { proxyMode, hasChannel, remoteInitialized } = client.proxy.getInfo()
if (
hasChannel === true && // A channel was previously provided.
remoteInitialized === true && // The Remote SDK is ready.
proxyMode === false && // Proxy mode is not already `true`.
) {
client.proxy.setProxyMode(true)
}
Retrieves the current mode for Proxy behaviour.
When set to true
, WebRTC operations will be proxied over a channel. When
set to false
, WebRTC operation will occur as normal on the local machine.
See the proxy.setProxyMode API for more information.
boolean
:
Whether proxy mode is currently enabled.
Retrieves information about the proxy.
Object
:
proxy Object containing information about the proxy.
boolean
:
proxy.proxyMode Current operating mode.
boolean
:
proxy.hasChannel Proxy has a channel associated with it.
boolean
:
proxy.remoteInitialized Proxy initialization state.
Object
:
proxy.browser Details for the browser the proxy is using.
const proxy = client.proxy.getInfo()
log(`Proxy Browser in use: ${proxy.browser}, mode: ${proxy.proxyMode}, channel: ${proxy.hasChannel}, initialized: ${proxy.remoteInitialized}.`)
Retrieve information about the proxy's browser being used. Browser information being defined indicates that the browser supports basic webRTC scenarios.
const details = client.proxy.getProxyDetails()
log(`Proxy Browser in use: ${details.browser}, version ${details.version}.`)
Sets the channel to be used while proxy mode is enabled.
Providing a channel is a required step for being able to use the Proxy functionality. This should be the first step, before initializing the remote endpoint and setting proxy mode.
On completion, this API will trigger a proxy:change event on success. The proxy.getInfo API can be used to verify that a channel has been set. If an error is encountered, this API will trigger a proxy:error event. A channel cannot be set if there is an on-going call.
Name | Description |
---|---|
channel proxy.Channel
|
See the
Channel
module for information.
|
client.on('proxy:change', () => {
const { hasChannel } = client.proxy.getInfo()
log(`A channel ${hasChannel ? 'has': 'has not'} been set.`)
})
client.on('proxy:error', params => {
const { code, message } = params.error
log(`Encountered error ${code}: ${message}.`)
})
const appChannel = ...
client.proxy.setChannel(appChannel)
Sends an initialization message over the channel with webRTC configurations.
Initializing the Remote SDK is a required step before being able to use the Proxy functionality. This step requires a channel having been set previously (see the API). It is recommended to perform this step before setting the proxy mode (see the proxy.setProxyMode API).
On completion, this API will trigger a proxy:change event on success. The proxy.getInfo API can be used to verify that the remote endpoint is initialized. If an error is encountered, this API will trigger a proxy:error event.
This API will perform a version-check between this SDK and the Remote SDK. Their versions must be the same, otherwise initialization will fail.
Name | Description |
---|---|
config Object
|
// Get the current proxy state to ensure we can initialize the Remote SDK.
const { hasChannel, remoteInitialized } = client.proxy.getInfo()
if (
hasChannel === true && // A channel was previously provided.
remoteInitialized === false // The Remote SDK was not previously initializted.
) {
client.proxy.initializeRemote()
}
A Proxy API has completed and changed the proxy state.
The proxy.getInfo API can be used to retrieve the current proxy state.
A Proxy API has resulted in an error.
The proxy.getInfo API can be used to retrieve the current proxy state.
Name | Description |
---|---|
params Object
|
|
params.error BasicError
|
An error with
code
and
message
information.
|
The 'request' namespace (within the 'api' type) is used to make network requests to the server.
Send a request to the underlying REST service with the appropriate configuration and authentication. This is a wrapper on top of the browser's fetch API and behaves very similarly but using SDK configuration for the base URL and authentication as well as SDK logging.
Name | Description |
---|---|
resource string
|
The full path of the resource to fetch from the underlying service. This should include any REST version or user information. This path will be appended to the base URL according to SDK configuration. |
init RequestInit
|
An object containing any custom settings that you want to apply to the request. See fetch API for a full description and defaults. |
// Send a REST request to the server
// Create a request options object following [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/fetch)
const requestOptions = {
method: 'POST',
body: JSON.stringify({
test: 123
})
}
// Note that you will need to subscribe for the `custom` service in order to
// receive notifications from the `externalnotification` service.
const response = await client.request.fetch('/rest/version/1/user/xyz@test.com/externalnotification', requestOptions)
A set of SdpHandlerFunctions for manipulating SDP information. These handlers are used to customize low-level call behaviour for very specific environments and/or scenarios.
Note that SDP handlers are exposed on the entry point of the SDK. They can be added during initialization of the SDK using the config.call.sdpHandlers configuration parameter. They can also be set after the SDK's creation by using the call.setSdpHandlers function.
import { create, sdpHandlers } from '@rbbn/webrtc-js-sdk';
const codecRemover = sdpHandlers.createCodecRemover(['VP8', 'VP9'])
const client = create({
call: {
sdpHandlers: [ codecRemover, <Your-SDP-Handler-Function>, ...]
}
})
// Through the Call API post-instantiation
client.call.setSdpHandlers([ codecRemover, <Your-SDP-Handler-Function>, ...])
This function creates an SDP handler that will remove codecs matching the selectors specified for SDP offers and answers.
In some scenarios it's necessary to remove certain codecs being offered by the SDK to remote parties. For example, some legacy call services limit the SDP length (usually to 4KB) and will reject calls that have SDP size above this amount.
While creating an SDP handler would allow a user to perform this type of manipulation, it is a non-trivial task that requires in-depth knowledge of WebRTC SDP.
To facilitate this common task, the createCodecRemover function creates a codec removal handler that can be used for this purpose. Applications can use this codec removal handler in combination with the call.getAvailableCodecs function in order to build logic to determine the best codecs to use for their application.
call.SdpHandlerFunction
:
The resulting SDP handler that will remove the codec.
import { create, sdpHandlers } from '@rbbn/webrtc-js-sdk';
const codecRemover = sdpHandlers.createCodecRemover([
// Remove all VP8 and VP9 codecs.
'VP8',
'VP9',
// Remove all H264 codecs with the specified FMTP parameters.
{
name: 'H264',
fmtpParams: ['packetization-mode=0']
}
])
const client = create({
call: {
sdpHandlers: [codecRemover]
}
})
The 'services' namespace allows an application to manage how they wish the SDK to receive communications from the platform. An application can subscribe to services in order to receive updates about that service for the current user. A feature generally requires a subscription for its service to be fully functional.
The services an application can subscribe to are based on the features included in the SDK. The list of available services can be retrieved using the services.getSubscriptions API. These values can be used with the services.subscribe API.
The channel used for subscriptions is the method for receiving the service
updates. The recommended channel is websocket
, where the SDK is able to
handle receiving the updates internally. Alternate channel methods, if a
websocket cannot be used, will be available in the future.
The ServiceDescriptor type defines the format for specifying how to subscribe for a certain service.
This is the service configuration object that needs to be passed (as part of an array of configuration objects)
when calling the services.subscribe function.
Only some plugins (call
, messaging
and presence
) support such configuration object that needs to be passed
to the subscribe function.
Type: Object
(string)
: The name of the available service user wants to subscribe to.
The available service names are
chat
,
presence
,
call
and
smsinbound
.
(Object?)
: An object containing any additional parameters required for subscribing to that service.
This is an optional property as not all service subscriptions require it.
// Subscribe to chat, presence & call services on a WebSocket channel.
client.services.subscribe([
{service: 'chat'},
{service: 'presence'},
{service: 'call'},
], 'websocket')
The SmsInboundServiceParams type defines the additional information when subscribing to SMS inbound service. This is the configuration object that needs to be passed as the value for the ServiceDescriptor.params property.
Type: Object
(string)
: An E164 formatted DID number.
The subscription created will provide notifications for inbound SMS messages destined for this address.
// Subscribe to smsinbound service on a WebSocket channel.
client.services.subscribe([
{service: 'smsinbound', params: {destinationAddress: '+18001234567'}}
], 'websocket')
Subscribes to platform notifications for an SDK service.
The SDK will emit a subscription:change event for each change in subscription state. This includes when this API is initially called, to indicate a pending subscription, then again after the operation succeeds. Upon getting such event, existing subscriptions can be retrieved using the services.getSubscriptions API.
The SDK will emit a subscription:error event if the operation fails.
The clientCorrelator
option should be provided to support a user subscribing from multiple clients
at the same time. This value is used by the platform to correlate subscriptions to specific clients.
If a second subscription is made with the same value (including no value), the platform will override
the first subscription. The client with the first subscription will receive a
subscription:change event with an explicit reason in this
scenario.
The SDK currently only supports the websocket
channel as a subscription type
option.
Name | Description |
---|---|
services Array<(string | services.ServiceDescriptor)>
|
A list of service configurations. |
options Object?
|
The options object for non-credential options. |
options.type string
(default 'websocket' )
|
The method of how to receive service updates. |
options.clientCorrelator string?
|
Unique ID for the client. This is used by the platform to identify an instance of the application used by the specific device. |
// Subscribe for call and messaging services.
client.services.subscribe(['call', 'IM'], { clientCorrelator: 'abc123' })
Cancels existing subscriptions for platform notifications.
When calling this API, SDK emits a subscription:change event, each time there is a change in subscriptions.
Upon getting such event, existing subscriptions can be retrieved using the
services.getSubscriptions API. The subscribed
values are the
services that can be unsubscribed from.
// Unsubscribe from chat and SMS services.
const services = [ 'chat', 'smsinbound' ]
client.services.unsubscribe(services)
Retrieves information about currently subscribed services and available services. The data returned by this API is a snapshot of the SDK's current local subscription state. The data does indicate whether there was an ongoing subscription at the time this API was called. If a subscription is in fact in progress, the user should not take decisions based on this snapshot, as the subscription is not yet complete.
To be notified when any subscription(s) did change/complete, listen for subscription:change events.
The available
values are the SDK's services that an application can
subscribe to receive notifications about. A feature generally
requires a subscription to its service in order to be fully functional.
The subscribed
values are the SDK's services that the application has
an active subscription for. Services are subscribed to using the
services.subscribe API.
Object
:
Lists of subscribed and available services.
// Get the lists of services.
const services = client.services.getSubscriptions()
// Ensure that there were no pending subscriptions at the time
// we called getSubscriptions API.
if (!services.isPending) {
// Figure out which available services don't have a subscription.
const notSubscribed = services.available.filter(service => {
return !services.subscribed.includes(service)
})
// Subscribe for all not-yet-subscribed services.
client.services.subscribe(notSubscribed)
}
Constants used to describe reasons for unsolicited subscription change.
These values are used in the subscription:change event
for the reason
parameter. When the parameter is defined, it indicates the subscription changed
for one of these unsolicited reasons.
Subscription information has changed.
The updated subscription information can be retrieved using the services.getSubscriptions API.
When the reason
parameter is provided, this means the subscription has been lost unexpectedly.
The value for this parameter will be one of the services.changeReasons constants.
An error occurred during a subscription operation.
The subscription information can be retrieved using the services.getSubscriptions API.
Below are some common errors related to service subscriptions.
authentication:1
- "Authorization failed with server. Please check credentials. Status code: 4`" - Invalid credentials.authentication:3
- "No subscription found for "X", can't unsubscribe" - The requested service is not currently subscribed.authentication:3
- "No subscription found, can't unsubscribe." - There are no active subscriptions.authentication:4
- "Failed to subscribe user. Status Code 19" - Too many active sessions with the requested user.authentication:4
- "Failed to subscribe user. Status Code 37" - Invalid service string.authentication:4
- "Failed to subscribe user. Status Code 38" - Invalid characters in client correlator.authentication:4
- "Failed to subscribe user. Status Code 39" - Session does not exist anymore.authentication:12
- "No services found in configuration." - No services found in SDK configuration.The following errors indicate an issue with the user account or temporary backend issue. They may require help from support or a delay before being retried.
authentication:4
- "Failed to subscribe user. Status Code 9"authentication:4
- "Failed to subscribe user. Status Code 17"authentication:4
- "Failed to subscribe user. Status Code 26"authentication:4
- "Failed to subscribe user. Status Code 27"authentication:4
- "Failed to subscribe user. Status Code 54"authentication:4
- "Failed to subscribe user. Status Code 62"authentication:4
- "Failed to subscribe user. Status Code 63"authentication:13
- "Failed to subscribe user. Status Code 53"For a more detailed look into subscription errors and handling recommendations, please refer to the "Handling Subscription Errors" tutorial.
An attempt to extend the current user's subscription was made.
In a failure scenario, the current user is still connected, and further resubscription attempts will be made, but may become disconnected if the session expires.
Name | Description |
---|---|
params Object
|
|
params.attemptNum number
|
The attempt number of this resubscription. |
params.isFailure boolean
|
Whether the resubscription failed or not. |
params.error api.BasicError?
|
The Basic error object. |
The SIP Events feature allows an application to communicate with a SIP network integrated
with their WebRTC Gateway instance. The SIP network may generate custom events intended
for an application, which can be handled with the SDK's sip
namespace.
Usage of SIP Events is dependent on your WebRTC Gateway instance. The types of SIP Events can be different based on configurations and components, often being part of a custom solution. As such, the SIP Events feature is presented in a generic manner to be flexible for any possible events.
An example of a common SIP event is "SIP presence". When a user is connected to a SIP phone, the network may generate "phone presence" events when the user starts and ends a call (eg. 'On Call', 'Available'). Applications can subscribe to receive these events for specific users.
A SIP event may either be solicited or unsolicited. Solicited events, such as the "presence" example above, requires the application to subscribe for the event. See the sip.subscribe API for more information about solicited events. Unsolicited events have no prerequisites for being received.
Creates a subscription for a SIP event.
A subscription is required to receive SIP notifications for solicited events. Before creating a SIP subscription, the service for the event type must have been provisioned as part of the user subscription using the services.subscribe API.
Only one SIP subscription per event type can exist at a time. A subscription can watch for events from multiple users at once. Users can be added to or removed from a subscription using the sip.update API at any time.
The SDK will emit a sip:subscriptionChange event when the operations completes. The sip.getDetails API can be used to retrieve the current information about a subscription.
The SDK will emit a sip:eventsChange event when a SIP event is received.
// Provision the service for the specific SIP event during user subscription.
// This is required before a SIP subscription for the event can be created.
const services = ['call', 'event:presence', ...]
client.services.subscribe(services)
// Subscribe to receive SIP presence events from two users.
client.sip.subscribe('event:presence', ['userOne@example.com', 'userTwo@example.com'], 'clientId123')
// Subscribe for SIP events with a custom parameter.
const customParameters = [{
name: 'X-nt-GUID',
value: 'GUID123abc'
}]
client.sip.subscribe('event:presence', subscribeUserList, 'clientId123', customParameters)
Updates an existing SIP event subscription.
Allows for adding or removing users from the subscription, and for changing the custom parameters of the subscription.
The SDK will emit a sip:subscriptionChange event when the operations completes. The sip.getDetails API can be used to retrieve the current information about a subscription.
Name | Description |
---|---|
eventType string
|
The name of the SIP event. |
userLists Object
|
|
userLists.subscribeUserList Array<string>
|
List of users to add to the subscription. |
userLists.unsubscribeUserList Array<string>
|
List of users to remove from the subscription. If all users are removed, the event subscription will be deleted. |
customParameters Array<call.CustomParameter>?
|
Custom SIP header parameters for the SIP backend. |
// Add a user to an existing subscription.
const userLists = {
subscribedUserList: ['userThree@example.com']
}
client.sip.update('event:presence', userLists)
// Simultaneously add and remove users from the subscription.
const userLists = {
subscribedUserList: ['userThree@example.com'],
unsubscribeUserList: ['userOne@example.com']
}
client.sip.update('event:presence', userLists)
Deletes an existing SIP event subscription.
The SDK will emit a sip:subscriptionChange event when the operations completes.
Subscription details will no longer be available using the sip.getDetails API after it has been unsubscribed from.
Name | Description |
---|---|
eventType string
|
The name of the SIP event. |
// Delete a SIP subscription.
client.sip.unsubscribe('event:presence')
Retrieve information about a SIP event subscription.
The SDK will track which users are included as part of the subscription and previous notifications received. Each subscription will include a unique ID.
Name | Description |
---|---|
eventType string?
|
The name of a SIP event. If not provided, will retrieve information for all SIP subscriptions. |
Object
:
SIP subscription information. If
eventType
was not provided, will
return an object namespaced by event types.
// Retrieve information about a single SIP subscription.
const { subscribedUsers, notifications } = client.sip.getDetails('event:presence')
// Retrieve information about all current SIP subscriptions.
const subscriptions = client.sip.getDetails()
const { subscribedUsers, notifications } = subscriptions['event:presence']
A change has occurred to a SIP subscription.
This event can be emitted when a new SIP subscription is created (sip.subscribe
API), an existing subscription is updated (sip.update API), or has been
deleted (sip.unsubscribe API). The change
parameter on the event indicates
which scenario caused the event.
When users are added or removed from a subscription through a new subscription or an update,
the subscribedUsers
and unsubscribedUsers
parameters will indicate the users added
and removed, respectively.
The sip.getDetails API can be used to retrieve the current information about a subscription.
Name | Description |
---|---|
params Object
|
|
params.eventType string
|
The name of the SIP event. |
params.change string
|
The change operation that triggered the event. |
params.subscribedUsers Array<string>?
|
List of users added to the subscription as part of the change. |
params.unsubscribedUsers Array<string>?
|
List of users removed from the subscription as part of the change. |
An error has occurred during a SIP event operation.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |
params.eventType string
|
The name of the SIP event. |
// Listen for the event being emitted.
client.on('sip:error', (params) => {
// Handle the error based on the information.
const { code, message } = params.error
...
})
A SIP event notification has been received.
The event
parameter is the full notification received from the network. The format
of the notification is dependant on its event type. The SDK does not do any
pre-processing of this data.
Name | Description |
---|---|
params Object
|
Information about the notification. |
params.eventType string
|
The name of the SIP event. |
params.eventId string
|
A unique ID for the event notification. |
params.event Object
|
The full event object. |
params.links Object
|
|
params.links.callId string?
|
The ID of the call this SIP event links to. |
// Listen for the event being emitted.
client.on('sip:eventsChange', (params) => {
// Gather the SIP info specific to the event.
const sipInfo = params.event.genericNotificationParams
// Handle the data based on the event type.
if (params.eventType === 'event:presence') {
const { data, from } = sipInfo
...
}
})
The 'user' namespace allows access to user information for users within the same domain.
The ID of a User (e.g. joe@domain.com)
Type: string
The User data object.
Type: Object
(user.UserID)
: The User ID of the user.
(string)
: The email address of the user.
(string)
: The first name of the user.
(string)
: The last name of the user.
(string)
: The URL to get the photo of the user.
(string)
: Whether the user is a "buddy". Values can be "true" or "false".
Fetches information about a User.
The SDK will emit a users:change event after the operation completes. The User's information will then be available.
Information about an available User can be retrieved using the user.get API.
Name | Description |
---|---|
userId string
|
The User ID of the user. |
Retrieves information about a User, if available.
See the user.fetch and user.search APIs for details about making Users' information available.
Name | Description |
---|---|
userId user.UserID
|
The User ID of the user. |
user.User
:
The User object for the specified user.
Retrieves information about all available Users.
See the user.fetch and user.search APIs for details about making Users' information available.
Searches the domain's directory for Users.
Directory searching only supports one filter. If multiple filters are provided, only one of the filters will be used for the search. A search with no filters provided will return all users.
The SDK will emit a directory:change event after the operation completes. The search results will be provided as part of the event, and will also be available using the user.get and user.getAll APIs.
Name | Description |
---|---|
filters Object
|
The filter options for the search. |
filters.userId user.UserID?
|
Matches the User ID of the user. |
filters.name string?
|
Matches the firstName or lastName. |
filters.firstName string?
|
Matches the firstName. |
filters.lastName string?
|
Matches the lastName. |
filters.userName string?
|
Matches the userName. |
filters.phoneNumber string?
|
Matches the phoneNumber. |
The 'voicemail' namespace is used to retrieve and view voicemail indicators.
Voicemail functions are all part of this namespace.
Attempts to retrieve voicemail information from the server.
A voicemail:change event is emitted upon completion.
Returns voicemail data from the store.
A voicemail event has been received.
Name | Description |
---|---|
params Object
|
An object containing voicemail info. |
params.lastUpdated number
|
Timestamp of the last time voicemail data was checked. |
params.newMessagesWaiting boolean
|
Whether there are new messages. |
params.totalVoice number
|
The total number of voicemail messages. |
params.unheardVoice number
|
Number of unheard voicemail messages. |
params.voice Object
|
Object containing individual counts of new, old, urgent voicemails. |
params.fax Object
|
Object containing individual counts of new, old, urgent faxes. |
params.multimedia Object
|
Object containing individual counts of new, old, urgent multimedia messages. |
An error has occurred while attempting to retrieve voicemail data.
Name | Description |
---|---|
params Object
|
|
params.error api.BasicError
|
The Basic error object. |