SinchClient Class
The SinchClient is the Sinch SDK entry point.
It provides access to the feature classes in the Sinch SDK: MessageClient, and other in future. It is also used to configure user's and device's capabilities.
The user IDs that are used to identify users application specific. If the app already has a scheme for user IDs (email addresses, phone numbers, customer numbers, etc.), the same ID could be used when configuring the SinchClient.
Constructor
SinchClient
-
configObj
Parameters:
-
configObj
ObjectConfiguration options for Sinch
-
key
StringApplication key to use
-
capabilities
ObjectList of capabilities
-
[messaging]
Boolean optionalEnable IM by setting this to true -
[calling]
Boolean optionalEnable data calling by setting this to true -
[multiCall]
Boolean optionalEnable multiple concurrent calls by setting this to true -
[video]
Boolean optionalEnable video calling by setting this to true (Beta)
-
-
[supportActiveConnection]
Boolean optionalSupport the online capability, receiving notifications over an active connection in addition to push (where available)
-
[startActiveConnection]
Boolean optionalAutomatically support online capability & start connection to listen for IM and data calls
-
[onLogMessage]
Function optionalCallback to handle detailed log messages
-
Example:
//Create new sinchClient instance and start the client using credentials
var sinchClient = new SinchClient({key: 'someAppKey', capabilities: {messaging: true}};
sinchClient.start({username: 'some_user', password: 'user_password'};
//Use sinchClient to retrieve messageClient
var messageClient = sinchClient.getMessageClient();
//Create and send a new message
var message = messageClient.newMessage('recipient', 'message');
messageClient.send(message);
Item Index
Methods
config
-
credentialsObj
Configure Sinch application key and session id / secret.
Parameters:
-
credentialsObj
ObjectObject with application credentials.
-
[appKey]
String optionalApplication key.
-
[sessionId]
String optionalSession ID for authenticated user.
-
[secret]
String optionalSession secret for authenticated user.
-
[authServer]
String optionalCallback URL for authentication ticket, if not using default identity provider from Sinch.
-
Returns:
undefined
Example:
var sinchClient = Sinch
createCalloutVerification
-
[number]
-
[custom]
Create a Callout Verification for a particular sinchClient.
Parameters:
-
[number]
String optionalPhone number to verify, give in E.164 format (i.e. +1800123456)
-
[custom]
String optionalCustom string to pass to your backend through callback. Useful for identifying user session, or similar. Max size is 4 kbyte.
Returns:
Example:
var verification = sinchClient.createCalloutVerification(phoneNumber);
createSmsVerification
-
[number]
-
[custom]
Create a SMS Verification for a particular sinchClient.
Parameters:
-
[number]
String optionalPhone number to verify, give in E.164 format (i.e. +1800123456)
-
[custom]
String optionalCustom string to pass to your backend through callback. Useful for identifying user session, or similar. Max size is 4 kbyte.
Returns:
Example:
var verification = sinchClient.createSmsVerification(phoneNumber);
getCallClient
()
CallClient
Retrieve a CallClient for a particular sinchClient. Requires a sinchClient with calling capability set true.
Returns:
Example:
var callClient = sinchClient.getCallClient();
getMessageClient
()
MessageClient
Retrieve a MessageClient for a particular sinchClient. Requires a sinchClient with messaging capability set true.
Returns:
Example:
var messageClient = sinchClient.getMessageClient();
getSession
()
SessionObj
Retrieve session id and secret
Returns:
Object containing sessionId and sessionSecret.
Example:
var sessionObj = sinchClient.getSession();
sessionStorage['sinchSession'] = sessionObj;
getVersion
()
Retrieve the current version of the Sinch JS SDK
Returns:
version string
Example:
var version = sinchClient.getVersion();
log
-
message
-
promise
Sinch log function, calls developer supplied log handler and optionally report progress on a defer
Parameters:
-
message
String | ObjectThe message to log, can be object or string
-
promise
Q.promiseThe promise to notify
Returns:
undefined
log
-
message
Sinch log MXP function, calls developer supplied MXP log handler, for tracing MXP messages.
Parameters:
-
message
String | ObjectThe message to log, can be object or string
Returns:
undefined
newUser
-
signupObj
-
[success=console.info]
-
[fail=console.error]
Create a new user. Can either be chained or supplied with success/fail callbacks. A promise will always be returned, supplied callback functions will be called before chained functions.
Parameters:
-
signupObj
ObjectObject describing the new user, must contain one or more of username, email or number identity
-
[username]
String optionalDesired username as identity
-
[email]
String optionalDesired email as identity
-
[number]
String optionalDesired number as identity
-
password
StringRequested password
-
-
[success=console.info]
Function optionalCallback on Success
-
[fail=console.error]
Fail optionalCallback on Error
Returns:
promise which resolves with an authentication ticket on success, which can be supplied to the start method.
Example:
sinchClient.newUser({username: 'magnus', email: 'magnus@example.com', password: 'strongstuff'})
.then(function(ticket) {
//Things to do on success
sinchClient.start(ticket); //Start sinch using ticket from creating user
})
.fail(function(error) {
//Manage error (One/more identities may be taken, or password not strong enough, or other)
})
setUrl
-
urlObj
Configure Sinch application URL.
Parameters:
-
urlObj
ObjectObject with backend PAPI URL's.
-
[user]
String optionalBackend for managing users
-
[base]
String optionalBackend for basic PAPI actions
-
[portal]
String optionalBackend for portal specific
-
[reporting]
String optionalBackend for reports
-
[calling]
String optionalBackend for data calling
-
[messaging]
String optionalBackend for messages
-
Returns:
undefined
signApp
-
configObj
Add authorization header for non signed request, using only the application key for public / open functions.
Parameters:
-
configObj
ObjectObject describing the request.
-
headers
ObjectObject containing header fields (only 'Accept' is required)
-
Returns:
undefined
Example:
Sinch.signApp({
method: 'POST',
url: 'http://example.com/resource',
data: {...},
headers: {Accept: 'application/json'}
});
signSession
-
configObj
Add authorization header using "session"-method and return modified header object for signed session requests (fallback to non-signed application key). Can be sent using jQuery. If using AngularJS, intercept and sign requests before they are sent.
Parameters:
-
configObj
ObjectObject describing the request.
-
method
StringRequest method (GET, POST, PUT, DELETE).
-
url
StringRequest URL. Example:
users/email/magnus@sinch.com/authentication)
-
[data]
Object optionalRaw data object to be sent (if any)
-
headers
ObjectObject containing header fields (only 'Accept' is required)
-
Returns:
undefined;
Example:
Sinch.signSession({
method: 'POST',
url: 'http://example.com/resource',
data: {...},
headers: {Accept: 'application/json'}
});
signTicket
-
configObj
Add authorization header using "ticket"-method and return modified header object. Can be sent using jQuery. If using AngularJS, intercept and sign requests before they are sent.
Parameters:
-
configObj
ObjectObject describing the request.
-
[data]
Object optionalRaw data object to be sent (if any)
-
headers
ObjectObject containing header fields (only 'Accept' is required)
-
Returns:
headers
Example:
Sinch.signTicket({
method: 'POST',
url: 'http://example.com/resource',
data: {...},
headers: {Accept: 'application/json'}
});
start
-
loginObj
-
[success=console.info]
-
[fail=console.error]
Initialize the SDK using a loginObject or supplied ticket. Can either be chained or supplied with success/fail callbacks. A promise will always be returned, supplied callback functions will be called before chained functions.
Parameters:
-
loginObj
ObjectObject containing details for authentication or authenticated object from creating new user or third party authentication.
-
[email]
String optionalAuthenticate using email (password is mandatory when supplying this)
-
[number]
String optionalAuthenticate using number (password is mandatory when supplying this)
-
[username]
String optionalAuthenticate using username (password is mandatory when supplying this)
-
[password]
String optionalAuthenticate with password
-
[userTicket]
String optionalAuthentication ticket signed with your app secret. User identity or password is not required if this is supplied together with the user profile.
-
-
[success=console.info]
Function optionalCallback on Success
-
[fail=console.error]
Fail optionalCallback on Error
Returns:
promise which resolves to null on success
Example:
sinchClient.start({username: 'magnus', password: 'strongstuff'})
.then(function() {
//Do things on success, like show UI, etc
})
.fail(function() {
//Handle error, such as incorrect username/password
});
startActiveConnection
()
Start connection for messages and data call signalling.
Returns:
promise which resolves when connection is active.
Example:
sinchClient.startActiveConnection();
stopActiveConnection
()
Stop connection for messages and data call signalling.
Returns:
undefined
Example:
sinchClient.stopActiveConnection();
terminate
()
Terminate session, invalidates sinchClient and this object is considered stale; instance can't be reused.
Returns:
undefined