首页 > 解决方案 > Ubuntu 和 Puppeteer 没有 srvflx 地址

问题描述

我想做的事

使用https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/收集 srvflx 候选。

问题:

无法在 Ubuntu Server(Linux) 上接收 srvflx 候选。在 Windows 上工作。

重现步骤:

操作系统 Ubuntu 19.04 安装 设置木偶:
    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);
    })();
输出窗口
[
        {
                "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"
            }
    ]

标签: ubuntuwebrtcpuppeteer

解决方案


如果您的机器配置了公共 IP 并且不在 NAT 后面(这是 ubuntu 的候选主机建议),则不会返回 srflx 候选,因为 serverreflexive 地址与主机地址相同。有关详细信息,请参阅https://www.rfc-editor.org/rfc/rfc8445#section-5.1.3


推荐阅读