Skip to main content

Starting Video Help

Diyalog Platform offers live assistance to your customers through your mobile application with video calls.

You can download full simple video call android project from SimpleVideoCall link.

First of all, you need to know the flow about video call help in Diyalog platform for anonymous users. Anonymous user means you can connect logged in or not logged in user with your representatives.

The flow is like below :

  1. Your app calls the DiyalogSDK startVideoCallWithAttachedDataInBackground method.
  2. startVideoCallWithAttachedDataInBackground connects Diyalog Server and server will add your video call request to your representative queue then return to sdk about the result.
  3. startVideoCallWithAttachedDataInBackground works asyncronously and result of the method call will return to your app in a callback method.
  4. If inserting queue successfull then DiyalogSDK waits in background without showing any screen in your mobile app until a representative connecting . Therefore, you should show your wait screen thaht showing a representative will connect soon.
  5. If any represenatative connecting, DiyalogSDK will automatically starts video call and come into foreground.
  6. After you retrun succecsfull result from startVideoCallWithAttachedDataInBackground function, You can follow all stages of the video call by subscribing CallState in DiyalogSDK. So, you should subscribe to CallState by calling subscribeToCallStateWithTxCodeEvent in DiyalogSDK.

According to your business needs, a video call can be started at the relevant stage of your application as follows. When the following method is called, the DiyalogSDK in the background will transmit the call request to the call center over the server, and it will be waiting in the background until a representative from the call center initiates the call. During this process, the standby screen should be displayed in your mobile application. Customers who are tired of waiting should be allowed to cancel the transaction by adding a cancellation option to the waiting screen.

public void startVideoCallWithAttachedDataInBackground(Activity context,
Long idNumber,
String customerId,
String customerName,
Long customerPhone,
String txCode,
ArrayList<AttachedData> attachedDataList,
VideoCallResult videoCallResult)
Parameters
context (Activity)
Activity that this method called from.
idNumber (Long)
National ID number of the customer.
customerId (String) Customer id number. This can be real of candidate customer id.
customerName (String)
Opsiyoneldir.
Name of the customer. This paramater is optional. It can be set null.
customerPhone (Long)
Opsiyoneldir.
Phone number of the customer. This paramater is optional. It can be set null.
txCode (String) This field is a parameter used only in the mobile client. The main application can distinguish the callState events of the its video calls in from other call. CallState events related to the conversation status are returned to the main application with this txcode parameter. It is in no way migrated to the server or agent application.
attachedData (ArrayList of AttachedData)
Opsiyoneldir.
With this parameter, you can send the data you want to the agent application. The Diyalog server transmits the data in the key-value array in this parameter to the Agent application. The data transmitted in this area is not stored on the Diyalog servers, only transmitted.
videoCallResult (VideoCallResult) startVideoCallWithAttachedDataInBackground method is an asynchronous method and sends the result (information that the call request has been started) to your application with this callback method.

You can find the detail about VideoCallResult class

public interface VideoCallResult {
void success();
void failure(VideoCallError videoCallError);
}
public class VideoCallError {
public static final String IDNUMBER_SHOULD_BE_PASSED = "DLGEXCPINP_IDNUMBER";
public static final String CUSTOMERID_SHOULD_BE_PASSED = "DLGEXCPINP_CUSTOMER_ID";
public static final String EXCEPTION_IN_AUTH_REQUEST = "DLGEXCP_AUTH_REQUEST";
private String errorCode;
private String errorMsg;
public VideoCallError(String errorCode, String errorMsg) {
this.errorCode = errorCode;
this.errorMsg = errorMsg;
}
public String getErrorCode() {
return errorCode;
}
public String getErrorMsg() {
return errorMsg;
}
}

You can use startVideoCallWithAttachedDataInBackground method as shown in below code. First of all, you need to create an ArrayList that takes the data you want to pass in AttachedData class.

