quickblox-android-sdk icon indicating copy to clipboard operation
quickblox-android-sdk copied to clipboard

Issue with calling when login on multiple devices

Open Yaya-Dev-Box opened this issue 3 years ago • 9 comments

Problem:

Hello, this is basically a copy of this iOS issue, but for Android, the linked issue's solution mentions using Apple's CallKit to notify users with multiple devices that one of their devices has answered/rejected the call, but I can't seem to find a similar solution for Android.

How to reproduce:

  • I managed to reproduce it using the sample-videochat-kotlin
  • Create two users: A and B.
  • Connect with user A's credentials on 1 Android device.
  • Connect with user B's credentials on 2 different Android devices.
  • Start a video call from user A to B.
  • User B's devices should both start ringing, answer the call on one of them.
  • The other device belonging to user B is still ringing.
  • Rejecting or accepting the call from the "still ringing device" affects user B's first device (the one in the call)

Expected behavior:

User B's second device should stop ringing when user B's first device accepts/rejects the call.

Question:

My question is: what is the Android equivalent of the iOS solution to produce the expected behavior?

Thanks

Yaya-Dev-Box avatar Jan 05 '23 11:01 Yaya-Dev-Box

Hello @Yaya-Dev-Box Now we are working to resolve the issue and give you an answer. Please wait for a new release Android SDK.

kirillTolmachev avatar Jan 11 '23 10:01 kirillTolmachev

@kirillTolmachev That's great, thanks.

I will be waiting.

Yaya-Dev-Box avatar Jan 11 '23 10:01 Yaya-Dev-Box

@Yaya-Dev-Box The Android SDK side was fixed but we need to do some improvements in our chat server. Now you can update your Android SDK to version 4.0.1 and wait for an update from the chat server side.

kirillTolmachev avatar Jan 18 '23 13:01 kirillTolmachev

@kirillTolmachev That's great, thank you.

Yaya-Dev-Box avatar Jan 18 '23 14:01 Yaya-Dev-Box

Hello @Yaya-Dev-Box We have released a server patch to our shared server. If you have a dedicated instance please contact with our support team for updating.

kirillTolmachev avatar Feb 14 '23 09:02 kirillTolmachev

Hi @kirillTolmachev, thanks for the update.

Are there any steps I need to make in order for the new change to take effect? I have already updated the SDK to use version "4.0.3", and also enabled "carbons" inside the sample-videochat-kotlin

Are there any other steps I'm missing? also, in what manner will the SDK be relaying user hangups/accepts with this new change?

Yaya-Dev-Box avatar Feb 14 '23 13:02 Yaya-Dev-Box

Hi @Yaya-Dev-Box

For correct work logic of multi-devices, you need to add logic with enable carbon. Inside the sample-videochat-kotlin in LoginService need to update method fun loginToChat(qbUser: QBUser). Before login to chat add ConnectionListener

private fun loginToChat(qbUser: QBUser) {
    QBChatService.getInstance().addConnectionListener(object : AbstractConnectionListener() {
        override fun authenticated(connection: XMPPConnection, resumed: Boolean) {
            try {
                CarbonManager.getInstanceFor(connection).sendCarbonsEnabled(true)
            } catch (e: NotConnectedException) {
                    // handle error
            }
        }
    })
    
    chatService.login(qbUser, object : QBEntityCallback<QBUser> {
        override fun onSuccess(qbUser: QBUser?, bundle: Bundle) {
            Log.d(TAG, "login onSuccess")
            startActionsOnSuccessLogin()
        }
        override fun onError(e: QBResponseException) {
            Log.d(TAG, "login onError " + e.message)
            val errorMessage = if (e.message != null) {
                e.message
            } else {
                "Login error"
            }
            sendResultToActivity(false, errorMessage)
        }
    })
}

For correct work, the application needs to update several methods fun onCallAcceptByUser() and fun onCallRejectByUser() in CallActivity.

private fun checkAndFinishMultiDeviceCall(userId: Int?) {
        // here we check that call was accepted or rejected from another device
        val currentUserId = QBChatService.getInstance().user.id
        if (currentUserId == userId) {
            WebRtcSessionManager.setCurrentSession(null)
            callService.stopForeground(true)
            finish()
     }
}
override fun onCallAcceptByUser(session: QBRTCSession?, userId: Int?, map: MutableMap<String, String>?) {
    if (callService.isCurrentSession(session)) {
        callService.stopRingtone()
    }
    
  checkAndFinishMultiDeviceCall(userId)
}
override fun onCallRejectByUser(session: QBRTCSession?, userId: Int?, map: MutableMap<String, String>?) {
    if (callService.isCurrentSession(session)) {
        callService.stopRingtone()
    }

    checkAndFinishMultiDeviceCall(userId)
}

vdovbnya-qb avatar Feb 17 '23 10:02 vdovbnya-qb

Works like a charm.

Thank you both @kirillTolmachev and @vdovbnya-qb , this issue is resolved now, feel free to close it.

Yaya-Dev-Box avatar Feb 17 '23 20:02 Yaya-Dev-Box

@Yaya-Dev-Box Thank you for your feedback. The issue is closed.

kirillTolmachev avatar Feb 18 '23 15:02 kirillTolmachev