【问题标题】:Handle network interruption in WebRTC在 WebRTC 中处理网络中断
【发布时间】:2020-09-11 13:38:55
【问题描述】:

我正在使用Amazon Kinesis Video Streams WebRTC 在移动应用程序和网站之间建立视频聊天连接。我需要在 Web 端处理网络中断。让我解释一下我已经完成的步骤。

我可以在事件监听器上检测到网络已断开...

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

在这种情况下,我将在循环时间间隔内向服务器(测试 api)发送请求,以检测网络是否正常。 在网络连接正常的情况下,我会运行... (reference)

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

之后我可以看到连接已建立(connectionState/iceConnectionState 状态已连接)但我无法接收任何数据流(来自移动用户的视频被冻结)。但是 1 分钟后,发送流将显示在移动端。

谢谢!

【问题讨论】:

    标签: video-streaming webrtc amazon-kinesis


    【解决方案1】:

    我发现我必须发送 sdp 报价。所以代码会像...

    const newOffer = await peerConnection.createOffer({ iceRestart: true })
    await peerConnection.setLocalDescription(newOffer)
    
    // Send sdp offer
    master.signalingClient.sendSdpOffer(peerConnection.localDescription, viewerClientID) 
    
    

    现在它可以正常工作了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 1970-01-01
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      相关资源
      最近更新 更多