WebRTC,ice 候选连接 [英] WebRTC, ice candidates connection
问题描述
我正在尝试学习如何使用 webRTC 在应用程序中,所以我在以下链接中编写了一个代码示例:http://wklej.org/hash/fd599a32e8e/
I'm trying to learn how to use webRTC in applications so I wrote a code sample available in the following link: http://wklej.org/hash/fd599a32e8e/
一开始我想说我不关心浏览器的兼容性,我只需要支持 Chromium web 引擎,不需要任何外部适配器/其他库.
At the beginning I need to say that I don't care about browsers compatibility, All I need is to support Chromium web engine without any external adapters/other libraries.
Web 应用程序应该允许我在同一主机上运行的两个浏览器选项卡之间建立连接 - 通过手动交换适当的数据 (SDP 和 ICE 候选人).
The web application should allow me to establish a connection between two browser tabs running on the same host — by manually exchange of appropriate data (SDP and ICE candidates).
要遵循的步骤:
- 点击创建报价按钮",复制本地SDP;
- 转到其他选项卡,将之前复制的 SDP 插入远程 SDP"区域,然后按创建答案";
- 复制生成的本地 SDP,转到第一个选项卡,插入远程 SDP"区域并单击设置远程 sdp"按钮(不是创建应答按钮);
- 交换 ice 候选 — 从一个选项卡中复制它们,插入到第二个选项卡中,然后按addCandidates"按钮.以另一种方式做同样的事情.
主要问题是这个函数:
peer.iceconnectionstatechange = function(event) {
console.log("ice connection state: " + peer.iceConnectionState)
}
不会被触发.我尝试使用 STUN/TURN 服务器而没有成功.远程视频将无法运行.如果有人能指出我哪里出错了?
won't be triggered. I tried to play with STUN/TURN servers without success. The remote video won't run. If somebody could point out where I made mistake?
推荐答案
Try mine (cut'n'paste): https://jsfiddle.net/7vv2vxtt/
Try mine (cut'n'paste): https://jsfiddle.net/7vv2vxtt/
或自动(localStorage):https://jsfiddle.net/2v1Lnpmx/
Or automatic (localStorage): https://jsfiddle.net/2v1Lnpmx/
This code intentionally left blank.
ICE 候选人会随着时间的推移被添加到本地报价/答案中,因此它只需等待候选人结束,然后再生成嵌入所有候选人的 SDP.
ICE candidates get added to the local offer/answer over time, so it simply waits for end-of-candidates before producing SDP with all candidates embedded.
应该适用于所有浏览器.
Should work in all browsers.
这篇关于WebRTC,ice 候选连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!