1.问题回放

  使用如下代码获取局域网IP报错

  (代码来源:https://github.com/diafygi/webrtc-ips 日期:2019-02-16)

Uncaught (in promise) DOMException: Failed to execute 'setLocalDescription' on 'RTCPeerConnection': Failed to parse SessionDescription. a=msid:  Missing track ID in msid attribute.

 //get the IP addresses associated with an account
function getIPs(callback){
var ip_dups = {}; //compatibility for firefox and chrome
var RTCPeerConnection = window.RTCPeerConnection
|| window.mozRTCPeerConnection
|| window.webkitRTCPeerConnection;
var useWebKit = !!window.webkitRTCPeerConnection; //bypass naive webrtc blocking using an iframe
if(!RTCPeerConnection){
//NOTE: you need to have an iframe in the page right above the script tag
//
//<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
//<script>...getIPs called in here...
//
var win = iframe.contentWindow;
RTCPeerConnection = win.RTCPeerConnection
|| win.mozRTCPeerConnection
|| win.webkitRTCPeerConnection;
useWebKit = !!win.webkitRTCPeerConnection;
} //minimal requirements for data connection
var mediaConstraints = {
optional: [{RtpDataChannels: true}]
}; var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]}; //construct a new RTCPeerConnection
var pc = new RTCPeerConnection(servers, mediaConstraints); function handleCandidate(candidate){
//match just the IP address
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
var ip_addr = ip_regex.exec(candidate)[1]; //remove duplicates
if(ip_dups[ip_addr] === undefined)
callback(ip_addr); ip_dups[ip_addr] = true;
} //listen for candidate events
pc.onicecandidate = function(ice){ //skip non-candidate events
if(ice.candidate)
handleCandidate(ice.candidate.candidate);
}; //create a bogus data channel
pc.createDataChannel(""); //create an offer sdp
pc.createOffer(function(result){ //trigger the stun server request
pc.setLocalDescription(result, function(){}, function(){}); }, function(){}); //wait for a while to let everything done
setTimeout(function(){
//read candidate info from local description
var lines = pc.localDescription.sdp.split('\n'); lines.forEach(function(line){
if(line.indexOf('a=candidate:') === 0)
handleCandidate(line);
});
}, 1000);
} //Test: Print the IP addresses into the console
getIPs(function(ip){console.log(ip);});

2.分析

  代码在此处报错:pc.setLocalDescription(result, function(){}, function(){})

  即此API报错:RTCPeerConnection.setLocalDescription()

  源代码在Firefox和Chrome71正常执行,Chrome升级到72稳定版后代码报错,浏览器debug调试发现Chrome71和Chrome72的offer(代码中是result)的SDP格式/内容发生了变化,因此可以判断是新版本Chrome的WebRTC相关API发生了变化,于是在https://www.chromestatus.com/features找到了解释:

 

  文中提供了此链接:https://docs.google.com/document/d/1-ZfikoUtoJa9k-GZG1daN0BU3IjIanQ_JSscHxQesvU/edit,划重点:

    WebRTC规范仍然在演进,Chrome上目前SDP格式有两种:规范定义的SDP格式(Unified Plan)和Chrome自己定义的SDP格式(Plan B),火狐支持前者,如果不指定SDP格式Chrome72默认使用Unified Plan,这和Chrome71的行为不同,那么如何指定SDP格式呢?

  

Controlling Which SDP Format Is Used

Specifying the sdpSemantics in Your Application

You can override the default behavior by explicitly specifying the sdpSemantics in the RTCPeerConnection constructor, allowing your application to control the SDP format of the client. This flag is Chrome-only; if the browser does not recognize the parameter it is simply ignored.

// Use Unified Plan or Plan B regardless of what the default browser behavior is.

new RTCPeerConnection({sdpSemantics:'unified-plan'});

new RTCPeerConnection({sdpSemantics:'plan-b'});

Unless your application is prepared for both cases, it is recommended that you explicitly set the sdpSemantics to avoid surprises when Chrome’s default behavior changes.

3.解决

  将源代码此行

    var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};

  更改为   

    var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}], sdpSemantics:'plan-b'};

4.其他

  如果Public IP无法解析,请更换stun服务器:

    var servers = {iceServers: [{urls: "stun:stun.l.google.com:19302"}], sdpSemantics:'plan-b'}; 

