ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
124 stars 111 forks source link

error [VideoChat]: 'setRemoteSessionDescription' error: [object Object] when chat video group 4/4 #204

Closed meosieudang closed 2 years ago

meosieudang commented 3 years ago

Screen Shot 2021-02-02 at 3 07 40 PM

meosieudang commented 3 years ago

i have 4 user A, B, C, D The bug appears when A call to B,C,D then B and C and D accept and then B or C or D will error [VideoChat]: 'setRemoteSessionDescription' error: [object Object] => lost connect stream

ccvlad commented 3 years ago

@meosieudang Could you share a code where you receive a call and do accept on the call? Did you check our VideoChat sample?

FYI - How we do accept a call

meosieudang commented 3 years ago

here is press accept button:

_onPressAccept = (notification) => { CallService.acceptCall(this._session) .then((stream) => { const { opponentsIDs, initiatorID, currentUserID } = this._session const opponentsIds = [initiatorID, ...opponentsIDs].filter( (userId) => currentUserID !== userId ) this.initRemoteStreams(opponentsIds) this._setLocalStream([{ userId: 'localStream', stream }]) this.setInfoCalling( notification.hasVideo, notification.roomId, notification.callerName, opponentsIds, notification.isGroupChat ) this.hideIncomingCall() }) .catch((e) => { showToast('Có lỗi trong quá trình kết nối, vui lòng thử lại sau.') CallService.stopCall() this.resetState() }) }

@ccvlad , here is func acceptCall

acceptCall = (session) => { this.stopSounds(); this._session = session; this.setMediaDevices();

return this._session
  .getUserMedia(CallService.MEDIA_OPTIONS)
  .then((stream) => {
    this._session.accept({});
    return stream;
  });

};

meosieudang commented 3 years ago

@ccvlad , https://www.youtube.com/watch?v=e4q9dQXkIEw please see the movie to see error

ccvlad commented 3 years ago

Could you test a call on real devices? I'm not sure that WebRTC will work correctly on the simulator

meosieudang commented 3 years ago

@ccvlad , sir i'm try test it on 4 real devices and sometime will lost 1 stream in 4 devices :((

ccvlad commented 3 years ago

I need some time to check you logs from video. Can I reproduce the issue on our VideoChat sample or it just related to your code?

ccvlad commented 3 years ago

@meosieudang Seems you call a session.accept() more than once. Check this please. You should call the session.accept() after getting the session in ConnectyCube.videochat.onCallListener = (session, extension) => {/* accept/reject */}

meosieudang commented 3 years ago

@ccvlad , the func accept call i just call once, sir. The bug appears
A => B and C B will receive event _onAcceptCallListener and _onRemoteStreamListener from A, and C C will receive event _onAcceptCallListener and _onRemoteStreamListener from A, and B A => receive stream from B and C 👍 B => receive stream A 👍 but stream C sometime happen error setRemoteSessionDescription C => receive stream A 👍 but stream B sometime happen error setRemoteSessionDescription

ccvlad commented 3 years ago

Can I reproduce the issue on our VideoChat sample or it just related to your code?

?

meosieudang commented 3 years ago

@ccvlad, yes you can reproduce the issue on your example but sometime happen like my code

ccvlad commented 3 years ago

I have tested our samples but can't reproduce the same error. I quickly pressed the 'Accept' button twice, but have gotten other errors. Could you attach logs with the error in this thread?

meosieudang commented 3 years ago

Sir, the issue happen A call to B and C. When B and C receive event onCallListener show modal acept and reject button. You need to press the accept button at B and C at the same time to get the error Vào Th 3, 2 thg 2, 2021 lúc 18:58 ccvlad notifications@github.com đã viết:

I have tested our samples but can't reproduce the same error. I quickly pressed the 'Accept' button twice, but have gotten other errors. Could you attach logs with the error in this thread?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ConnectyCube/connectycube-reactnative-samples/issues/204#issuecomment-771585928, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK6JCD57IUM3BGQIVZC46LLS47SHDANCNFSM4W6FWEDA .

ccvlad commented 3 years ago

Try to debug w/o Google Chrome console, use only Metro server. Will the error appear?

meosieudang commented 3 years ago

Im try turn off debug but still this error. The issue happen when my app build on testflight appstore connect. Someone user in group chat will state freeze face and disconnect. Then i try init new video call group and never fire event onRemoteStreamListener

Vào Th 3, 2 thg 2, 2021 lúc 20:03 ccvlad notifications@github.com đã viết:

Try to debug w/o Google Chrome console, use only Metro server. Will the error appear?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ConnectyCube/connectycube-reactnative-samples/issues/204#issuecomment-771619757, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK6JCDZI3MSTG5DTSODWI2TS47Z2ZANCNFSM4W6FWEDA .

ccvlad commented 3 years ago

Try to debug w/o Google Chrome console, use only Metro server. Will the error appear?

Please send. I will check the sequence

meosieudang commented 3 years ago

@ccvlad , user A has id 3101422 (initiator call) Screen Shot 2021-02-03 at 12 12 11 PM

user B has id 3050168 Screen Shot 2021-02-03 at 12 14 27 PM

user C has id 3082051 Screen Shot 2021-02-03 at 12 15 05 PM

