kandy-js
3.0.0-beta
- createKandy
- configs ▸
-
Events
▸
- Static members
- .on
- .off
- .subscribe
- .unsubscribe
-
Authentication
▸
- Static members
- .connect
- .disconnect
- .updateConnection
- .getUserInfo
- .getConnection
- .getServices
- .subscriptionStates
- Events
- ⓔ auth:change
- ⓔ auth:error
- Calls ▸
- Media ▸
-
CallHistory
▸
-
Messaging
▸
- Static members
- .get
-
Conversation
▸
- Static members
- .createMessage
- .clearMessages
- .getMessages
- .subscribe
- .fetchMessages
-
Message
▸
- Static members
- .send
-
Presence
▸
- Static members
- .update
- .get
- .fetch
- .subscribe
- .unsubscribe
-
Voicemail
▸
-
SipEvents
▸
- Static members
- .subscribe
- .update
- .unsubscribe
- .getDetails
-
Connectivity
▸
- Static members
- .getSocketState
- .enableConnectivityChecking
- Events
- ⓔ ws:change
-
Notification
▸
- Static members
- .registerPush
- .deregisterPush
- .enableWebsocket
-
Users
▸
- Static members
- .fetch
- .fetchDetails
- .get
- .getSelf
- Contacts ▸
-
Logger
▸
- Static members
- .levels
- KandyError
createKandy
The Kandy.js SDK Factory. Create an instance of the SDK by calling this factory with the the desired configurations.
(Object)
The configuration object.
// Instantiate the SDK.
let kandy = createKandy({
authentication: { ... },
logs: { ... },
...
});
// Use the Kandy API.
kandy.on( ... );
configs
The configuration object. This object defines what different configuration values you can use when instantiating the SDK.
Configuration options for the Logs feature.
(Object)
Logs configs.
Name | Description |
---|---|
logs.logLevel String
(default debug )
|
Log level to be set. See
kandy.logger.levels
.
|
logs.logActions Object?
|
Extra configs when logLevel is at DEBUG+ levels. Set this to false to not log actions. |
logs.logActions.actionOnly Boolean
(default true )
|
Only show the action payload. |
logs.logActions.flattenActions Boolean
(default true )
|
Display the logged actions as a string. |
logs.logActions.collapsed Boolean
(default false )
|
Have logged objects be collapsed. |
logs.logActions.diff Boolean
(default false )
|
Display the diff for each action log. |
logs.enableFcsLogs Boolean
(default true )
|
Enable the detailed call logger. |
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 |
Configuration options for the Authentication feature.
(Object)
Authentication configs.
Name | Description |
---|---|
authentication.subscription Object
|
|
authentication.subscription.protocol string
(default https )
|
Protocol to be used for subscription requests. |
authentication.subscription.server string
(default multispidr.kandy.io )
|
Server to be used for subscription requests. |
authentication.subscription.port Number
(default 443 )
|
Port to be used for subscription requests. |
authentication.subscription.server string
(default multispidr.kandy.io )
|
Server 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. |
authentication.websocket Object
|
|
authentication.websocket.protocol string
(default wss )
|
Protocol to be used for websocket notifications. |
authentication.websocket.server string
(default multiwebsocket.kandy.io )
|
Server to be used for websocket notifications. |
authentication.websocket.port Number
(default 443 )
|
Port to be used for websocket notifications. |
Configuration options for the call feature.
(Object)
The call configuration object.
Name | Description |
---|---|
call.callDefaults Object?
|
Default options to be used when making/answering a call. |
call.chromeExtensionId string?
|
ID of the Kandy Screenshare Extension being used for screenshare of Google Chrome. |
call.webrtcdtls boolean
(default true )
|
Whether to enable the webRTC DTLS setting for calls. |
Configuration options for the Connectivity feature.
(Object)
Connectivity configs.
Name | Description |
---|---|
connectivity.method String
(default 'keepAlive' )
|
The method of connectivity checking to use. Either 'keepAlive' or 'pingPong'. |
connectivity.pingInterval Number
(default 5000 )
|
Time in between websocket ping attempts (milliseconds). |
connectivity.reconnectLimit Number
(default 5 )
|
Number of failed reconnect attempts before reporting an error. |
connectivity.reconnectDelay Number
(default 5000 )
|
Base time between websocket reconnect attempts (milliseconds). |
connectivity.reconnectTimeMultiplier Number
(default 1 )
|
Reconnect delay multiplier for subsequent attempts. |
connectivity.reconnectTimeLimit Number
(default 640000 )
|
Maximum time delay between reconnect attempts (milliseconds). |
connectivity.reconnectCount Number
(default 0 )
|
Initial reconnect count. |
connectivity.autoReconnect Boolean
(default true )
|
Flag to determine whether Kandy will attempt to automatically reconnect 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 Kandy should check connectivity. |
Events
Authentication
Kandy's 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 to Kandy with user credentials.
kandy.connect({
username: 'alfred@example.kandy.io',
password: '********'
});
Disconnects from the backend. This will close the websocket and you will stop receiving events.
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 kandy.getConnection().
There was an error with authentication.
(Object)
Name | Description |
---|---|
params.error KandyError
|
The Kandy error object. |
Calls
Kandy's call feature is used to make audio and video calls between Kandy users, or to PSTN phones and SIP endpoints. Kandy will store meta-information about each call made during the current session in internal state, which can be accessed via the call getter functions.
Call functions are namespaced beneath 'call' on the returned Kandy object.
States of a call.
(string)
: The call is on-going.
(string)
: The call has been established and is waiting for a user response.
(string)
: The call has been terminated.
(string)
: The call has been put on hold locally.
(string)
: The call has been put on hold remotely.
kandy.on('call:stateChange', function(callInfo) {
if(callInfo.state === kandy.call.states.ENDED) {
// Call has ended.
}
});
State of the media connection within a call.
(string)
: A new media connection process has started.
(string)
: Media is searching for a connection.
(string)
: Media has found a connection, but may still be searching for a better connection to use.
(string)
: Media has finished searching and been established. Audio/video should now be flowing on the call.
(string)
: Media was not able to find a connection. Audio/video will not flow.
(string)
: The media connection has lost its connection and is trying to recover.
(string)
: The media connection has shut down.
Start an outgoing call.
(string)
Full user ID of the call recipient.
(Object?)
Call options.
Name | Description |
---|---|
options.isVideoEnabled boolean
(default true )
|
Whether to enable video during the call. If false, you cannot start video mid-call. |
options.contact Object?
|
Object containing firstName and lastName of caller. |
options.sendInitialVideo boolean
(default false )
|
Whether to start the call sending the local video stream. |
options.isAudioEnabled boolean
(default true )
|
Whether to enable audio during the call. Setting this to false will disable audio for the call. |
options.webrtcdtls boolean
(default true )
|
Whether to enable DTLS for WebRTC calls. |
options.videoResolution Object?
|
The object to configure the local video resolution. |
options.videoResolution.height number?
|
The height in pixels of the local video. |
options.videoResolution.width number?
|
The width in pixels of the local video. |
options.remoteVideoContainer HTMLElement?
|
The HTML element to use as a container for the remote video. |
options.localVideoContainer HTMLElement?
|
The HTML element to use as a container for the local video. |
options.normalizeAddress boolean
(default false )
|
Whether to enable normalization of callee address. |
string
:
Id of the outgoing call.
let remoteContainer = document.getElementById('remote-container');
// Start a video call that only shows the remote media (not local).
let callId = kandy.call.make('sampleUser@kandy.io', {
isVideoEnabled: true,
sendInitialVideo: true,
remoteVideoContainer: remoteContainer
});
Answer an incoming call.
(string)
The ID of the call to answer.
(Object?)
Call options.
Name | Description |
---|---|
options.isVideoEnabled boolean?
|
Whether to enable video during the call. If false, you cannot start video mid-call. |
options.sendInitialVideo boolean?
|
Whether to start the call sending the local video stream. |
options.isAudioEnabled boolean
(default true )
|
Whether to enable audio during the call. Setting this to false will disable audio for the call. |
options.videoResolution Object?
|
The object to configure the local video resolution. |
options.videoResolution.height number?
|
The height in pixels of the local video. |
options.videoResolution.width number?
|
The width in pixels of the local video. |
options.localVideoContainer HTMLElement?
|
The HTML element to use as a container for the remote video. |
options.remoteVideoContainer HTMLElement?
|
The HTML element to use as a container for the local video. |
Start local video stream for an ongoing call.
(string)
Id of the call being acted on.
(Object?)
options Options for the video stream.
Name | Description |
---|---|
options.videoResolution Object?
|
videoResolution The video resolution configuation object. |
options.videoResolution.height number?
|
height The height of the outoing video in pixels. |
options.videoResolution.width number?
|
width The width of the outoing video in pixels. |
Starts sharing a screen over a call.
(string)
Id of the call being acted on.
(Object)
Name | Description |
---|---|
options.mediaSourceId string
|
Id of the media screen to share. |
options.height Number
(default 768 )
|
The height of the video stream to send. |
options.width Number
(default 1024 )
|
The width of the video stream to send. |
options.frameRate Number
(default 15 )
|
The number of frames per second to request. |
A call's state has changed.
(Object)
Name | Description |
---|---|
params.callId string
|
The Id of the call. |
params.state string
|
New state of the call. |
params.transition Object
|
Information about the state change. |
params.transition.code number
|
Code representing the reason for the state change. |
params.transition.reasonText string
|
Explanation of the status code. |
params.transition.oldState string
|
The previous state of the call. |
kandy.on('call:stateChange', function(params) {
// We are now in call with another user, so update our app to show it.
if(params.state === kandy.call.states.IN_CALL) {
renderCall(kandy.call.getById(params.callId));
}
});
An error has occurred with a call.
(Object)
Name | Description |
---|---|
params.callId string
|
The id of the call. |
params.error KandyError
|
The Kandy error object. |
Media
Kandy's media features are used to control WebRTC Media Devices.
Media functions are namespaced beneath 'media' on the returned Kandy object.
Sets the selected devices as the default devices. They will be used for audio output for future calls. Changing speaker is supported on browser's that support HTMLMediaElement.setSinkId().
// Set only the default microphone and camera.
kandy.media.setDefaultDevices({
camera: 'abc123...',
microphone: 'def456...'
});
Retrieves the available media devices for use.
Starts the local video stream and displays it to the user.
(HTMLElement?)
The container to use for local video.
``` javascript
var container = document.getElementById('local-video');
kandy.media.startPreviewVideo(container);
```
Stops the local video stream created in startPreviewVideo
.
An error has occurred when changing local video preview status.
(Object)
Name | Description |
---|---|
params.error KandyError
|
Information about the error. |
Media support has been checked.
CallHistory
Kandy's call history feature is used to retrieve and inspect the authenticated users call logs.
CallHistory functions are namespaced beneath 'call.history' on the returned Kandy object.
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.
kandy.on('callHistory:change', function() {
// Get all call logs when they've been updated.
let callLogs = kandy.call.history.get();
});
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 KandyError
|
The Kandy error object. |
Messaging
Kandy's Messaging features revolve around a "conversation" structure. Kandy stores the conversations and its messages, and returns conversation objects when requested.
See the "Conversation" and "Message" sections of the documentation for more details.
Messaging functions are namespaced beneath 'conversation' on the returned Kandy object. Ex: kandy.conversation.get('id').
Create and return a conversation object. If successfull, the event 'conversations:change' will be emitted. If a conversation with the given user already exists in the store, then no new one will be created. If no conversation exists, then a new conversation will be created in the store.
(string)
The Id of user for whom to create the conversation.
Conversation
:
A Conversation object.
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.
An error occured with messaging.
(Object)
Name | Description |
---|---|
params.error KandyError
|
The Kandy error object. |
Conversation
A Conversation object represents a conversation between either two users, or a user and a group. A Conversation can spawn messages via the conversations createMessage() function.
Create and return a message object. You must provide a text
part as demonstrated in the example.
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.
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.
Message
A Message object represents an inidividual message. Messages in Kandy 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.
Sends the message.
Presence
Kandy's presence functions are used to update the authenticated users presence on the server, as well as retrieve other users presence information.
Presence functions are namespaced beneath 'presence' on the returned Kandy object.
Update the presence for the current user
Get (from state) the presence for the given user(s)
(string?)
A user id or an array of user ids.
any
:
An array of presence objects containing:
userId,
loading,
status,
activity,
and note.
Or, if a userId was provided instead of an array, returns
the corresponding presence object or
undefined
.
Received a presence event.
An error occured with presence.
(Object)
Name | Description |
---|---|
params.error KandyError
|
The Kandy error object. |
Voicemail
Kandy's mwi (Message Waiting Indicator) features are used to retrieve and view voicemail indicators.
Voicemail functions are namespaced beneath 'voicemail' on the returned Kandy object.
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 KandyError
|
The Kandy error object. |
SipEvents
Allows a user to subscribe to, and receive notifications for, sip events.
SipEvents functions are namespaced beneath 'sip' on the returned Kandy object.
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 KandyError
|
The Kandy error object. |
Connectivity
Kandy's connection feature is used to connect and maintain connections between the SDK and one or more backend servers.
Connectivity functions are namespaced beneath 'connectivity' on the returned Kandy object.
Notification
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 KandyError
|
The Kandy error object. |
params.channel string
|
The channel for the notification. |
Users
Users functions are namespaced beneath 'users' on the returned Kandy object.
Contacts
Contacts functions are namespaced beneath 'contacts' on the returned Kandy object.
Refreshes the contacts in the state. This will get new contacts from the server.
Add a contact to a user's personal address book.
(Object)
The contact object.
Name | Description |
---|---|
contact.userId string
|
The userId for the contact |
contact.primaryContact string
|
The primary userId for the contact |
contact.id number
|
The id number by which this user is indexed in your address book |
contact.friendStatus boolean?
|
Indicates whether or not the contact is a friend of the user |
contact.username string?
|
The contact's username, shortened from their userId |
contact.firstName string?
|
The contact's first name |
contact.lastName string?
|
The contact's last name |
contact.nickname string?
|
The contact's nickname |
contact.email string?
|
The contact's email address |
contact.homePhone string?
|
The contact's home phone number |
contact.workPhone string?
|
The contact's work phone number |
contact.mobilePhone string?
|
The contact's mobile phone number |
contact.fax string?
|
The contact's fax number |
contact.pager string?
|
The contact's pager number |
contact.groupList Array?
|
A list of groups associated with the contact |
Logger
The internal logger used to provide information about the SDK's behaviour.
Provide a log level as part of the SDK configuration (see configs.logs
) to use the logger.
Possible levels for the SDK logger.
(string)
: Logs nothing.
(string)
: Only log 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.
KandyError
The Kandy error object. Provides information about an error that occurred in the SDK.