flutter webrtc RTCPeerConnection.addStream 不工作

Ebr*_*asi 4 webrtc flutter flutter-webrtc

朋友们,我想使用 webrtc 为 Flutter 开发一个应用程序,但不幸的是我面临着无法解决的问题。

错误代码:AddStream 不适用于 Unified Plan SdpSemantics。请改用 AddTrack。

谢谢

Map<String, dynamic> configuration = {
  "iceServers": [
    {"url": "stun:stun1.l.google.com:19302"},
  ]
};
final Map<String, dynamic> offerSdpConstraints = {
  "mandatory": {
    "OfferToReceiveAudio": true,
    "OfferToReceiveVideo": true,
  },
  'optional': [
    {'DollsSftpKeyAgreement': true},
  ],
};

Map<String,dynamic> mediaConstraints = {
  'audio': true,
  'video': true,
};
_localStream = await navigator.mediaDevices.getUserMedia(mediaConstraints);
_localRenderer.srcObject = _localStream;


RTCPeerConnection pc = await createPeerConnection(configuration,offerSdpConstraints);
pc.addStream(_localStream!);
Run Code Online (Sandbox Code Playgroud)

Ebr*_*asi 6

我终于找到了这个错误的原因并意识到

RTCPeerConnection.addStream(localStream)它已经过时了

我用它

localStream?.getTracks().forEach((track) { peerConnection?.addTrack(track, localStream!); });

我希望它对你有用