you can see event _onAcceptCallListener call 2 times on user C => issue setRemoteSessionDescription p/s: i'm just press accept call once

meosieudang commented 3 years ago

@ccvlad , this issue from cubeWebRTCSession.js file

_processOnAccept(userID, extension) { const peerConnection = this.peerConnections[userID]; if (peerConnection) { peerConnection._clearDialingTimer(); peerConnection .setRemoteSessionDescription('answer', extension.sdp) .then(() => { Helpers.trace("'setRemoteSessionDescription' success"); }) .catch(error => { console.warn(error); Helpers.traceError("'setRemoteSessionDescription' error: " + error); }); } else { Helpers.traceWarning("Ignore 'OnAccept', there is no information about peer connection by some reason."); } }

meosieudang commented 3 years ago

photo_2021-02-03 3 10 22 PM

the issue appear on sample code @ccvlad

ccvlad commented 3 years ago

Hi @meosieudang

I've found the error!

100% to reproduce the case:

FYI. Our sample has 4 hardcoded user (Alice, Bob, Ciri and Dexter). So, somebody else is able to use the RNVideoChat when you are testing too.

To avoid the error use the code snippet below:

ConnectyCube.videochat.onCallListener = (session, extension) => {
  // show the incoming call screen/modal with abilities to accept and reject
}

ConnectyCube.videochat.onAcceptCallListener = (session, userId, extension) => {
  // ignore session.accept() from the same user on other device
  if (userId === currentUserId) {
    // hide the incoming call screen/modal and ignore the call
  }
}
meosieudang commented 3 years ago

@ccvlad , this issue from cubeWebRTCSession.js file

_processOnAccept(userID, extension) { const peerConnection = this.peerConnections[userID]; if (peerConnection) { peerConnection._clearDialingTimer(); peerConnection .setRemoteSessionDescription('answer', extension.sdp) .then(() => { Helpers.trace("'setRemoteSessionDescription' success"); }) .catch(error => { console.warn(error); Helpers.traceError("'setRemoteSessionDescription' error: " + error); }); } else { Helpers.traceWarning("Ignore 'OnAccept', there is no information about peer connection by some reason."); } }

Hi @ccvlad , Can you login an account on a device? the issue happen on above file For the your solution i just handle same userId ago please help me fix this issue

ccvlad commented 3 years ago

The issue happens after rtcPeerConnection.setRemoteDescription('answer', sdp). The code obtain the peerConnection with user by userId (const peerConnection = this.peerConnections[userID]) and trying to set SDP (Session Description Protocol) for 'answer', but the peerConnection already has remote description.

The way to prevent the error is avoid the onAcceptListener from firing twice from the same user. The first user who accepts the call shouldn't accepts from other device (for the same user logged in on different devices).

You can check:

ConnectyCube.videochat.onAcceptListener = (session, userId, extension) => {
  // the same ids will be showe twice before the 'serRemoteSessionDescription' error
  console.log(`${userId} accepted the call to ${currentUserId}`)
}

We can prevent the error in our SDK, but it will take some time to release.

meosieudang commented 3 years ago

Hi @ccvlad , I fixed the problem by checking if the user is setRemoteStream or not on func _processOnAccept So hope you fix it and release next version for lib. thanks

meosieudang commented 3 years ago

@ccvlad, can i fork lib react-native-connectycube?

meosieudang commented 3 years ago

@ccvlad , you need check it this code : accept(extension) { const ext = _prepareExtension(extension)

    Helpers.trace('Accept, extension: ' + JSON.stringify(ext.userInfo))

    if (this.state === SessionState.ACTIVE) {
        Helpers.traceError("Can't accept, the session is already active, return.")
        return
    }

    if (this.state === SessionState.CLOSED) {
        Helpers.traceError("Can't accept, the session is already closed, return.")
        this.stop({})
        return
    }

    this.state = SessionState.ACTIVE

    this.acceptCallTime = new Date()

    this._clearAnswerTimer()

    this._acceptInternal(this.initiatorID, ext)

    //group call
    const oppIDs = this._uniqueOpponentsIDsWithoutInitiator()
    if (oppIDs.length > 0) {
        const offerTime = (this.acceptCallTime - this.startCallTime) / 1000
        this._startWaitingOfferOrAnswerTimer(offerTime)

        oppIDs.forEach((opID) => {
            if (this.currentUserID > opID) {
                this._callInternal(opID, {}, true)
            }
        })
    }
}

@ccvlad , after //group call i think the problem here

ccvlad commented 3 years ago

Hi @ccvlad , I fixed the problem by checking if the user is setRemoteStream or not on func _processOnAccept So hope you fix it and release next version for lib. thanks

Great!

ccvlad commented 3 years ago

@ccvlad, can i fork lib react-native-connectycube?

Unfortunately, the ConnectyCube SDKs stored in private repository. You can install it via NPM, change what you want and use npm pack to make a TGZ file. Then connect the source from the TGZ file in your package.json:

...
"react-native-connectycube": "file:<path-to-sdk>/react-native-connectycube-<version>.tgz",
...
meosieudang commented 3 years ago

@ccvlad, here is file i'm fix bug accept call twice cubeWebRTCSession.js.zip

ccvlad commented 2 years ago

Closed due to inactivity. Please create a new issue if needed.