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

2024-02-10 22:12

本文主要是介绍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入门demo(代码)

这篇关于Failed to construct ‘RTCIceCandidate‘ sdpMid and sdpMLineIndex are both null的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/698157

相关文章

C++中NULL与nullptr的区别小结

《C++中NULL与nullptr的区别小结》本文介绍了C++编程中NULL与nullptr的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编... 目录C++98空值——NULLC++11空值——nullptr区别对比示例 C++98空值——NUL

解决Maven项目报错:failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题

《解决Maven项目报错:failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题》这篇文章主要介... 目录Maven项目报错:failed to execute goal org.apache.maven.pl

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

浅析Java中如何优雅地处理null值

《浅析Java中如何优雅地处理null值》这篇文章主要为大家详细介绍了如何结合Lambda表达式和Optional,让Java更优雅地处理null值,感兴趣的小伙伴可以跟随小编一起学习一下... 目录场景 1:不为 null 则执行场景 2:不为 null 则返回,为 null 则返回特定值或抛出异常场景

解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'

《解决SpringBoot启动报错:Failedtoloadpropertysourcefromlocationclasspath:/application.yml问题》这篇文章主要介绍... 目录在启动SpringBoot项目时报如下错误原因可能是1.yml中语法错误2.yml文件格式是GBK总结在启动S

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

android java.io.IOException: open failed: ENOENT (No such file or directory)-api23+权限受权

问题描述 在安卓上,清单明明已经受权了读写文件权限,但偏偏就是创建不了目录和文件 调用mkdirs()总是返回false. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_E

UserWarning: mkl-service package failed to import

安装完成anaconda,并设置了两个环境变量  之后再控制台运行python环境,输入import numpy as np,提示错误 D:\InstallFolder\Anaconda3\lib\site-packages\numpy\__init__.py:143: UserWarning: mkl-service package failed to import, therefore

Python安装llama库出错“metadata-generation-failed”

Python安装llama库出错“metadata-generation-failed” 1. 安装llama库时出错2. 定位问题1. 去官网下载llama包 2.修改配置文件2.1 解压文件2.2 修改配置文件 3. 本地安装文件 1. 安装llama库时出错 2. 定位问题 根据查到的资料,发现时llama包中的execfile函数已经被下线了,需要我们手动修改代码后

Cannot read property ‘length‘ of null while opening vscode terminal

同一问题地址:Cannot read property ‘length’ of null while opening vscode terminal 问题描述 One day, 我在ubuntu 18.04下用vscode打开一个项目,并想和往常一样在vscode使用终端,发现报错Cannot read property 'length' of null。 解决 打开setting.jso