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

WebRTC视频通话Demo:Firestore未生成集合致远端用户无法接入排查

问题排查与修复建议

核心问题1:未将Offer描述写入Firestore文档

你的代码中创建了callDoc文档引用,但从未向该文档写入任何数据。Firestore的集合是"惰性创建"的——只有当集合下存在至少一个有内容的文档时,才会在控制台中显示。目前calls集合下没有实际写入的文档,自然不会生成对应的集合。

修复方法:在设置本地描述后,将offer描述写入callDoc:

// Create offer
const offerDescription = await pc.createOffer();
await pc.setLocalDescription(offerDescription);

// 新增:将offer描述写入Firestore文档
await callDoc.set({
  offer: {
    type: offerDescription.type,
    sdp: offerDescription.sdp
  }
});

核心问题2:ICE候选处理可能不完整

  • 确保你的RTCPeerConnection实例pc配置了有效的ICE服务器,否则可能无法生成ICE候选,导致offerCandidates集合没有数据写入:
// 初始化pc时添加iceServers配置
const pc = new RTCPeerConnection({
  iceServers: [
    { urls: "stun:stun.l.google.com:19302" } // 公共STUN服务器
  ]
});
  • 给onicecandidate事件添加错误捕获,确认是否有候选生成:
pc.onicecandidate = async (event) => {
  if (event.candidate) {
    try {
      await offerCandidates.add(event.candidate.toJSON());
    } catch (err) {
      console.error("保存ICE候选失败:", err);
    }
  }
};

额外检查点:Firestore安全规则

确认你的Firestore安全规则允许未认证用户写入(如果Demo没有做用户登录),否则写入操作会被拒绝。临时测试可以设置宽松规则(上线前务必修改):

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

验证步骤

  • 点击呼叫按钮后,打开浏览器控制台,检查是否有Firestore相关的错误日志
  • 完成上述修复后,再次操作,查看Firestore控制台是否生成calls集合及对应的子集合

内容的提问来源于stack exchange,提问作者Tejendra Singh Rajawat

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 01:06:25