Sinch Client
The SinchClient is the Sinch SDK entry point. It's used to configure the user’s and device’s capabilities, as well as to provide access to feature classes such as the CallClient, MessageClient and AudioController.
Create a SinchClient
// Instantiate a SinchClient using the SinchClientBuilder.
const sinchClient = Sinch.getSinchClientBuilder().applicationKey("<application key>")
.environmentHost("clientapi.sinch.com")
.userId("<user id>")
.build();
- The Application Key is obtained from the Sinch Developer Dashboard - Apps .
- The User ID should uniquely identify the user on the particular device.
Note: All listener callbacks emitted from the Sinch SDK are invoked on the same thread that the call to SinchClientBuilder.build
is made on. If the invoking thread is not the main-thread, it needs to have an associated Looper
.
Specify capabilities
The SinchClient can be configured to enable or disable certain functionality. Please see the Reference for a comprehensive description of each capability.
The following example shows how to setup the client with voice calling enabled.
// Enable push notifications.
sinchClient.setSupportManagedPush();
Note
If the application is meant to only make outgoing calls but not receive incoming calls, don’t call
setSupportManagedPush
. Outgoing calls can be made after calling the start method.
Start the Sinch client
Before starting the client, add a client listener (see Reference documentation):
sinchClient.addListener({
onClientStarted: (client) => {
// sinch client started successfully
},
onClientFailed: (client, error) => {
// sinch client start failed
},
onCredentialsRequired: (client, registrationCallback) => {
// registration required, get jwt token for user and register
}
});
sinchClient.start();
Terminate the Sinch client
When the app is done using the SinchClient, it should be stopped. If the client is currently listening for incoming events, it needs to stop listening as well. After terminate
is called, any object retrieved directly from the client object that's, CallClient
, MessageClient
, and AudioController
) is considered invalid.
Terminating the client:
sinchClient.terminate();