You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter WebRTC中RTCPeerConnection.addStream失效问题求助

解决WebRTC中AddStream不可用的问题

报错提示AddStream is not available with Unified Plan SdpSemantics. Please use AddTrack instead.是因为Unified Plan SDP语义已废弃addStream方法,必须改用addTrack逐个添加媒体轨道。

修改步骤:

  • 删除原代码中的pc.addStream(_localStream!);
  • 遍历本地流的所有媒体轨道,通过addTrack添加到PeerConnection

修改后的完整代码:

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);
// 替换原addStream方法
_localStream!.getTracks().forEach((track) {
  pc.addTrack(track, _localStream!);
});

内容的提问来源于stack exchange,提问作者EbrahimAghdasi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 21:05:24