QuickBlox / quickblox-android-sdk

QuickBlox Android SDK includes code snippets with main use cases and framework JAR library.
BSD 3-Clause "New" or "Revised" License
417 stars 697 forks source link

Please help me, call back not work :( #517

Closed A2DNEW closed 3 years ago

A2DNEW commented 6 years ago

Hi Please help me!

  1. Device A login and config chatService
  2. Device B login and config chatService
  3. Device B startCall and send notification to device A
  4. Device A receive notification and send to CallSerivce
    String message = data.get("message");
    if(message != null){
    CallService.start(this, G.userQB);
    }

    My problem: After start CallService, call backs and onReceiveNewSession(QBRTCSession session) not work and not receive anything and not set in logcat

CallService.java

public class CallService extends Service implements QBRTCClientSessionCallbacks, QBRTCSessionConnectionCallbacks {
    private static final String TAG = CallService.class.getSimpleName();
    private QBChatService chatService;
    private QBRTCClient rtcClient;
    private PendingIntent pendingIntent;
    private int currentCommand;
    private QBUser currentUser;

    public static void start(Context context, QBUser qbUser, PendingIntent pendingIntent) {
        Intent intent = new Intent(context, CallService.class);

        intent.putExtra(Consts.EXTRA_COMMAND_TO_SERVICE, Consts.COMMAND_LOGIN);
        intent.putExtra(Consts.EXTRA_QB_USER, qbUser);
        intent.putExtra(Consts.EXTRA_PENDING_INTENT, pendingIntent);

        Log.i("errorCheck", "pendingIntent => " + pendingIntent);

        context.startService(intent);
    }

    public static void start(Context context, QBUser qbUser) {
        start(context, qbUser, null);
    }

    @Override
    public void onCreate() {
        super.onCreate();

        /*QBSettings.getInstance().init(getApplicationContext(), G.APP_ID, G.AUTH_KEY, G.AUTH_SECRET);
        QBSettings.getInstance().setAccountKey(G.ACCOUNT_KEY);
        QBSettings.getInstance().setEnablePushNotification(true);
        QBSettings.getInstance().isEnablePushNotification();*/

        createChatService();

        Log.d(TAG, "Service onCreate()");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d(TAG, "Service started");

        parseIntentExtras(intent);

        startSuitableActions();

        return START_REDELIVER_INTENT;
    }

    private void parseIntentExtras(Intent intent) {
        if (intent != null && intent.getExtras() != null) {
            currentCommand = intent.getIntExtra(Consts.EXTRA_COMMAND_TO_SERVICE, Consts.COMMAND_NOT_FOUND);
            pendingIntent = intent.getParcelableExtra(Consts.EXTRA_PENDING_INTENT);
            currentUser = (QBUser) intent.getSerializableExtra(Consts.EXTRA_QB_USER);
        }
    }

    private void startSuitableActions() {
        Log.i("errorCheck",currentCommand+ " == " + Consts.COMMAND_LOGIN);
        Log.i("errorCheck",currentCommand+ " == "+Consts.COMMAND_LOGOUT);
        if (currentCommand == Consts.COMMAND_LOGIN) {
            Log.i("errorCheck","?!: TO");
            startLoginToChat();
        } else if (currentCommand == Consts.COMMAND_LOGOUT) {
            Log.i("errorCheck","?!: OUT");
            logout();
        }
    }

    private void createChatService() {
        if (chatService == null) {
            QBChatService.setDebugEnabled(true);
            chatService = QBChatService.getInstance();
        }
    }

    private void startLoginToChat() {
        Log.i("errorCheck","?!: "+chatService);
        if (!chatService.isLoggedIn()) {
            Log.i("errorCheck","??????!!!!: "+chatService);
            loginToChat(currentUser);
        } else {
            Log.i("errorCheck", "NOLOGIN: "+chatService);
            sendResultToActivity(true, null);
        }
    }

    private void loginToChat(QBUser qbUser) {
        Log.i("errorCheck", "QQ: " + chatService);
        chatService.login(qbUser, new QBEntityCallback<QBUser>() {
            @Override
            public void onSuccess(QBUser qbUser, Bundle bundle) {
                Log.d(TAG, "login onSuccess");
                startActionsOnSuccessLogin();
            }

            @Override
            public void onError(QBResponseException e) {
                Log.d(TAG, "login onError " + e.getMessage());
                sendResultToActivity(false, e.getMessage() != null
                        ? e.getMessage()
                        : "Login error");
            }
        });
    }

    private void startActionsOnSuccessLogin() {
        initPingListener();
        initQBRTCClient();
        sendResultToActivity(true, null);
    }

    private void initPingListener() {
        ChatPingAlarmManager.onCreate(this);
        ChatPingAlarmManager.getInstanceFor().addPingListener(new PingFailedListener() {
            @Override
            public void pingFailed() {
                Log.d(TAG, "Ping chat server failed");
            }
        });
    }

    private void initQBRTCClient() {
        rtcClient = QBRTCClient.getInstance(getApplicationContext());
        // Add signalling manager
        chatService.getVideoChatWebRTCSignalingManager().addSignalingManagerListener(new QBVideoChatSignalingManagerListener() {
            @Override
            public void signalingCreated(QBSignaling qbSignaling, boolean createdLocally) {
                if (!createdLocally) {
                    rtcClient.addSignaling((QBWebRTCSignaling) qbSignaling);
                }
            }
        });

        // Configure
        QBRTCConfig.setDebugEnabled(true);
        SettingsUtil.configRTCTimers(CallService.this);

        // Add service as callback to RTCClient
        rtcClient.addSessionCallbacksListener(WebRtcSessionManager.getInstance(this));
        rtcClient.prepareToProcessCalls();
    }

    private void sendResultToActivity(boolean isSuccess, String errorMessage) {
        Log.d(TAG, "Activity(): "+isSuccess+" , "+errorMessage+" , "+pendingIntent);
        if (pendingIntent != null) {
            Log.d(TAG, "sendResultToActivity()");
            try {
                Intent intent = new Intent();
                intent.putExtra(Consts.EXTRA_LOGIN_RESULT, isSuccess);
                intent.putExtra(Consts.EXTRA_LOGIN_ERROR_MESSAGE, errorMessage);

                /*Intent newInt = new Intent(Intent.ACTION_SENDTO);
                newInt.setData(Uri.parse("sms:0523737233"));
                newInt.putExtra("sms_body", "The SMS text");
                pendingIntent = PendingIntent.getActivity(this, 0, newInt, 0);*/

                pendingIntent.send(CallService.this, Consts.EXTRA_LOGIN_RESULT_CODE, intent);
            } catch (PendingIntent.CanceledException e) {
                String errorMessageSendingResult = e.getMessage();
                Log.d(TAG, errorMessageSendingResult != null
                        ? errorMessageSendingResult
                        : "Error sending result to activity");
            }
        }
    }

    public static void logout(Context context) {
        Intent intent = new Intent(context, CallService.class);
        intent.putExtra(Consts.EXTRA_COMMAND_TO_SERVICE, Consts.COMMAND_LOGOUT);
        context.startService(intent);
    }

    private void logout() {
        destroyRtcClientAndChat();
    }

    private void destroyRtcClientAndChat() {
        if (rtcClient != null) {
            rtcClient.destroy();
        }
        ChatPingAlarmManager.onDestroy();
        if (chatService != null) {
            chatService.logout(new QBEntityCallback<Void>() {
                @Override
                public void onSuccess(Void aVoid, Bundle bundle) {
                    chatService.destroy();
                }

                @Override
                public void onError(QBResponseException e) {
                    Log.d(TAG, "logout onError " + e.getMessage());
                    chatService.destroy();
                }
            });
        }
        stopSelf();
    }

    @Override
    public void onDestroy() {
        Log.d(TAG, "Service onDestroy()");
        super.onDestroy();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.d(TAG, "Service onBind)");
        return null;
    }

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        Log.d(TAG, "Service onTaskRemoved()");
        super.onTaskRemoved(rootIntent);
        destroyRtcClientAndChat();
    }

    @Override
    public void onReceiveNewSession(QBRTCSession qbrtcSession) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onUserNoActions(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onSessionStartClose(QBRTCSession qbrtcSession) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onStartConnectToUser(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onDisconnectedTimeoutFromUser(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onConnectionFailedWithUser(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onError(QBRTCSession qbrtcSession, QBRTCException e) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onUserNotAnswer(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onCallRejectByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onCallAcceptByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onReceiveHangUpFromUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onSessionClosed(QBRTCSession qbrtcSession) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onConnectedToUser(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onDisconnectedFromUser(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }

    @Override
    public void onConnectionClosedForUser(QBRTCSession qbrtcSession, Integer integer) {
        Log.d(TAG, ""+1);
    }
}
A2DNEW commented 6 years ago

Can you help me ?!

diaz9557 commented 6 years ago

@ A2DNEW first calm down . If you are not receiving call with quickblox sdk . Then you need to crosscheck everything . First ting double check API creadentials. Then Just follow the sample see if you have done similar or something missing . Meanwhile please post your startCall() code . maybe there is some problem in starting calll .

HFMohammad commented 6 years ago

@diaz9557 thank you for helping. i post all codes here : https://github.com/QuickBlox/quickblox-android-sdk/issues/519 Please check it

HFMohammad commented 6 years ago

@diaz9557 Can help me ? :(

tatanka987 commented 6 years ago

@A2DNEW sorry for long time answer, please specify where do you want listen this callback in WebRtcSessionManager or in CallService? If you want listen it in CallService, you need add CallService as callback listener too:

rtcClient.addSessionCallbacksListener(this);

in method initQBRTCClient() after string rtcClient.addSessionCallbacksListener(WebRtcSessionManager.getInstance(this));

ghost commented 3 years ago

Hello QuickBlox customer,

This is Nikolay from QuickBlox support.

The issue was closed as it is outdated.

Please check the relevant section of our documentation here: https://docs.quickblox.com/docs/android-video-calling

Also, please update the SDK to the latest version: https://github.com/QuickBlox/quickblox-android-sdk-releases/releases/tag/3.9.11

Additionally, please check our new samples: https://docs.quickblox.com/docs/code-samples#video-calling-samples

If it is still relevant after reviewing the updated information, feel free to open a new issue.

Have a nice day.