Coder Social home page Coder Social logo

Comments (3)

bijuC1983 avatar bijuC1983 commented on June 16, 2024

Hello @disa6302 ,
After rigorous live testing with different users on different networks, the problem was isolated to the following:

func checkAndAddIceCandidate(remoteCandidate: RTCIceCandidate, clientId: String) {
    **if(clientId == ""){return}**
    // if answer/offer is not received, it means peer connection is not found. Hold the received ICE candidates in the map.
    if peerConnectionFoundMap.index(forKey: clientId) == nil {
        print("SDP exchange not completed yet. Adding candidate: \(remoteCandidate.sdp) to pending queue")
        // If the entry for the client ID already exists (in case of subsequent ICE candidates), update the queue
        if pendingIceCandidatesMap.index(forKey: clientId) != nil {
            var pendingIceCandidateListByClientId: Set<RTCIceCandidate> = pendingIceCandidatesMap[clientId]!
            pendingIceCandidateListByClientId.insert(remoteCandidate)
            pendingIceCandidatesMap[clientId] = pendingIceCandidateListByClientId
        }
        // If the first ICE candidate before peer connection is received, add entry to map and ICE candidate to a queue
        else {
            var pendingIceCandidateListByClientId = Set<RTCIceCandidate>()
            pendingIceCandidateListByClientId.insert(remoteCandidate)
            pendingIceCandidatesMap[clientId] = pendingIceCandidateListByClientId
        }
    }
    // This is the case where peer connection is established and ICE candidates are received for the established connection
    else {
        print("Peer connection found already")
        // Remote sent us ICE candidates, add to local peer connection
        let peerConnectionCurrent : RTCPeerConnection = peerConnectionFoundMap[clientId]!
        peerConnectionCurrent.add(remoteCandidate);
        print("Added ice candidate \(remoteCandidate.sdp)");
    }
}

This method was added in the last merge in order to handle out of turn ICE candidates as per the PR request. It uses a dictionary with the client Id as key to maintain the pending Ice Candidates by Client Id. We had noticed that sometimes, the app crashed with a EXC_BAD_ACCESS crash at:
pendingIceCandidateListByClientId.insert(remoteCandidate)
Our engineers, added some debug and prematurely concluded that this maybe when client id is received as empty(""). As error handling, the following statement was added which was causing the WebRTC to fail on many but certain network combinations. On certain networks like Airtel 4G, it worked 100% of the time.
if(clientId == ""){return}
Removing this statement, made it to work again on all networks with consistency. Hence, could you help us with the following:

  • pendingIceCandidatesMap is a dictionary with clientId as the key. It seems a bit odd that the clientId is received empty almost all the time. Is it expected and natural?
  • We suspect the Exec_Bad_Access could be happening sometimes due to some race condition considering the nature of these messages. Could you think of any reasons why this may be happening and suggest possible resolution.

Thank you in advance!

from amazon-kinesis-video-streams-webrtc-sdk-ios.

unicornss avatar unicornss commented on June 16, 2024

@bijuC1983
ConnectAsViewer requries clientId
https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/kvswebrtc-websocket-apis-1.html
but the ConnectAsMaster does not require one (1 to many)
https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/kvswebrtc-websocket-apis-2.html

In your scenario, the camera is connecting as master and mobile device is associating the iceCandidates from the master with that empty key clientId.

Hope this helps!

Thanks,.

from amazon-kinesis-video-streams-webrtc-sdk-ios.

unicornss avatar unicornss commented on June 16, 2024

@bijuC1983 ,
Given

Removing this statement, made it to work again on all networks with consistency.

closing the issue for now. Please re-open or create a new one as needed.

from amazon-kinesis-video-streams-webrtc-sdk-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.