API Docs for: 1.4.7
Show:

SinchClient Class

Defined in: src/main.js:12
Module: Sinch

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
)

Defined in src/main.js:12

Parameters:

  • configObj Object

    Configuration options for Sinch

    • key String

      Application key to use

    • capabilities Object

      List of capabilities

      • [messaging] Boolean optional
        Enable IM by setting this to true
      • [calling] Boolean optional
        Enable data calling by setting this to true
      • [multiCall] Boolean optional
        Enable multiple concurrent calls by setting this to true
      • [video] Boolean optional
        Enable video calling by setting this to true (Beta)
    • [supportActiveConnection] Boolean optional

      Support the online capability, receiving notifications over an active connection in addition to push (where available)

    • [startActiveConnection] Boolean optional

      Automatically support online capability & start connection to listen for IM and data calls

    • [onLogMessage] Function optional

      Callback 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);

Methods

config

(
  • credentialsObj
)
protected

Defined in src/main.js:156

Configure Sinch application key and session id / secret.

Parameters:

  • credentialsObj Object

    Object with application credentials.

    • [appKey] String optional

      Application key.

    • [sessionId] String optional

      Session ID for authenticated user.

    • [secret] String optional

      Session secret for authenticated user.

    • [authServer] String optional

      Callback URL for authentication ticket, if not using default identity provider from Sinch.

Returns:

undefined

Example:

    var sinchClient = Sinch

createCalloutVerification

(
  • [number]
  • [custom]
)
Verification

Defined in src/main.js:625

Create a Callout Verification for a particular sinchClient.

Parameters:

  • [number] String optional

    Phone number to verify, give in E.164 format (i.e. +1800123456)

  • [custom] String optional

    Custom 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]
)
Verification

Defined in src/main.js:611

Create a SMS Verification for a particular sinchClient.

Parameters:

  • [number] String optional

    Phone number to verify, give in E.164 format (i.e. +1800123456)

  • [custom] String optional

    Custom 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

Defined in src/main.js:591

Retrieve a CallClient for a particular sinchClient. Requires a sinchClient with calling capability set true.

Returns:

Example:

var callClient = sinchClient.getCallClient();

getMessageClient

() MessageClient

Defined in src/main.js:571

Retrieve a MessageClient for a particular sinchClient. Requires a sinchClient with messaging capability set true.

Returns:

Example:

var messageClient = sinchClient.getMessageClient();

getSession

() SessionObj

Defined in src/main.js:390

Retrieve session id and secret

Returns:

SessionObj:

Object containing sessionId and sessionSecret.

Example:

var sessionObj = sinchClient.getSession();
sessionStorage['sinchSession'] = sessionObj;

getVersion

()

Defined in src/main.js:692

Retrieve the current version of the Sinch JS SDK

Returns:

version string

Example:

var version = sinchClient.getVersion();

log

(
  • message
  • promise
)
protected

Defined in src/main.js:184

Sinch log function, calls developer supplied log handler and optionally report progress on a defer

Parameters:

  • message String | Object

    The message to log, can be object or string

  • promise Q.promise

    The promise to notify

Returns:

undefined

log

(
  • message
)
protected

Defined in src/main.js:201

Sinch log MXP function, calls developer supplied MXP log handler, for tracing MXP messages.

Parameters:

  • message String | Object

    The message to log, can be object or string

Returns:

undefined

newUser

(
  • signupObj
  • [success=console.info]
  • [fail=console.error]
)
chainable async

Defined in src/main.js:404

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 Object

    Object describing the new user, must contain one or more of username, email or number identity

    • [username] String optional

      Desired username as identity

    • [email] String optional

      Desired email as identity

    • [number] String optional

      Desired number as identity

    • password String

      Requested password

  • [success=console.info] Function optional

    Callback on Success

  • [fail=console.error] Fail optional

    Callback 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
)
protected

Defined in src/main.js:213

Configure Sinch application URL.

Parameters:

  • urlObj Object

    Object with backend PAPI URL's.

    • [user] String optional

      Backend for managing users

    • [base] String optional

      Backend for basic PAPI actions

    • [portal] String optional

      Backend for portal specific

    • [reporting] String optional

      Backend for reports

    • [calling] String optional

      Backend for data calling

    • [messaging] String optional

      Backend for messages

Returns:

undefined

signApp

(
  • configObj
)
protected

Defined in src/main.js:361

Add authorization header for non signed request, using only the application key for public / open functions.

Parameters:

  • configObj Object

    Object describing the request.

    • headers Object

      Object 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
)
protected

Defined in src/main.js:271

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 Object

    Object describing the request.

    • method String

      Request method (GET, POST, PUT, DELETE).

    • url String

      Request URL. Example: users/email/magnus@sinch.com/authentication)

    • [data] Object optional

      Raw data object to be sent (if any)

    • headers Object

      Object 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
)
Object protected

Defined in src/main.js:332

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 Object

    Object describing the request.

    • [data] Object optional

      Raw data object to be sent (if any)

    • headers Object

      Object containing header fields (only 'Accept' is required)

Returns:

Object:

headers

Example:

Sinch.signTicket({
    method: 'POST',
    url: 'http://example.com/resource',
    data: {...},
    headers: {Accept: 'application/json'}
});

start

(
  • loginObj
  • [success=console.info]
  • [fail=console.error]
)
chainable async

Defined in src/main.js:451

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 Object

    Object containing details for authentication or authenticated object from creating new user or third party authentication.

    • [email] String optional

      Authenticate using email (password is mandatory when supplying this)

    • [number] String optional

      Authenticate using number (password is mandatory when supplying this)

    • [username] String optional

      Authenticate using username (password is mandatory when supplying this)

    • [password] String optional

      Authenticate with password

    • [userTicket] String optional

      Authentication 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 optional

    Callback on Success

  • [fail=console.error] Fail optional

    Callback 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

()

Defined in src/main.js:647

Start connection for messages and data call signalling.

Returns:

promise which resolves when connection is active.

Example:

sinchClient.startActiveConnection();

stopActiveConnection

()

Defined in src/main.js:671

Stop connection for messages and data call signalling.

Returns:

undefined

Example:

sinchClient.stopActiveConnection();

terminate

()

Defined in src/main.js:240

Terminate session, invalidates sinchClient and this object is considered stale; instance can't be reused.

Returns:

undefined