flutter webrtc RTCPeerConnection.addStream 不起作用

问题描述 投票:0回答:2

朋友们,我想使用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!);
flutter webrtc flutter-webrtc
2个回答
7
投票

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

RTCPeerConnection.addStream(localStream)
已经过时了

我也用它

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

希望对你有用


0
投票

iska 解决方案 h koe ?

  _createPeerConnection() async {
Map<String, dynamic> configuration = {
  'iceServers': [
    {"url": "stun:stun.l.google.com:19302"}
  ]
};

final Map<String, dynamic> offerSdpConstrains = {
  "mandatory": {
    "OfferToReceiveAudio": true,
    "OfferToReceiveVideo": true,
  },
  "optional": []
};

_localStream = await _getUserMedia();

RTCPeerConnection pc =
    await createPeerConnection(configuration, offerSdpConstrains);
pc.addStream(_localStream!);
pc.onIceCandidate = (e) {
  if (e.candidate != null) {
    print(json.encode({
      "candidate": e.candidate.toString(),
      "sdpMid": e.sdpMid.toString(),
      "sdpMlineIndex": e.sdpMLineIndex,
    }));
  }
};
pc.onIceConnectionState = (e) {
  print(e);
};

pc.onAddStream = (stream) {
  print("addstream $stream");
  _remoteRender.srcObject = stream;
};

return pc;

}

© www.soinside.com 2019 - 2024. All rights reserved.