Skip to main content

Initializing and using the SDK

Getting token

After completing the installation phase, you must initialize the SDK with a profile token from the server and other necessary information.

Initializing

Create a global value of type VideoSDK.Builder.

    /** Video Call configuration object*/
private lateinit var videoBuilder: VideoSDK.Builder

Setting up the event listeners

Create a global AmaniVideoCallObserver object like below

private val videoCallObserver: AmaniVideoCallObserver = object : AmaniVideoCallObserver{
override fun onConnectionState(connectionState: ConnectionState) {
when (connectionState) {
ConnectionState.CONNECTING -> {
//Agent is connecting to the call
}

ConnectionState.FAILED -> {
//Connection is failed
}

ConnectionState.CONNECTED -> {
//Agent is connect to the video call
}

ConnectionState.DISCONNECTED -> {
//Agent is disconnected from call as unexpected situation like electricity gone
//or possible internet connection issues
}
}
}

override fun onException(exception: String) {
//Any exception during the call
}

override fun onUiEvent(
amaniVideoButtonEvents: AmaniVideoButtonEvents,
isActivated: Boolean
) {
when (amaniVideoButtonEvents) {
AmaniVideoButtonEvents.CALL_END -> {
//The call end button is clicked by mobile SDK user and call ended
}

AmaniVideoButtonEvents.CAMERA_SWITCH -> {
//The camera switch button is clicked by mobile SDK user and camera switched
}

AmaniVideoButtonEvents.MUTE -> {
//The mic mute button is clicked by mobile SDK user and mic muted
}

AmaniVideoButtonEvents.CAMERA_CLOSE -> {
//The camera close button is clicked by mobile SDK user and camera closed
}
}
}

override fun onRemoteEvent(
amaniVideoRemoteEvents: AmaniVideoRemoteEvents,
isActivated: Boolean
) {
when (amaniVideoRemoteEvents) {
AmaniVideoRemoteEvents.CALL_END -> {
//The call end button is clicked by studio agent side and call is ended
}

AmaniVideoRemoteEvents.CAMERA_SWITCH -> {
//The camera switch request button is clicked by studio agent. At this time
//you can ask user to switch camera or you can directly switch camera thanks to
//switch function @see VideoSDK.switchCamera()
}

AmaniVideoRemoteEvents.TORCH -> {
//The torch flash request button is clicked by studio agent. At this time
//you can ask user to enable flash or you can directly enable flash thanks to
//switch function @see VideoSDK.toggleTorch()
}
AmaniVideoRemoteEvents.CALL_ESCALATED -> {
//The event triggered when the studio requests the call
//to be transferred/forwarded to another agent. In this case, the call can be
//set to escalated true again and started as in the example.
}
}
}
}

Setting Video SDK Parameters

Configure the VideoSDK.Builder type object you created as follows.

videoBuilder = VideoSDK.Builder()
.nameSurname("Name Surname") //Mandatory field
.servers(
mainServerURL = VideoSDKCredentials.mainServerURL, //Mandatory field
stunServerURL = VideoSDKCredentials.stunServerURL, //Mandatory field
turnServerURL = VideoSDKCredentials.turnServerURL //Mandatory field
)
.authentication(
token = VideoSDKCredentials.token, //Mandatory field
userName = VideoSDKCredentials.userName, //Mandatory field
password = VideoSDKCredentials.password //Mandatory field
)
.remoteViewAspectRatio(
VideoSDK.RemoteViewAspectRatio.Vertical //Default is Vertical, non mandatory field
)
.audioOptions(
VideoSDK.AudioOptions.SpeakerPhoneOn //Default is SpeakerPhoneOn, non mandatory field
)
.userInterface( //Has default user interface, non mandatory function
cameraSwitchButton = R.drawable.ic_camera_switch,
cameraSwitchButtonBackground = R.drawable.oval_gray,
microphoneMuteButton = R.drawable.ic_mic_on,
microphoneMuteButtonEnabled = R.drawable.ic_mic_off,
microphoneMuteButtonBackground = R.drawable.oval_gray,
cameraCloseButton = R.drawable.ic_camera_on,
cameraCloseButtonEnabled = R.drawable.ic_camera_off,
cameraCloseButtonBackground = R.drawable.oval_gray,
callEndButton = R.drawable.call_end,
callEndButtonBackground = R.drawable.oval_red
)
.videoCallObserver(videoCallObserver) //Mandatory field
.build() //Mandatory function

Set the server urls (required)

Server urls provided by Amani

  • mainServerURL is socket server url
  • stunServerURL is stun server url
  • turnServerURL is turn server url
    .servers(
mainServerURL = VideoSDKCredentials.mainServerURL, //Mandatory field
stunServerURL = VideoSDKCredentials.stunServerURL, //Mandatory field
turnServerURL = VideoSDKCredentials.turnServerURL //Mandatory field
)

Set authentication parameters (required)

  • token is profile token generatad by Amani Api
  • userName is turnservers username
  • password is turnservers password
    .authentication(
token = VideoSDKCredentials.token, //Mandatory field
userName = VideoSDKCredentials.userName, //Mandatory field
password = VideoSDKCredentials.password //Mandatory field
)

Set observer (required)

We need to set observer what we defined in Setting up the event listeners

    .videoCallObserver(videoCallObserver) //Mandatory field

Start to use

We will use startCallVideoCall method to get a Fragment (it could be null check it out while using it). You can commit or navigate this fragment. For this, use the object as typed VideoSDK.Builder that we created Setting Video SDK Parameters to get Fragment.

     val callFragment: Fragment? = VideoSDK.startVideoCall(videoBuilder)
callFragment?.let {
replaceFragment(R.id.container, callFragment)
}

Extra Functions

We will cover the use of functions such as camera rotation and flash activation in the SDK. The main purpose of use of these functions is to use with a remote request by the Agent. The reason why these functions are given separately is to allow you to get permission from the user before a Flash or Camera translation request from the Agent. You can respect user permissions by using these functions if the user allows.

Camera Switch

VideoSDK.switchCamera(object : SwitchCameraObserver {
override fun onSuccess(cameraPosition: CameraPosition) {
//The camera is switched successfully
}

override fun onException(exception: Throwable) {
//Exception happened during the camera switch
}
})

Toggle Flash

VideoSDK.toggleTorch(object : ToggleTorchObserver {
override fun onSuccess(isEnabled: Boolean) {
//The camera flash is enabled successfully
//Note:If the current camera is front camera the flash will not be opened
}

override fun onError(error: Throwable) {
//Exception happened during the camera switch
}
})