WebRTC | Failed to execute 'setLocalDescription' on 'RTCPeerConnection': Failed to parse SessionDescription. a=msid: Missing track ID in msid attribute.的更多相关文章

  1. NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load xxxx错误解决方法

    在开发项目的过程中,和后端对接,我们使用是一个成熟的集成很全面的架构JHipster.后端为java spring-boot 前端ts+react,需求是有一个需要在页面里嵌套iframe的需求.然后 ...

  2. mui.min.js:7 Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load

    mui框架做的微信公众号网页,在上传数据的时候报了这个错,async: true,//将false改为true就可以了 https://blog.csdn.net/liuzp111/article/d ...

  3. maven install Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang

    maven打包成war时,报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default- ...

  4. Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (dist) on project hadoop-kms: An Ant BuildException has occured

    编译cdh版hadoop2.5.0出现的问题 系统: CentOs66 64位 JDK:1.7 Maven: 3.0.5 Protobuf: libprotoc 2.5.0 编译命令: mvn pac ...

  5. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project LogTest: Compilation failure -> [Help 1]

      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default ...

  6. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:

    security-sdk-1.0.jar已经存在于D:/secServerSDK-test/src/main/resources/lib下 报错如下: xxxxxx@xxxxxxxx /d/secSe ...

  7. 错误解决:SharePoint Designer 2010编辑后,出现数据源控件未能执行插入命令,data source control failed to execute the insert command

    打了SharePoint 2010 最新的SP 2的补丁,但是使用SharePoint Designer 2010 定义任何一个列表的“插入视图”时,总是出现标题那样的错误: 数据源控件未能执行插入命 ...

  8. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of 3: mojo org.apache.maven.plugins:

    问题: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (defau ...

  9. Failed to execute request because the App-Domain could not be created.

    原错误信息: 服务器应用程序不可用 您试图在此 Web 服务器上访问的 Web 应用程序当前不可用.请点击 Web 浏览器中的“刷新”按钮重试您的请求. 管理员注意事项: 详述此特定请求失败原因的错误 ...

随机推荐

  1. Android回炉系列之四大组件之首Activity

            有段时间没有认认真真研习过android了,android毕竟是我进这个软件开发圈子接触的第一门技术,android已经成了口头禅之类的东西了.当初学习android的时候大都是草草了 ...

  2. testng+selnium+eclipse的测试框架运用

    一:TestNG在Eclipse中的安装(1)点击eclipse中的Help->Install New Software (2)点击[Add]按钮,输入相应的地址(3)勾选加载出来的TestNG ...

  3. js浏览器问题

    前段时间做了个项目,里面关于手机移动端下载的问题 开始是判断微信.ios和android系统的下载 因为微信屏蔽点击事件和链接的缘故,需要通过打开新页面来进行下载 ios和android的下载分别为不 ...

  4. Python_study_day_1_while_if

    1.什么是计算机 cpu:大脑 3GHz 内存:缓冲硬盘和cpu,提高计算机运算速度 硬盘:存储数据 2.编程语言的简单分类 编译型,解释型,混合型 3.python是什么编程语言 解释类语言 //. ...

  5. BZOJ 1396 识别子串 (后缀自动机+线段树)

    题目大意: 给你一个字符串S,求关于每个位置x的识别串T的最短长度,T必须满足覆盖x,且T在S中仅出现一次 神题 以节点x为结尾的识别串,必须满足它在$parent$树的子树中只有一个$endpos$ ...

  6. Mysql怎么样避免全表扫描,sql查询优化

    对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引: 尝试下面的技巧以避免优化器错选了表扫描: 使用ANALYZE TABLE tbl_name为扫 ...

  7. Html 播放 mp4格式视频提示 没有发现支持的视频格式和mime类型

    转自原文 Html 播放 mp4格式视频提示 没有发现支持的视频格式和mime类型 播放mp4格式的时候提示 Html 播放 mp4格式视频提示 没有发现支持的视频格式和mime类型 原因是在IIS中 ...

  8. [CSS3] All abourt responsive image

    Take few examples: Full size image: The problem for that is it overflow when the screen size is smal ...

  9. leetcode第一刷_Subsets II

    要求子集,有很现成的方法.N个数.子集的个数是2^N.每一个元素都有在集合中和不在集合中两种状态,这些状态用[0,pow(2,N)]中每一个数来穷举,假设这个数中的第i位为1,说明当前集合中包括源数组 ...

  10. 在fragment中显示对话框出现异常

    异常类型为:android.view.WindowManager$BadTokenException: Unable to add window 我在fragment中public View onCr ...