当前位置: 首页 > news >正文

Failed to construct ‘RTCIceCandidate‘ sdpMid and sdpMLineIndex are both null

最近在搞webrtc,在编写函数处理远端传递来的candidate时报错了,具体信息如下。国内关于webrtc的资料很少,所以去国外社区转了一圈,回来记录一下报错的解决方案
在这里插入图片描述
其实这个bug也好解决,根据报错信息可以判断是RTCIceCandidatesdpMidsdpMlineIndex为null了,看了看RTCIceCandidate的原码,基本就能判断出应该是对端传递candidate的时候没传递这两个值

interface RTCIceCandidate {/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/address) */readonly address: string | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/candidate) */readonly candidate: string;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/component) */readonly component: RTCIceComponent | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/foundation) */readonly foundation: string | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/port) */readonly port: number | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/priority) */readonly priority: number | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/protocol) */readonly protocol: RTCIceProtocol | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/relatedAddress) */readonly relatedAddress: string | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/relatedPort) */readonly relatedPort: number | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/sdpMLineIndex) */readonly sdpMLineIndex: number | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/sdpMid) */readonly sdpMid: string | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/tcpType) */readonly tcpType: RTCIceTcpCandidateType | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/type) */readonly type: RTCIceCandidateType | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/usernameFragment) */readonly usernameFragment: string | null;/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/RTCIceCandidate/toJSON) */toJSON(): RTCIceCandidateInit;
}

于是我检查发送来的数据是这么构造的
在这里插入图片描述
我丢你的雷姆,这俩参数我压根就没传递。我们修改一下传递的json数据
在这里插入图片描述

tip:上述修改方式任然过于繁杂,const candidateJson = JSON.stringfy(event.candidate)即可实现预期效果

然后重启项目我们会发现报错消失了,并且也能显示出我们想要的效果,webrtc能够正常搭建

在这里插入图片描述

这篇文章提供了上面这个项目的源码(前端+后端)但还未整理,后续我会发布有关webrtc入门demo的文章和各位分享

webRTC详解文章
【前后端的那些事】2万字详解WebRTC(附加入门demo代码解析)

相关文章:

  • 【机器学习】数据清洗之处理缺失点
  • uniapp API文档地址 以及 HBuilder安装
  • 使用vscode传入参数的方式进行debug
  • 解决Ubuntu23.10中WPS的字体问题
  • Facebook MarketPlace自养号测评在海外FB商城如何精准引流私域?(上)
  • 配置Vite+React+TS项目
  • 云计算基础-虚拟机迁移原理
  • ChatGPT-4 Alpha:OpenAI的革命性升级
  • Doris ——SQL原理解析
  • C++中的constexpr
  • C#面:简述重载
  • 基于SpringBoot+WebSocket+Spring Task的前后端分离外卖项目-订单管理(十七)
  • 用Python和OpenCV搭建自己的一维码和QRCode扫描仪(步骤 + 源码)
  • C++学习Day05之函数调用运算符重载
  • PostgreSQL的学习心得和知识总结(一百二十八)|构建 PostgreSQL 负载测试器
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • crontab执行失败的多种原因
  • Dubbo 整合 Pinpoint 做分布式服务请求跟踪
  • HTML-表单
  • Js实现点击查看全文(类似今日头条、知乎日报效果)
  • ReactNativeweexDeviceOne对比
  • Solarized Scheme
  • vagrant 添加本地 box 安装 laravel homestead
  • Vue--数据传输
  • Web Storage相关
  • Zepto.js源码学习之二
  • 分布式熔断降级平台aegis
  • 基于Volley网络库实现加载多种网络图片(包括GIF动态图片、圆形图片、普通图片)...
  • 什么软件可以剪辑音乐?
  • 使用Tinker来调试Laravel应用程序的数据以及使用Tinker一些总结
  • Unity3D - 异步加载游戏场景与异步加载游戏资源进度条 ...
  • 数据库巡检项
  • 昨天1024程序员节,我故意写了个死循环~
  • #FPGA(基础知识)
  • (3)STL算法之搜索
  • (C)一些题4
  • (Oracle)SQL优化技巧(一):分页查询
  • (zhuan) 一些RL的文献(及笔记)
  • (附源码)spring boot校园健康监测管理系统 毕业设计 151047
  • (力扣)1314.矩阵区域和
  • (转)C语言家族扩展收藏 (转)C语言家族扩展
  • (转贴)用VML开发工作流设计器 UCML.NET工作流管理系统
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .NET Remoting学习笔记(三)信道
  • .net 微服务 服务保护 自动重试 Polly
  • .Net7 环境安装配置
  • .net与java建立WebService再互相调用
  • @font-face 用字体画图标
  • @property @synthesize @dynamic 及相关属性作用探究
  • [ C++ ] 继承
  • []error LNK2001: unresolved external symbol _m
  • [AutoSar]工程中的cpuload陷阱(三)测试
  • [C#]winform制作仪表盘好用的表盘控件和使用方法
  • [cocos2d-x]关于CC_CALLBACK
  • [FZSZOJ 1223] 上海红茶馆