首页 > 解决方案 > 我是否为 mediasoup 打开了错误的端口?

问题描述

我正在尝试在 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 控制台上找到的值:( 在此处输入图像描述 无法复制/粘贴)

订阅视频不起作用,如此处所示:( 在此处输入图像描述 无法复制/粘贴)

(一段时间后,Chrome 的控制台显示mediasoup-client:Transport connection state changed to disconnected +17s

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

我将非常感谢一些帮助。先感谢您... :)

标签: javascriptamazon-ec2webrtcubuntu-servermediasoup

解决方案


这是怎么回事?

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

尝试将您的 EC2 的公共 IP 放入ip,并设置announcedIp为 null。

或者,做我在这里所做的,因为我厌倦了摆弄 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 Web 服务器端口以外的端口上使用 TLS 连接。


推荐阅读