Audio Call

The Methods below are available for Audio Chat:

Method Description
SendAudioChatRequest Allows logged-in user to initiate an audio call
CancelAudioChatRequest Allows logged-in user to cancel the initiated audio call
AcceptAudioChatRequest Allows logged-in user to accept incoming audio call
RejectAudioChatRequest Allows logged-in user to reject incoming audio call
StartAudioChatCall Starts the audio call in a provided UI container
EndAudioChatCall Ends the audio call
SendNoAnswerCall Sends no answer to the initiator of the call if callee doesn’t accept or reject the call
SendBusyTone Sends busy tone to inform the caller that callee is currently busy
MuteAudio Allows logged in user to mute/unmute his audio
SwitchSpeakers Allows logged-in user to switch the speaker

Initially, follow the steps mentioned in Initialization section to obtain an instantiated object of the CometChat class. Then use the object to call the methods required to implement the Audio Call feature.

SendAudioChatRequest

Allows logged-in user to initiate an audio call
Method Signature:

SendAudioChatRequest(String toId, ICallbacks callback)

Example:

cometChat.SendAudioChatRequest("15", new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
             //block of code
        }

Arguments:

Argument Description
toId userId of a callee
callback success and failure callbacks

Response for successCallback:

{
    "id": "15",
    "callid": "bf1e7055f8e15d6f8662c7c4b6f8adb9"
}

Description:

Response Property Description
id userId of a callee
callid id of the call session

CancelAudioChatRequest

Allows logged-in user to cancel the initiated audio call
Method Signature:

CancelAudioChatRequest(String userId, ICallbacks callback)

Example:

cometChat.CancelAudioChatRequest("15",new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
      //block of code
        }

Arguments:

Argument Description
userId id of a callee
callback success and failure callbacks

Response for successCallback:

{
    "id":"15"
}

Description:

Response Property Description
id userId of a callee

AcceptAudioChatRequest

Allows logged-in user to accept incoming audio call
Method Signature:

AcceptAudioChatRequest(String userId, ICallbacks callback)

Example:

cometChat.AcceptAudioChatRequest("16", new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
      //block of code
        }

Arguments:

Argument Description
userId userId of a caller
callback success and failure callbacks

Response for successCallback:

{
    "id":"16"
}

Description:

Response Property Description
id userId of a caller

RejectAudioChatRequest

Allows logged-in user to reject incoming audio call
Method Signature:

RejectAudioChatRequest(String userId, String callId, ICallbacks callback)

Example:

cometChat.RejectAudioChatRequest("16", "bf1e7055f8e15d6f8662c7c4b6f8adb9", new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
      //block of code
        }

Agruments:

Argument Description
userId userId of a caller
callId id of a call received in onAvchatMessageReceived() callback
callback success and failure callbacks

Response for successCallback:

    { 
        "id":"16"
    }

Description:

Response Property Description
id userId of a caller

StartAudioChatCall

Starts the audio call in a provided UI container
Method Signature:

StartAudioChatCall(Context context, String callid,RelativeLayout container,ICallbacks callbacks)

Example:

cometChat.StartAudioChatCall(MainActivity.this, "bf1e7055f8e15d6f8662c7c4b6f8adb9 ",container,new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
      //block of code
        }

Arguments:

Argument Description
context context of the activity
callId id of a call received in onAvchatMessageReceived() callback
container UI container to hold Audio Call UI
callback failure callbacks

endAudioChatCall

Ends the audio call
Method Signature:

EndAudioChatCall(String userId, String callId, ICallbacks callback)

Example:

cometChat.EndAudioChatCall("15", "bf1e7055f8e15d6f8662c7c4b6f8adb9", new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
      //block of code
        }

Arguments:

Argument Description
userId userId of other chat participant
callId id of a call received in onAvchatMessageReceived() callback
callback success and failure callbacks

Response for successCallback:

{ 
    "id": "15"
}

Description:

Response Property Description
id userId of other chat participants

SendNoAnswerCall

Sends no answer to the initiator of the call if callee doesn’t accept or reject the call
Method Signature:

SendNoAnswerCall(String userId, ICallbacks callback)

Example:

cometChat.SendNoAnswerCall("15", new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
      //block of code
        }

Arguments:

Argument Description
userId id of a group to delete
callback success and failure callbacks

Response for successCallback:

{ 
    "id": "15"
}

Description:

Response Property Description
id userId of the caller

SendBusyTone

Sends busy tone to inform the caller that callee is currently busy
Method Signature:

SendBusyTone(String userId, ICallbacks callback)

Example:

cometChat.SendBusyTone("15", new MyCallbacks(success => successcallback(success), fail => failcallback(fail)));

    public void successcallback(JSONObject p0)
        {
           //block of code
        }

        public void failcallback(JSONObject p0)
        {
      //block of code
        }

Arguments:

Argument Description
userId id of a group to delete
callback success and failure callbacks

Response for successCallback:

{ 
    "id": "15"
}

Description:

Response Property Description
id userId of the caller

MuteAudio

Allows logged in user to mute/unmute the audio
Method Signature:

MuteAudio(Boolean flag)

Example:

cometChat.MuteAudio(true);

Arguments:

Argument Description
flag turn audio on/off

SwitchSpeakers

Allows logged-in user to switch the speaker
Method Signature:

SwitchSpeakers()

Example:

cometChat.SwitchSpeakers();

Where MyCallbacks is defined as:


using System;
using Com.Inscripts.Interfaces;
using Org.Json;

    public class MyCallbacks : Java.Lang.Object, ICallbacks
    {
        Action _onSuccess;
        Action _onFail;
        public MyCallbacks(Action onSuccess, Action onFail)
        {
            this._onFail = onFail;
            this._onSuccess = onSuccess;
        }

        public void FailCallback(JSONObject p0)
        {
            this._onFail?.Invoke(p0);
        }

        public void SuccessCallback(JSONObject p0)
        {
            this._onSuccess?.Invoke(p0);
        }
    }


  • Was this helpful?
  • Yes   No