4.8.0The SDK creation factory. Create an instance of the SDK by calling this factory with the desired configurations.
(config)
The configuration object.
// Instantiate the SDK.
import { create } from 'kandy'
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.
(Object)
Logs configs.
| Name | Description |
|---|---|
logs.logLevel string
(default 'debug')
|
Log level to be set. See levels . |
logs.flatten boolean
(default false)
|
Whether all logs should be output in a string-only format. |
logs.logActions Object?
|
Options specifically for action logs when logLevel is at DEBUG+ levels. Set this to false to not output action logs. |
logs.logActions.actionOnly boolean
(default true)
|
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.exposePayloads boolean
(default false)
|
Allow action payloads to be exposed in the logs, potentially displaying sensitive information |
logs.enableFcsLogs boolean
(default true)
|
Enable the detailed call logger. |
logs.enableGrouping boolean
(default true)
|
Whether to group information about an action log together in the console. |
Configuration options for the Authentication feature.
(Object)
Authentication configs.
| Name | Description |
|---|---|
authentication.subscription Object
|
|
authentication.subscription.server string
|
Hostname of the server to be used for subscription requests. |
authentication.subscription.protocol string
(default https)
|
Protocol to be used for subscription requests. |
authentication.subscription.port Number
(default 443)
|
Port to be used for subscription requests. |
authentication.subscription.version string
(default 1)
|
Version of the REST API to be used. |
authentication.subscription.expires Number
(default 3600)
|
Time duration, in seconds, until a subscription should expire. |
authentication.subscription.service Array?
|
Services to subscribe to for notifications. Default value is ['call', 'IM', 'presence'] . |
authentication.subscription.localization string
(default English_US)
|
|
authentication.subscription.useTurn Boolean
(default true)
|
|
authentication.subscription.notificationType string
(default Websocket)
|
|
authentication.websocket Object
|
|
authentication.websocket.server string
|
Hostname of the server to be used for websocket notifications. |
authentication.websocket.protocol string
(default wss)
|
Protocol to be used for websocket notifications. |
authentication.websocket.port Number
(default 443)
|
Port to be used for websocket notifications. |
authentication.earlyRefreshMargin Number
(default 300)
|
Configuration options for the call feature.
(Object)
The call configuration object.
| Name | Description |
|---|---|
call.sdpSemantics string
(default 'unified-plan')
|
The sdpSemantics to use (
'unified-plan'
or
'plan-b'
).
|
call.iceServers Array<IceServer>?
|
The list of ICE servers to be used for calls. |
call.serverTurnCredentials boolean
(default true)
|
Whether server-provided TURN credentials should be used. |
call.sdpHandlers Array<SdpHandlerFunction>?
|
List of SDP handler functions to modify SDP. Advanced usage. |
call.removeH264Codecs boolean
(default true)
|
Whether to remove "H264" codec lines from incoming and outgoing SDP messages. |
Configuration options for the Connectivity feature.
(Object)
Connectivity configs.
| Name | Description |
|---|---|
connectivity.method Object
|
Configuration for how connectivity checks should be made. |
connectivity.method.type String
(default 'keepAlive')
|
The method of connectivity checking to use:
keepAlive
or
pingPong
.
|
connectivity.method.responsibleParty String
(default 'client')
|
Configures who is responsible for initiating the connectivity check:
client
or
server
.
|
connectivity.pingInterval Number
(default 30000)
|
Time in between websocket ping attempts (milliseconds). Only used for when the client is responsible for ping/connCheck. |
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 factor after each failed reconnect attempt to increase the delay between attempts. |
connectivity.reconnectTimeLimit Number
(default 640000)
|
Maximum time delay between reconnect attempts (milliseconds). Used in conjunction with
reconnectTimeMultiplier
to prevent overly long delays between reconnection attempts.
|
connectivity.autoReconnect Boolean
(default true)
|
Flag to determine whether reconnection will be attempted automatically after connectivity disruptions. |
connectivity.maxMissedPings Number
(default 3)
|
Maximum pings sent (without receiving a response) before reporting an error. |
connectivity.checkConnectivity Boolean
(default false)
|
Flag to determine whether to enable connectivity checking or not. |
Configuration options for the notification feature.
(Object)
The notifications configuration object.
| Name | Description |
|---|---|
notifications.idCacheLength number
(default 100)
|
Default amount of event ids to remember for de-duplication purposes. |
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. |
notifications.realm string?
|
The realm used for push notifications |
notifications.bundleId string?
|
The bundle id used for push notifications |
An interface for getting and updating the configuration Object.
Configuration functions are available directly on the SDK Object
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}.`)
The authentication feature handles connecting and disconnecting from any backend services that the SDK deals with. As well, it handles and stores authentication information on the behalf of the user. This allows the user to interact with the server without worrying about authenticating.
Connect by providing an OAuth token.
client.connect({
username: 'alfred@example.com',
oauthToken: 'RTG9SV3QAoJaeUSEQCZAHqrhde1yT'
});
Connect by providing a refresh token.
client.connect({
username: 'alfred@example.com',
refreshToken: 'RTG9SV3QAoJaeUSEQCZAHqrhde1yT'
expires: 3600
});
Connect by providing an access token. You can optionally provide a refresh token and the SDK will automatically get new access tokens.
(Object)
The credentials object.
| Name | Description |
|---|---|
credentials.username string
|
The username without the application's domain. |
credentials.accessToken string
|
An access token for the user with the provided user Id. |
credentials.refreshToken string?
|
A refresh token for the same user. |
credentials.expires number?
|
The time in seconds until the access token will expire. |
client.connect({
username: 'alfred@example.com',
accessToken: 'AT0V1fswAiJadokx1iJMQdG04pRf',
refreshToken: 'RTG9SV3QAoJaeUSEQCZAHqrhde1yT',
expires: 3600
});
Connect with user credentials.
client.connect({
username: 'alfred@example.com',
password: '********'
authname: '********'
});
Disconnects from the backend. This will close the websocket and you will stop receiving events.
If you're authenticating with tokens that expire and have not provided a refresh token to the connect function, you can update your access token with updateToken before it expires to stay connected.
client.updateToken({
username: 'alfred@example.com',
oauthToken: 'RTG9SV3QAoJaeUSEQCZAHqrhde1yT'
});
If you're authenticating with tokens that expire and have not provided a refresh token to the connect function, you can update your access token with updateToken before it expires to stay connected.
(Object)
The credentials object.
| Name | Description |
|---|---|
credentials.accessToken string
|
The new access token. |
credentials.username string
|
The username without the application's domain. |
credentials.accessToken string
|
An access token for the user with the provided user Id. |
(Object)
The credentials object.
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.
Get the connection state.
Object:
connection The connection state.
boolean:
connection.isConnected Whether the authenticated user is currently connected.
boolean:
connection.isPending Whether the authenticated user's connection is currently pending.
Object:
connection.error The error object if an error occured.
string:
connection.error.message The error message.
string:
connection.error.stack The stack trace of the error.
Authentication state has changed. You can get the new state by calling getConnection().
There was an error with authentication.
(Object)
| Name | Description |
|---|---|
params.error BasicError
|
The Basic error object. |
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.
(Object)
| Name | Description |
|---|---|
params.attemptNum number
|
The attempt number of this resubscription. |
params.isFailure boolean
|
Whether the resubscription failed or not. |
params.error BasicError?
|
The Basic error object. |
The Basic Error object. Provides information about an error that occurred in the SDK.
The call history feature is used to retrieve and inspect the authenticated users call logs.
CallHistory functions are all part of the 'call.history' namespace.
Fetches the list of call logs and stores them locally. The API
getCallLogs can then be used to get the logs from local state after
it has been updated.
Deletes all call logs.
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();
});
Sets the cached call history data, expects stringified data as it will be parsed.
(any)
The data to restore in the cache.
Call history state has been updated. See getCallLogs() to retrieve new state.
An error occured while performing a call history operation.
(Object)
| Name | Description |
|---|---|
params.error BasicError
|
The Basic error object. |
Call history cached state has been updated
The Calls feature 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 state representation of a Media object. Media is a collection of Track objects.
Type: Object
Information about a Call.
Can be retrieved using the call.getAll or call.getById APIs.
Type: Object
(string)
: The ID of the call.
(string)
: The direction in which the call was created. Can be 'outgoing' or 'incoming'.
(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.
(Object)
: Information about the other call participant.
(BandwidthControls)
: The bandwidth limitations set 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.
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 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 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 form of an SDP handler function and the expected arguments that it receives.
Type: Function
(Object)
The SDP so far (could have been modified by previous handlers).
(SdpHandlerInfo)
Additional information that might be useful when making SDP modifications.
(Object)
The SDP in its initial state.
Object:
The resulting modified SDP based on the changes made by this function.
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.
(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.
(string)
: The state of this Track. Can be 'live' or 'ended'.
(string)
: The ID of the Media Stream that includes this Track.
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 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.
((SIP_URI | TEL_URI))
The desired destination.
(Object)
The media options the call should be initialized with.
| Name | Description |
|---|---|
media.audio boolean
(default false)
|
Whether the call should have audio on start. Currently, audio-less calls are not supported. |
media.audioOptions Object?
|
Options for configuring the call's audio. |
media.audioOptions.deviceId MediaConstraint?
|
ID of the microphone to receive audio from. |
media.video boolean
(default false)
|
Whether the call should have video on start. |
media.videoOptions Object?
|
Options for configuring the call's video. |
media.videoOptions.deviceId MediaConstraint?
|
ID of the camera to receive video from. |
media.videoOptions.height MediaConstraint?
|
The height of the video. |
media.videoOptions.width MediaConstraint?
|
The width of the video. |
media.videoOptions.frameRate MediaConstraint?
|
The frame rate of the video. |
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 })
Rejects an incoming call.
The specified call to reject must be in a ringing state with an incoming direction. The call will be ended 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, through their own call:stateChange event, that the call was rejected.
(string)
The ID of the call to reject.
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 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.
(string)
The ID of the call to answer.
(Object)
The media options the call should be initialized with.
| Name | Description |
|---|---|
media.audio boolean
(default false)
|
Whether the call should have audio on start. Currently, audio-less calls are not supported. |
media.audioOptions Object?
|
Options for configuring the call's audio. |
media.audioOptions.deviceId MediaConstraint?
|
ID of the microphone to receive audio from. |
media.video boolean
(default false)
|
Whether the call should have video on start. |
media.videoOptions Object?
|
Options for configuring the call's video. |
media.videoOptions.deviceId MediaConstraint?
|
ID of the camera to receive video from. |
media.videoOptions.height MediaConstraint?
|
The height of the video. |
media.videoOptions.width MediaConstraint?
|
The width of the video. |
media.videoOptions.frameRate MediaConstraint?
|
The frame rate of the video. |
(Object?)
| Name | Description |
|---|---|
options.bandwidth BandwidthControls?
|
Options for configuring media's bandwidth. |
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 SDK will emit a call:stateChange event locally when the operation completes. The remote participant will not be notified that the call was ignored.
(string)
The ID of the call to ignore.
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 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.
(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 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.
(string)
The ID of the call to unhold.
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 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.
(string)
The ID of the call to end.
Add new media tracks to an ongoing call. Will get new media tracks from the specific sources to add to the call.
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.
(string)
The ID of the call to add media to.
(Object
= {})
The media options to add to the call.
| Name | Description |
|---|---|
media.audio boolean
(default false)
|
Whether to add audio to the call. |
media.audioOptions Object?
|
Options for configuring the call's audio. |
media.audioOptions.deviceId MediaConstraint?
|
ID of the microphone to receive audio from. |
media.video boolean
(default false)
|
Whether to add video to the call. |
media.videoOptions Object?
|
Options for configuring the call's video. |
media.videoOptions.deviceId MediaConstraint?
|
ID of the camera to receive video from. |
media.videoOptions.height MediaConstraint?
|
The height of the video. |
media.videoOptions.width MediaConstraint?
|
The width of the video. |
media.videoOptions.frameRate MediaConstraint?
|
The frame rate of the video. |
(Object?
= {})
| Name | Description |
|---|---|
options.bandwidth BandwidthControls?
|
Options for configuring media's bandwidth. |
Remove tracks from an ongoing call.
The SDK will emit a call:trackEnded event for both the local and remote users to indicate that a track has been removed.
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 or Ringing 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.
(string)
ID of the call being acted on.
(string)
DTMF tone(s) to send. Valid chracters are
['0','1','2','3','4','5','6','7','8','9','#','*' and ',']
.
(number
= 100)
The amount of time, in milliseconds, that each DTMF tone should last.
(number
= 70)
The length of time, in milliseconds, to wait between tones.
Get a report about low-level call statistical information.
A Track ID can optionally be provided to get a report for a specific Track of the Call.
The SDK will emit a call:statsReceived event, after the operation completes, that has the report.
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. Both remote participants will see their call be unheld, and will be connected to one another after the operation. Both calls for the current user will be ended.
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 "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 calls for the current user will be ended after the operation.
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.
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.
(string)
The ID of the call to replace the track of.
(string)
The ID of the track to replace.
(Object
= {})
The media options.
| Name | Description |
|---|---|
media.audio boolean
(default false)
|
Whether to create an audio track. |
media.audioOptions Object?
|
Options for configuring the audio track. |
media.audioOptions.deviceId MediaConstraint?
|
ID of the microphone to receive audio from. |
media.video boolean
(default false)
|
Whether to create a video track. |
media.videoOptions Object?
|
Options for configuring the video track. |
media.videoOptions.deviceId MediaConstraint?
|
ID of the camera to receive video from. |
media.videoOptions.height MediaConstraint?
|
The height of the video. |
media.videoOptions.width MediaConstraint?
|
The width of the video. |
media.videoOptions.frameRate MediaConstraint?
|
The frame rate of the video. |
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
}
})
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.
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.
(string)
: The (outgoing) call is being started.
(string)
: The (outgoing) call has been sent over the network, but has not been received.
(string)
: The call has been received by both parties, and is waiting to be answered.
(string)
: The call was disconnected before it could be answered.
(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) {
// Render call media ...
}
})
An outgoing call has been started.
Information about the Call can be retrieved using the call.getById API.
(Object)
| Name | Description |
|---|---|
params.callId string
|
The ID of the call. |
params.error 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.
(Object)
| Name | Description |
|---|---|
params.callId string
|
The ID of the call. |
params.error 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.
(Object)
| Name | Description |
|---|---|
params.callId string
|
The ID of the call. |
params.error BasicError?
|
An error object, if the operation was not successful. |
client.on('call:receive', function(params) {
// We have received a call, prompt the user to respond.
promptUser(client.call.getById(params.callId));
});
A Call's state has changed.
See call.states for information about call states.
(Object)
| Name | Description |
|---|---|
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?
|
|
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 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.
A new Track has been added to the Call.
The Track may have been added by either the local user or remote user using the call.addMedia API.
Information about the Track can be retrieved using the media.getTrackById API.
A Track has been removed from a Call.
The Track may have been removed by either the local user or remote user using the call.removeMedia API. Tracks are also removed from Calls automatically while the Call is on hold.
Stats have been retrieved for a Call or specific Track of a Call.
See the call.getStats API for more information.
(Object)
| Name | Description |
|---|---|
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 string
|
The RTCStatsReport. |
params.error BasicError?
|
An error object, if the operation was not successful. |
A Track has been replaced on the Call.
A Track is replaced by the local user using the call.replaceTrack API.
This event is similar to the call:newTrack event, where the call has a new Track, except that an existing Track has been removed at the same time. The event includes information about the Track that was replaced to help an application replace it seamlessly.
(Object)
| Name | Description |
|---|---|
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 TrackObject?
|
State of the replaced track. |
params.error BasicError?
|
An error object, if the operation was not successful. |
The clickToCall feature is used to bridge a call between two specified devices
ClickToCall had an error.
(Object)
| Name | Description |
|---|---|
params.callId string
|
A unique id representing the call made |
params.error BasicError
|
The Basic error object. |
The connection feature is used to connect and maintain connections between the SDK and one or more backend servers.
Connectivity functions are all part of the 'connection' namespace.
The Contacts feature allows users to store personal contacts to their account.
These functions are namespaced beneath 'contacts' on the API.
Add a contact to a user's personal address book.
Will trigger the contacts:new event.
(Object)
The contact object.
| Name | Description |
|---|---|
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.
(Object)
The contact object.
| Name | Description |
|---|---|
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.
(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 Events feature allows an application to listen for events that the SDK emits. Each other feature has a set of event types that can be subscribed to using the Event APIs.
Add an event listener for the specified event type.
(string)
The event type for which to add the listener.
(Function)
The listener for the event type. The parameters of the listener depend on the event type.
// Listen for events of a specific type emitted by the SDK.
client.on('dummy:event', function (params) {
// Handle the event.
})
The internal logger is used to provide information about the SDK's behaviour. The logger can provide two types of logs: basic logs and action logs. Basic logs are simple lines of information about what the SDK is doing during operations. Action logs are complete information about a specific action that occurred within the SDK, providing debug information describing it. The amount of information logged can be configured as part of the SDK configuration. See config.logs .
Possible levels for the SDK logger.
(string)
: Log nothing.
(string)
: Log only unhandled errors.
(string)
: Log issues that may cause problems or unexpected behaviour.
(string)
: Log useful information and messages to indicate the SDK's internal operations.
(string)
: Log information to help diagnose problematic behaviour.
The Media feature provides an interface for interacting with Media that the SDK has access to. Media is used 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.
Media functions are all part of the 'media' namespace.
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.
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.
(string)
A CSS selector string that uniquely
identifies an element. Ensure that special characters are properly
escaped.
// When an outgoing call is accepted, render the Media used for the call.
client.on('call:accepted', function (params) {
// Get the information about the call.
const call = client.call.getById(params.callId)
// Render the call's local and remote media in their respective containers.
client.media.render(call.localMedia[0], localContainer)
client.media.render(call.remoteMedia[0], remoteContainer)
})
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 at their media source.
Prevents media from being received for the Tracks. Audio Tracks will become silent and video Tracks will be a black frame.
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.
The SDK will emit a media:muted event when a Track has been muted.
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()
})
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 messaging feature revolves around a "conversation" structure. 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 either two users, or a user and a group. 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.
(number)
: The timestamp (milliseconds since epoch) of when a message was last received in this conversation.
Create and return a message object. You must specify the part. If this is a simple text message, provide a text part as demonstrated in the example.
(Object)
The part to add to the message.
| Name | Description |
|---|---|
part.type string
|
The type of part. Can be "text", "json", "file". |
part.text string?
|
The text of the part. Must be a part of type "text". |
part.json Object?
|
The json of the part. Must be a part of type "json". |
part.file File?
|
The file of the part. Must be a part of type "file". |
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.
Subscribe to this conversations messages array.
Function:
The unsubscribe function.
Allows the user to fetch messages associated with a specific conversation from the server. When the operation is complete, a NEW_MESSAGE event will be emitted. Messages can then be retrieved using getMessages.
(number
= 50)
An amount of messages to fetch.
A Message object represents an individual message. Messages have parts which represent pieces of a message, such as a text part or a file part. Once all the desired parts have been added, a message can be sent with the send() function.
Type: Object
Sends the message.
Add an additional part to a message.
(Object)
The part to add to the message.
| Name | Description |
|---|---|
part.type string
|
The type of part. Can be "text", "json", "file", or "location". |
part.text string?
|
The text of the part. Must be a part of type "text". |
part.json Object?
|
The json of the part. Must be a part of type "json". |
part.file File?
|
The file of the part. Must be a part of type "file". |
Attempts to retrieve a list of conversations that the current user is a part of. These conversations can then be retrieved from the store using get().
(Object?)
An optional configuration object to query for more specific results.
If no object is passed, all threads will be retrieved.
| Name | Description |
|---|---|
options.touched string?
|
The unix timestamp in seconds representing the date from which to return any threads that have changed. Can also pass the string literal "lastcheck", resulting in the back-end making use of the most recent date value provided in a previous request |
options.type string?
|
Limit results to one of: "internal", "sms", "group" or "unknown". |
options.thread (string | number)?
|
Limit results to one thread specified by its thread handle. |
Get a conversation object matching the user IDs provided. If successful, the event 'conversations:change' will be emitted. Multi-user conversations have a destination comprised of multiple user IDs.
(Array)
An array of destinations for messages created in this conversation.
These will be a user's sip address.
(Object?)
An optional configuration object to query for more specific results.
If this object is not passed, the function will query for "im" conversations associated with those destinations.
| Name | Description |
|---|---|
options.type string?
|
The type of conversation to retrieve. Can be one of "im", "sms" or "other". |
Conversation:
A Conversation object.
Create and return a new conversation object. Any messages being sent through this conversation object will be sent to the destinations provided
(Array)
An array of destinations for messages created in this conversation. These will be a user's sip address.
(string)
The type of conversation to create. Can be one of "im", "sms", "group" or "other"
(any)
Object:
a Conversation object
A new conversation has been created and added to the state.
A change has occured in the conversation list.
(Array)
An array of objects containing information about the conversations that have changed
| Name | Description |
|---|---|
params.destination Array
|
The destination for messages created in this conversation. |
params.type string
|
The type of conversation to create. Can be one of "chat", "im", "sms" or "group" |
A change has occured in a specific conversations message list.
If a single message was affected/created, messageId will be present
as part of the event argument.
(Object)
| Name | Description |
|---|---|
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" or "group" |
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 occured with messaging.
(Object)
| Name | Description |
|---|---|
params.error BasicError
|
The Basic error object. |
Registers a device token for push notifications.
(Object)
| Name | Description |
|---|---|
params.deviceToken string
|
The device token to be registered. |
params.services Array<string>
|
Array of services to register for. |
params.pushProvider string
|
The push provider, can be either 'apple' or 'google'. |
params.clientCorrelator string
|
Unique identifier for a client device. |
Deregisters for push notifications.
An error occured with push notifications.
(Object)
| Name | Description |
|---|---|
params.error BasicError
|
The Basic error object. |
params.channel string
|
The channel for the notification. |
The Presence feature 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.
Presence APIs are part of the 'presence' namespace.
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.
Retrieves the presence information for the current user.
This information is set using the presnece.update API.
Object:
Presence information for the current user.
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.
A presence update about a subscribed user has been received.
The current user's presence information has changed.
The changed information can be retrieved using the presence.getSelf API.
An error occurred with presence.
(Object)
| Name | Description |
|---|---|
params.error BasicError
|
The Basic error object. |
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. They can be provided during SDK instantiation to be used for all calls.
import { create, sdpHandlers } from 'kandy';
const codecRemover = sdpHandlers.createCodecRemover(['VP8', 'VP9'])
const client = create({
call: {
sdpHandlers: [ <Your-SDP-Handler-Function>, ...]
}
})
In some scenarios it's necessary to remove certain codecs being offered by the SDK to the remote party. 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 SDK provides a codec removal handler creator that can be used for this purpose.
The SDP handlers are exposed on the entry point of the SDK. They need to be added to the list of SDP handlers via configuration on creation of an instance of the SDK.
SdpHandlerFunction:
The resulting SDP handler that will remove the codec.
import { create, sdpHandlers } from 'kandy';
const codecRemover = sdpHandlers.createCodecRemover(['VP8', 'VP9'])
const client = create({
call: {
sdpHandlers: [codecRemover]
}
})
Allows a user to subscribe to, and receive notifications for, sip events.
SipEvents functions are all part of the 'sip' namespace.
Update a subscription for a sip event.
(string)
The sip event subscription to update.
(Object)
| Name | Description |
|---|---|
userLists.subscribeUserList Array
|
The list of users to subcribe to. |
userLists.unsubscribeUserList Array
|
The list of users to unsubscribe from. If all users are unsubscribed from, the event subscription is removed completly. |
(Array?)
List of custom options provided as part of the subscription.
A change in SIP event subscriptions has occurred.
An error occurred while performing a SIP event action.
(Object)
| Name | Description |
|---|---|
params.error BasicError
|
The Basic error object. |
The Users feature allows access to user information for users within the same domain.
The functions in this module are namespaced under 'user'.
The User data object.
Type: Object
(string)
: 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 directory: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.
(string)
The User ID of the user.
Fetches information about the current User from directory. Compared to user.fetch API, this API retrieves additional user related information.
The SDK will emit a directory: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.
Retrieves information about a User, if available.
See the user.fetch and user.search APIs for details about making Users' information available.
(string)
The User ID of the 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.
Array<User>:
An array of all the User objects.
Searches the domain's directory for 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.
(Object)
The filter options for the search.
| Name | Description |
|---|---|
filters.userId string?
|
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. |
(Object?)
Sorting options.
| Name | Description |
|---|---|
options.sortBy string?
|
The User property to sort the results by. This can be any of the above listed filters. |
options.order string?
|
Order in which results are returned. Can be either "asc" or "desc". |
options.max number?
|
The maximum number of results to return. |
options.next string?
|
The pointer for a chunk of results, which may be returned from a previous query. |
The voicemail features are used to retrieve and view voicemail indicators.
Voicemail functions are all part of the 'voicemail' namespace.
Attempts to retrieve voicemail information from the server.
A voicemail:new event is emitted upon completion.
Returns voicemail data from the store.
A voicemail event has been received.
(Object)
An object containing voicemail info.
| Name | Description |
|---|---|
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 occured while attempting to retrieve voicemail data.
(Object)
| Name | Description |
|---|---|
params.error BasicError
|
The Basic error object. |