我想做的事
使用https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/收集一个 srvflx 候选人。
问题:
无法在 Ubuntu Server(Linux) 上接收 srvflx 候选。在 Windows 上工作。
重现步骤:
操作系统 Ubuntu 19.04 安装
sudo apt-get update && apt-get upgrade
sudo ufw disable
curl ipecho.net/plain
//返回一个可 ping 通的 ip 设置 puppeteer :
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash - && sudo apt-get install -y nodejs
mkdir -p /tmp/puppeteertest && cd /tmp/puppeteertest && npm init
npm i puppeteer --save
sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: [
"--no-sandbox",
"--disable-features=WebRtcHideLocalIpsWithMdns",
"--disable-setuid-sandbox"
]
});
const pages = await browser.pages();
const page = pages[0];
await page.goto('https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/');
// Start gathering
await page.click("#gather");
await page.waitFor(5000);
// Scrape candidates
const respItems = [];
const tableContainer = await page.$('#candidatesBody');
const trsElem = await tableContainer.$$('tr');
for (let trElem of trsElem) {
const dataList = await trElem.$$eval('td', tdsElem => tdsElem.map(td => td.innerText));
respItems.push({
time: dataList[0],
compoment: dataList[1],
type: dataList[2],
foundation: dataList[3],
protocol: dataList[4],
address: dataList[5],
port: dataList[6],
priority: dataList[7],
});
};
console.log(JSON.stringify(respItems, null, "\t"));
await browser.close();
process.exit(0);
})();
跑
node index.js
输出窗口
[
{
"time": "0.009",
"compoment": "rtp",
"type": "host",
"foundation": "1879246603",
"protocol": "udp",
"address": "[LOCAL IP]",
"port": "55810",
"priority": "126 | 30 | 255"
},
{
"time": "0.028",
"compoment": "rtp",
"type": "srflx",
"foundation": "842163049",
"protocol": "udp",
"address": "[PUBLIC IP]",
"port": "55810",
"port": "55810",
"priority": "126 | 30 | 255"
},
{
"time": "0.028",
"compoment": "rtp",
"type": "srflx",
"foundation": "842163049",
"protocol": "udp",
"address": "[PUBLIC IP]",
"port": "55810",
"priority": "100 | 30 | 255"
},
{
"time": "0.110",
"compoment": "Done"
},
{
"time": "0.112"
}
]
输出 Ubuntu
[
{
"time": "0.007",
"compoment": "rtp",
"type": "host",
"foundation": "3461618340",
"protocol": "udp",
"address": "[PUBLIC IP]",
"port": "45743",
"priority": "126 | 30 | 255"
},
{
"time": "0.109",
"compoment": "Done"
},
{
"time": "0.111"
}
]
最佳答案
如果您的机器配置了公共(public) IP 并且不在 NAT 后面(这是 ubuntu 的候选主机建议),则不会返回 srflx 候选,因为 serverreflexive 地址与主机地址相同。见 https://www.rfc-editor.org/rfc/rfc8445#section-5.1.3详情。
关于ubuntu - Ubuntu 和 Puppeteer 没有 srvflx 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59142220/