awslabs / amazon-kinesis-video-streams-webrtc-sdk-ios

iOS SDK for interfacing with the Amazon Kinesis Video Streams Signaling Service.
Apache License 2.0
66 stars 29 forks source link

WebRTC does not connect if there is no forced delay between Signaling Client connect and sendOffer #32

Closed bijuC1983 closed 3 years ago

bijuC1983 commented 3 years ago

`signalingClient!.connect()

    let seconds = 2.0
    DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
        self.updateConnectionLabel()
        self.vc = VideoViewController(webRTCClient: self.webRTCClient!, signalingClient: self.signalingClient!, localSenderClientID: self.localSenderId, isMaster: self.isMaster!)
        self.present(self.vc!, animated: true, completion: nil)
    }`

As you see in the above snippet there is a delay of 2 seconds after the connect method is executed and before the sendOffer is executed inside VideoViewController init method. If this is set to 0, the WebRTC does not get connected and for values between 0 & 2 it is very inconsistent. Even with 2, one or two out of ten times it does not get connected.

What is the significance of this delay and how could this be made more consistent? This is not something specific to an individual network because these findings are from beta testing with an audience of 30+ people.

Thanks in advance.

disa6302 commented 3 years ago

The sample accounts for the time it needs to establish the connection before bring up the video view, but you could try launching that view after this triggers

bijuC1983 commented 3 years ago

Hello @disa6302, @unicornss
Thank you for your suggestions. I am now using the signalClientDidConnect to launch the view. The consistency has improved and the initialisation time has decreased. However, 2 scenarios were noticed:

  1. 1 out of 10 times, signalClientDidConnect is not called and the sequence gets stalled after that resulting in WebRTC connection not getting established. The log for this scenario is here
  2. 1 out of 10 times, signallingClientDidConnect is called and also .connected is received in didChangeConnectionState for webRTCClient. But, no video is received from the master. The log for this scenario is here Could you share your inputs regarding what could be happening in the above 2 scenarios and what are the ways the above could be avoided/fixed/handled?
disa6302 commented 3 years ago

@bijuC1983 ,

For the first issue, you can look into using a timeout in the starscream client to allow user to get the option to reconnect. For the second issue, I did go through the logs but did not find any errors. Can you provide the SDP offer and answer and also let us know if you see any errors in this case?

bijuC1983 commented 3 years ago

@disa6302 Thank your for your suggestions and inputs

Thanks again!

disa6302 commented 3 years ago

@bijuC1983 ,

I do not think I would do anything differently for the first case.

disa6302 commented 3 years ago

@bijuC1983 ,

I am closing this issue for now since the question is answered. Feel free to open a new issue if you reproduce the issue. Would like to minimize the scope of this ticket to the original question