Search in sources :

Example 16 with Call

use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.

the class MyFirebaseMessagingService method onMessageReceived.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    try {
        count++;
        json = new JSONObject(remoteMessage.getData());
        Log.d(TAG, "JSONObject: " + json.toString());
        JSONObject messageData = new JSONObject(json.getString("message"));
        BaseMessage baseMessage = CometChatHelper.processMessage(new JSONObject(remoteMessage.getData().get("message")));
        if (baseMessage instanceof Call) {
            call = (Call) baseMessage;
            isCall = true;
        }
        showNotifcation(baseMessage);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : Call(com.cometchat.pro.core.Call) JSONObject(org.json.JSONObject) BaseMessage(com.cometchat.pro.models.BaseMessage) JSONException(org.json.JSONException)

Example 17 with Call

use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.

the class Utils method getDirectCallData.

public static Call getDirectCallData(BaseMessage baseMessage) {
    Call call = null;
    String callType = CometChatConstants.CALL_TYPE_VIDEO;
    try {
        if (((CustomMessage) baseMessage).getCustomData() != null) {
            JSONObject customObject = ((CustomMessage) baseMessage).getCustomData();
            String receiverID = baseMessage.getReceiverUid();
            String receiverType = baseMessage.getReceiverType();
            call = new Call(receiverID, receiverType, callType);
            if (customObject.has("sessionID")) {
                String sessionID = customObject.getString("sessionID");
                call.setSessionId(sessionID);
                Log.e(TAG, "startDirectCallData: " + call.toString());
            } else {
                call.setSessionId(receiverID);
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "startDirectCallData: " + e.getMessage());
    }
    return call;
}
Also used : Call(com.cometchat.pro.core.Call) JSONObject(org.json.JSONObject) CustomMessage(com.cometchat.pro.models.CustomMessage) IOException(java.io.IOException)

Example 18 with Call

use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.

the class CallHistoryAdapter method update.

/**
 * This method is used to update call in callList.
 *
 * @param call is an object of Call. It is used to update the previous call
 *                     in list
 * @see Call
 */
public void update(Call call) {
    if (callList.contains(call)) {
        Call oldCall = (Call) callList.get(callList.indexOf(call));
        callList.remove(oldCall);
        callList.add(0, call);
    } else {
        callList.add(0, call);
    }
    notifyDataSetChanged();
}
Also used : Call(com.cometchat.pro.core.Call)

Example 19 with Call

use of com.cometchat.pro.core.Call in project android-java-chat-push-notification-app by cometchat-pro.

the class CallUtils method initiateCall.

/**
 * This method is used to initiate a call for user or a group.
 * @param context is a object of Context
 * @param recieverID is String - It can be either uid or guid
 * @param receiverType is String - It can be either user or group
 *                     [<code>CometChatConstants.RECEIVER_TYPE_USER</code> or
 *                     <code>CometChatConstants.RECEIVER_TYPE_GROUP</code>]
 * @param callType is String -  It can be either audio or video
 *                 [<code>CometChatConstants.CALL_TYPE_AUDIO</code> or
 *                 <code>CometChatConstants.CALL_TYPE_VIDEO</code>]
 *
 * @see CometChat#initiateCall(Call, CometChat.CallbackListener)
 */
public static void initiateCall(Context context, String recieverID, String receiverType, String callType) {
    Call call = new Call(recieverID, receiverType, callType);
    CometChat.initiateCall(call, new CometChat.CallbackListener<Call>() {

        @Override
        public void onSuccess(Call call) {
            if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER))
                startCallIntent(context, ((User) call.getCallReceiver()), call.getType(), true, call.getSessionId());
            else if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_GROUP))
                startGroupCallIntent(context, ((Group) call.getCallReceiver()), call.getType(), true, call.getSessionId());
        }

        @Override
        public void onError(CometChatException e) {
            Log.e(TAG, "onError: " + e.getMessage());
            Snackbar.make(((Activity) context).getWindow().getDecorView().getRootView(), context.getResources().getString(R.string.call_initiate_error) + ":" + e.getMessage(), Snackbar.LENGTH_LONG).show();
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat)

Aggregations

Call (com.cometchat.pro.core.Call)19 CometChatException (com.cometchat.pro.exceptions.CometChatException)6 User (com.cometchat.pro.models.User)6 Intent (android.content.Intent)5 View (android.view.View)5 CometChat (com.cometchat.pro.core.CometChat)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 BaseMessage (com.cometchat.pro.models.BaseMessage)4 ViewGroup (android.view.ViewGroup)3 Group (com.cometchat.pro.models.Group)3 JSONObject (org.json.JSONObject)3 Bundle (android.os.Bundle)2 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 CustomMessage (com.cometchat.pro.models.CustomMessage)2 CometChatStartCallActivity (com.cometchat.pro.uikit.ui_components.calls.call_manager.CometChatStartCallActivity)2 CometChatGroupDetailActivity (com.cometchat.pro.uikit.ui_components.groups.group_details.CometChatGroupDetailActivity)2 CometChatUserDetailScreenActivity (com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity)2 OnItemClickListener (com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener)2 ClickListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)2