import im.diyalog.core.AttachedData;
..
ArrayList<AttachedData> attachedData = new ArrayList<AttachedData>();
attachedData.add(new AttachedData("dataName1","dataValue1"));
attachedData.add(new AttachedData("dataName2","dataValue2"));
attachedData.add(new AttachedData("dataName3","dataValue3"));
attachedData.add(new AttachedData("dataName4","dataValue4"));

Then you need to pass this data in the attachedDataList parameter of the startVideoCallWithAttachedDataInBackground method.

public void startVideoCallWithAttachedDataInBackground(Activity context,
Long idNumber,
String customerId,
String customerName,
Long customerPhone,
String txCode,
ArrayList<AttachedData> attachedDataList,
VideoCallResult videoCallResult)

If you get success as a videoCallResult from the startVideoCallWithAttachedDataInBackground method, you need to subscribe to the event mechanism where you can follow the status of the call.

public void subscribeToCallStateWithTxCodeEvent(
ValueChangedListener<CallStateEvent> listener
)
public class CallStateEvent {
private String state;
private String txCode;
public CallStateEvent(String state, String txCode) {
this.state = state;
this.txCode = txCode;
}
public String getState() {
return state;
}
public String getTxCode() {
return txCode;
}
}

CallStates that can receive from DiyalogSDK after subscribe as follows:

"RINGING" : Phone is calling "CONNECTING" : Call accepted by both peers and Webrtc session is creating. "IN_PROGRESS" : Call in progress "ENDED" : Call ended.
"NO_CALL" : Initial state. No call active.
"CALL_ACTIVITY_DESTROYED" : DiyalogSDK Call Activity completely destroyed. This event is only for android sdk.

After call completed and your logic finished for video help, you should unsubscribe from CallState event bu using following method.aşağıdaki metod ile unsubscribe olabilirsiniz.

public void unSubscribeToCallStateWithTxCodeEvent(ValueChangedListener<String> listener)

You can see complete code sample that you need to implement below. You should show wait screen after getting success from VideoCallResult callback. If you receive failure, there is an error in the system and you should show error screen to customer.

ArrayList<AttachedData> attachedData = new ArrayList<AttachedData>();
attachedData.add(new AttachedData("dataName1","dataValue1"));
attachedData.add(new AttachedData("dataName2","dataValue2"));
attachedData.add(new AttachedData("dataName3","dataValue3"));
attachedData.add(new AttachedData("dataName4","dataValue4"));
DiyalogEngine.diyalogInstance().startVideoCallWithAttachedDataInBackground(
this,
Long.parseLong(idenNo),
"<Customer_No>",
"<Customer_NAME>",
null,
"<Tx_Code",
attachedData,
new VideoCallResult() {
@Override
public void success() {
DiyalogEngine.diyalogInstance().subscribeToCallStateWithTxCodeEvent(
new ValueChangedListener<CallStateEvent>() {
@Override
public void onChanged(CallStateEvent val, Value<CallStateEvent> valueModel) {
Log.d("VIDEOCALL",
"CALL STATE CHANGED TO " +
val.getState() +
" for txCode " +
val.getTxCode());
//RINGING, CONNECTING, IN_PROGRESS, ENDED, NO_CALL, CALL_ACTIVITY_DESTROYED
if (val.equals("CALL_ACTIVITY_DESTROYED")){
// Show customer creation result to user
}
else if (val.equals("IN_PROGRESS")){
}
..
}
});
// SHOW YOUR WAIT SCREEN
}
@Override
public void failure(VideoCallError videoCallError) {
Log.e(
"VIDEO CALL CENTER",
"Video call failed. Failure Code :" +
videoCallError.getErrorCode() +
" Failure Message :" +
videoCallError.getErrorMsg());
// Show Call failed message to user
}
});

If startVideoCallWithAttachedDataInBackground method return successfull and you showed wait screen to customer and the customer press cancel button in your wait screen before agent start video call, you should call stopVideoCall method to stop process

public boolean stopVideoCall(String customerId)

Sample code

DiyalogEngine.diyalogInstance().stopVideoCall(customerId);

Done :)

You can download full simple video call android project from SimpleVideoCall link.