|
|
# Configuring and Initializing the Listeners.
|
|
|
|
|
|
The ListenersProvider Class interacts with the SIPProvider to communicate with the UI or the Foreground processes. You can set the Listeners in your front end Activites.
|
|
|
|
|
|
**The SDK listeners:** This sdk has two sdk Listener Interfaces . **SDKServiceListener** and **SDKSipListener**.
|
|
|
|
|
|
1. **SDKServiceListener:** This interface is used to declare the incoming call id. ListenerProvider.sdkServiceListener is an Interface with one abstract method. The service or Activity that will be waiting for incoming calls must have this initialized in the following way. It must be initialized in a service or Activity that waits for incoming calls. This interface should be implemented in the following way in the Activity of your app so that you can use the Callid and CallerID to accept calls or to show from whom the incoming call is.
|
|
|
|
|
|
>In **Kotlin**
|
|
|
```kotlin
|
|
|
ListenersProvider.sdkServiceListener = object : SDKServiceListener{
|
|
|
override fun startIncomingCall(callid: String, callerID: String) {
|
|
|
TODO("Use the callid to accept or decline the incoming call " +
|
|
|
"and callerID in the UI to show who is calling")
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
>In **Java**
|
|
|
```java
|
|
|
istenersProvider.sdkServiceListener = new SDKServiceListener() {
|
|
|
@Override
|
|
|
public void startIncomingCall(@NonNull String callid, @NonNull String callerID) {
|
|
|
//TODO "Use the callid to accept or decline the incoming call
|
|
|
//and callerID in the UI to show who is calling"
|
|
|
}
|
|
|
};
|
|
|
```
|
|
|
|
|
|
|
|
|
2. **SDKSIPListener:** Just as the previous interface needs to be implemented in the service or Acitivity that will launch incoming calls , this one has to be implemented in any Activity that is currently using the call service in any way. This interface is designed to be a communication channel between back and front side of the application. This inteface is most useful to have in an Activity that has direct control over the relevant call related UI. This interface should be implemented the following way.
|
|
|
>in **Kotlin**
|
|
|
|
|
|
```kotlin
|
|
|
ListenersProvider.sdksipListener = object : SDKSIPListener {
|
|
|
override fun updateCallState(callState: String) {
|
|
|
//todo This method is called to communicate the current call state to the UI. See more about CallStates below.
|
|
|
}
|
|
|
|
|
|
override fun updateDuration(duration: String) {
|
|
|
//todo Updates Call Duration in real time. Useful in UI to show the user how much time is spent in the call.
|
|
|
}
|
|
|
|
|
|
override fun updateCallState(callState: CallState) {
|
|
|
//todo Same as the the Update callState before
|
|
|
|
|
|
}
|
|
|
|
|
|
override fun callStartOrStop(start: Boolean, duration: String) {
|
|
|
//todo This method is invoked when the Ringing is stopped. If the Call has been disconnected from the other side this method will have start = false.
|
|
|
}
|
|
|
|
|
|
override fun incomingCallIdDeclaration(callid: String) {
|
|
|
//todo Declares the Incoming callId.
|
|
|
}
|
|
|
|
|
|
override fun updateDisplayStatus(displayStatus: DisplayStatus) {
|
|
|
//todo Can show the display status like Registered.InvalidLogIn or Registering etc. More about it below.
|
|
|
}
|
|
|
|
|
|
override fun onMissedCall(s: String, b: Boolean) {
|
|
|
//todo When one Peer to Peer call is missed by the user then this method is called. Can be helpful to keep log of missed calls or create missed call alerts
|
|
|
}
|
|
|
|
|
|
override fun updateCallInfo(callParameters: CallParameters) {
|
|
|
//todo Updates the callParameters. callParameters stores all kinds of data useful to keep logs.
|
|
|
}
|
|
|
|
|
|
override fun updateBalance(balance: String) {
|
|
|
//todo Useful to show balance in the UI
|
|
|
}
|
|
|
|
|
|
override fun disconnectedErrorCode(i: Int) {
|
|
|
//todo If the call gets disconnected for some network reason then this method provides the error code
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
>in **Java** *(See Kotlin code for details of each overwritten function)*
|
|
|
```Java
|
|
|
|
|
|
ListenersProvider.sdksipListener = new SDKSIPListener() {
|
|
|
@Override
|
|
|
public void updateCallState(@NonNull String callState) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateDuration(@NonNull String duration) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateCallState(@NonNull CallState callState) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void callStartOrStop(boolean start, @NonNull String duration) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void incomingCallIdDeclaration(@NonNull String callid) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateDisplayStatus(@NonNull DisplayStatus displayStatus) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onMissedCall(@NonNull String s, boolean b) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateCallInfo(@NonNull CallParameters callParameters) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updateBalance(@NonNull String balance) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void disconnectedErrorCode(int i) {
|
|
|
|
|
|
}
|
|
|
};
|
|
|
|
|
|
```
|
|
|
3. **Important** ListenersProvider. sdksipListener and ListenersProvider. sdksipListener must be re-initialized in relevant Activities if any other subsequent but now dead activities had re-assigned the these interfaces. These act as bridges between UI and the core functionalities. So if Any of these interfaces is not connected to UI, UI can not get any info on what's going on inside.
|
|
|
|
|
|
4. See [Others Guide](others-guide) for more information about Callstates , CallParameters , DisplayStatus etc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|