javascriptamazon-ec2webrtcubuntu-servermediasoup

Do I have the wrong ports open for mediasoup?


I'm trying to launch this on AWS Ubuntu.

It works fine under Chrome on localhost. (There was an issue with Firefox, hopefully running remotely with HTTPS will make the problem disappear. But that's unrelated to this question.)

I opened the ports that are specified on readme.MD using the AWS console (inbound TCP to port 3000, inbound UDP to ports 40000-49999, all outgoing traffic is allowed.)

Then adapted config.json to:

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,
    },
  },
};

Using values I found on the AWS console: enter image description here (can't copy/paste this)

Subscribing to video isn't working as seen here: enter image description here (can't copy/paste this)

(After a while Chrome's console reads mediasoup-client:Transport connection state changed to disconnected +17s)

It looks to me as if I need to open an additional port or two, I'm not sure which one(s) though.

I would be very grateful for some help. Thank you in advance... :)


Solution

  • What's up with this?

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

    Try putting the public IP of your EC2 in ip, and set announcedIp to null.

    Or, do what I did here because I got sick of fiddling that config.js setting.

    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
    }
    

    And, be aware that WebRTC can connect with TLS on ports other than the mediasoup web server port.