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 CallController, AudioController, and VideoController.
const sinchClient = Sinch.getSinchClientBuilder()
.applicationKey("<application key>")
.environmentHost("ocra.api.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.
- The term Ocra in the hostname
ocra.api.sinch.comis the name of the Sinch API that SDK clients target.
Before starting, add a client listener (see SinchClientListener reference):
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();When SinchClient starts with a given user ID, you must provide an authorization token (JWT) to register with Sinch. Implement SinchClientListener.onCredentialsRequired() and supply a JWT signed with the Application Secret.
The reference apps include a JWT helper showing how to create and sign the token with the Application Secret.
See Authentication & Authorization for details.
Do not embed the Application Secret in a production app. Implement the required functionality on your backend and fetch a signed registration token when required.
When you’re done, stop the client. If it’s listening for incoming events, stop listening as well. After terminate() any object retrieved from the client (CallClient, AudioController, etc.) is considered invalid.
Terminating the client:
sinchClient.terminate();