我是否为 mediasoup 打开了错误的端口?

Do I have the wrong ports open for mediasoup?

I'm trying to launch this on AWS Ubuntu.

它在本地主机上的 Chrome 下工作正常。 (Firefox 有一个问题,希望 运行 远程使用 HTTPS 会使问题消失。但这与这个问题无关。)

我使用 AWS 控制台打开了在 readme.MD 上指定的端口(入站 TCP 到端口 3000,入站 UDP 到端口 40000-49999,允许所有传出流量。)

然后将config.json改编为:

module.exports = {
  // http server ip, port, and peer timeout constant
  //
  httpIp: "0.0.0.0",
  httpPort: 3000,
  httpPeerStale: 15000,

  // ssl certs. we'll start as http instead of https if we don't have
  // these
  sslCrt: "local.crt",
  sslKey: "local.key",

  mediasoup: {
    worker: {
      rtcMinPort: 40000,
      rtcMaxPort: 49999,
      logLevel: "debug",
      logTags: [
        "info",
        "ice",
        "dtls",
        "rtp",
        "srtp",
        "rtcp",
        // 'rtx',
        // 'bwe',
        // 'score',
        // 'simulcast',
        // 'svc'
      ],
    },
    router: {
      mediaCodecs: [
        {
          kind: "audio",
          mimeType: "audio/opus",
          clockRate: 48000,
          channels: 2,
        },
        {
          kind: "video",
          mimeType: "video/VP8",
          clockRate: 90000,
          parameters: {
            //                'x-google-start-bitrate': 1000
          },
        },
        {
          kind: "video",
          mimeType: "video/h264",
          clockRate: 90000,
          parameters: {
            "packetization-mode": 1,
            "profile-level-id": "4d0032",
            "level-asymmetry-allowed": 1,
            //                        'x-google-start-bitrate'  : 1000
          },
        },
        {
          kind: "video",
          mimeType: "video/h264",
          clockRate: 90000,
          parameters: {
            "packetization-mode": 1,
            "profile-level-id": "42e01f",
            "level-asymmetry-allowed": 1,
            //                        'x-google-start-bitrate'  : 1000
          },
        },
      ],
    },

    // rtp listenIps are the most important thing, below. you'll need
    // to set these appropriately for your network for the demo to
    // run anywhere but on localhost
    webRtcTransport: {
      listenIps: [
        { ip: "172.3.-.-", announcedIp: "18.255.8.87" },
        // { ip: "192.168.42.68", announcedIp: null },
        // { ip: '10.10.23.101', announcedIp: null },
      ],
      initialAvailableOutgoingBitrate: 800000,
    },
  },
};

使用我在 AWS 控制台上找到的值: (不能copy/paste这个)

无法订阅视频,如下所示: (不能copy/paste这个)

(过了一会儿 Chrome 的控制台显示 mediasoup-client:Transport connection state changed to disconnected +17s

在我看来,好像我需要打开一两个额外的端口,但我不确定是哪一个。

如果能提供一些帮助,我将不胜感激。提前谢谢你...:)

这是怎么回事?

listenIps: [
        { ip: "172.3.-.-", announcedIp: "18.255.8.87" },
    

尝试将您的 EC2 的 public IP 放入 ip,并将 announcedIp 设置为空。

或者,做我做的事 here 因为我厌倦了摆弄 config.js 设置。

function getListenIps () {
  const listenIps = []
  if (typeof window === 'undefined') {
    const os = require('os')
    const networkInterfaces = os.networkInterfaces()
    const ips = []
    if (networkInterfaces) {
      for (const [key, addresses] of Object.entries(networkInterfaces)) {
        addresses.forEach(address => {
          if (address.family === 'IPv4') {
            listenIps.push({ ip: address.address, announcedIp: null })
          }
          /* ignore link-local and other special ipv6 addresses.
           * https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml
           */
          else if (address.family === 'IPv6' 
                   && address.address[0] !== 'f') {
            listenIps.push({ ip: address.address, announcedIp: null })
          }
        })
      }
    }
  }
  if (listenIps.length === 0) {
    listenIps.push({ ip: '127.0.0.1', announcedIp: null })
  }
  return listenIps
}

并且请注意,WebRTC 可以在 mediasoup 网络服务器端口以外的端口上与 TLS 连接。

我遇到了同样的问题,以下事情帮助我让它工作:

1.) 确保 config.json 文件中定义的 UDP 端口(默认为 4000-4999)在用于您的 EC2 实例的安全组中被允许 OS 的防火墙(在 Ubuntu 的情况下是 ufw)。要启用 ubuntu 上的端口,您可以使用 sudo ufw allow 4000:4999/udp.

2.) 对于 listenIps,使用 [{ ip: "0.0.0.0", announcedIp: process.env.ANNOUNCED_IP }] 其中 ANNOUNCED_IP env 变量等于 Public IPV4 EC2实例的地址