Handle network interruption in WebRTC

Viewed 298

I am using Amazon Kinesis Video Streams WebRTC for video chat connection between a mobile app and web site. I need to handle network interruption on web side. Let me explain the steps I have done already.

I can detect that network is disconnected on event listener ...

peerConnection.addEventListener('iceconnectionstatechange', event => {
  if (event.target.connectionState === 'connected' && event.target.iceConnectionState === 
  'disconnected') {
   // do something to handle network interruption 
  }
}

In this case I will send a request to the server (test api) in a loop time interval to detect whether network is Ok or not. In the case network connection is OK, I will run ... (reference)

const newOffer = await peerConnection.createOffer({ iceRestart: true })
            await peerConnection.setLocalDescription(newOffer)

After that I can see the connection established (connectionState/iceConnectionState status is connected) but I can not receive any datastream (the video from mobile user is freeze). However after 1 minute the send stream will be displayed on mobile side.

Thank you!

1 Answers

I found that I had to send sdp offer. So the code will be like ...

const newOffer = await peerConnection.createOffer({ iceRestart: true })
await peerConnection.setLocalDescription(newOffer)

// Send sdp offer
master.signalingClient.sendSdpOffer(peerConnection.localDescription, viewerClientID) 

Now it works as expected!

Related