Search in sources :

Example 1 with CallSettings

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

the class CometChatStartCallActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    setContentView(R.layout.activity_cometchat_start_call);
    ongoingCallService = new OngoingCallService();
    mServiceIntent = new Intent(this, ongoingCallService.getClass());
    isDefaultCall = getIntent().getBooleanExtra(UIKitConstants.IntentStrings.IS_DEFAULT_CALL, false);
    if (isDefaultCall && !isMyServiceRunning(ongoingCallService.getClass())) {
        startService(mServiceIntent);
    }
    mainView = findViewById(R.id.call_view);
    connectingLayout = findViewById(R.id.connecting_to_call);
    sessionID = getIntent().getStringExtra(UIKitConstants.IntentStrings.SESSION_ID);
    type = getIntent().getStringExtra(UIKitConstants.IntentStrings.TYPE);
    if (type != null && type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).setMode(CallSettings.MODE_SINGLE).build();
    else
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).build();
    CometChatError.init(this);
    Log.e("startCallActivity: ", sessionID + " " + type);
    CometChat.startCall(callSettings, new CometChat.OngoingCallListener() {

        @Override
        public void onUserListUpdated(List<User> list) {
            Log.e("onUserListUpdated: ", list.toString());
        }

        @Override
        public void onAudioModesUpdated(List<AudioMode> list) {
            Log.e("onAudioModesUpdated: ", list.toString());
        }

        @Override
        public void onUserJoined(User user) {
            connectingLayout.setVisibility(View.GONE);
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_joined) + ":" + user.getName(), CometChatSnackBar.INFO);
            Log.e("onUserJoined: ", user.getUid());
        }

        @Override
        public void onUserLeft(User user) {
            if (user != null) {
                CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_left) + ":" + user.getName(), CometChatSnackBar.INFO);
                Log.e("onUserLeft: ", user.getUid());
                if (callSettings.getMode().equals(CallSettings.MODE_SINGLE)) {
                    endCall();
                }
            } else {
                Log.e("onUserLeft: ", "triggered");
            }
        }

        @Override
        public void onError(CometChatException e) {
            stopService(mServiceIntent);
            Log.e("onstartcallError: ", e.getMessage());
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }

        @Override
        public void onCallEnded(Call call) {
            stopService(mServiceIntent);
            Log.e("TAG", "onCallEnded: ");
            finish();
        }
    });
}
Also used : OngoingCallService(com.cometchat.pro.uikit.ui_components.calls.call_manager.ongoing_call.OngoingCallService) CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) Intent(android.content.Intent) CallSettings(com.cometchat.pro.core.CallSettings) AudioMode(com.cometchat.pro.models.AudioMode)

Aggregations

Intent (android.content.Intent)1 Call (com.cometchat.pro.core.Call)1 CallSettings (com.cometchat.pro.core.CallSettings)1 CometChat (com.cometchat.pro.core.CometChat)1 CometChatException (com.cometchat.pro.exceptions.CometChatException)1 AudioMode (com.cometchat.pro.models.AudioMode)1 User (com.cometchat.pro.models.User)1 OngoingCallService (com.cometchat.pro.uikit.ui_components.calls.call_manager.ongoing_call.OngoingCallService)1