Mediasoup Routes

how can I create multiple routers per worker in I only could create a single router per worker; I am using mediasoup for broadcasting live events with ultra low latency

below is my implementation

for (const worker of mediasoupWorkers)
		{
			const router = await worker.createRouter({ mediaCodecs });

			mediasoupRouters.set(router.id, router);
		}

:man_shrugging:

for (const worker of mediasoupWorkers)
		{
			const router = await worker.createRouter({ mediaCodecs });

			mediasoupRouters.set(router.id, router);

			const router2 = await worker.createRouter({ mediaCodecs });

			mediasoupRouters.set(router2.id, router2);
		}

I got confused with that, in my project the number of consumers grew; I am implementing a website for streaming live events like vimeo, youtube.
I am planning to make the live stream reachable to every one; my question is that how can I scale my routers so that it can accommodate large number of audience?
how can we check we automate the creation and deletion of routers in workers?

Please read the documentation, this question specifically has the whole page dedicated in documentation, take advantage of that and search the forum for numerous similar topics.

If you have something that wasn’t answered yet, I’ll try to help.

hello, the connection transport state stacks on ‘new’ below is my implementation according to the documentation

async function publish(e) {
  const isWebcam = (e.target.id === 'btn_webcam');
  $txtPublish = isWebcam ? $txtWebcam : $txtScreen;

  const data = await socket.request('createProducerTransport', {
    forceTcp: false,
    rtpCapabilities: device.rtpCapabilities,
  });
  if (data.error) {
    console.error(data.error);
    return;
  }
 
  const transport = device.createSendTransport(data);
  transport.on('connect', async ({ dtlsParameters }, callback, errback) => {
    socket.request('connectProducerTransport', { 
      transportId    : transport.id, 
      dtlsParameters 
    })
      .then(callback)
      .catch(errback);
  });
  //{ kind, rtpParameters }
  transport.on('produce', async (parameters, callback, errback) => {

    try {
      const data = await socket.request('produce', {
        transportId: transport.id,
        kind : parameters.kind,
        rtpParameters : parameters.rtpParameters

      });
      const { id } = data

      callback({ id });

    } 
    catch (err) {
      console.log('transport --> produce : error message --> ', err)
      errback(err);
    }
  });

  transport.on('connectionstatechange', (state) => {

    switch (state) {
      case 'connecting':
        $txtPublish.innerHTML = 'publishing...';
        $fsPublish.disabled = true;
        $fsSubscribe.disabled = true;
      break;

      case 'connected':
        document.querySelector('#local_video').srcObject = media_stream;
        $txtPublish.innerHTML = 'published';
        $fsPublish.disabled = true; 
        $fsSubscribe.disabled = false;
      break;

      case 'failed':
        transport.close();
        $txtPublish.innerHTML = 'failed';
        $fsPublish.disabled = false;
        $fsSubscribe.disabled = true;
      break;

      default: break;
    }
  });

  
  try {
    media_stream = await getUserMedia(transport, isWebcam);
  
    const track = media_stream.getVideoTracks()[0];
    const params = { track };
    if ($chkSimulcast.checked) {
      params.encodings = [
        { maxBitrate: 100000 },
        { maxBitrate: 300000 },
        { maxBitrate: 900000 },
      ];
      params.codecOptions = {
        videoGoogleStartBitrate : 1000
      };
    }
    producer = await transport.produce(params);

    // console.log(`tranport.produce(params) --> producer : ${JSON.stringify(producer)}`)
  }
   catch (err) {
    $txtPublish.innerHTML = 'failed';
  }

}//end of publish method

async function getUserMedia(transport, isWebcam) {
  if (!device.canProduce('video')) {
    console.error('cannot produce video');
    return;
  }

  let stream;
  try {
    stream = isWebcam ?
      await navigator.mediaDevices.getUserMedia({ video: true }) :
      await navigator.mediaDevices.getDisplayMedia({ video: true });
  } catch (err) {
    console.error('getUserMedia(transport, isWebcam) failed --> ', err.message);
    throw err;
  }
  return stream;
}

I set ip: ‘127.0.0.1’ and announcedIp: null,
I tried to debug it for days but I couldn’t get any solutions

Check the browser logs, what is it doing. For example, Firefox doesn’t allow ICE connections to the loopback interface by default.

I asked this earlier,

please read the docs:

Trust me: there is the answer to your (non) issue.

yaa, Firefox were the cause of the problem, it worked on google chrome, is there any solutions to allow ICE Connection Loop backs in Firefox

There is a config option in Firefox, “media.peerconnection.ice.loopback”. However it does not guarantee that everything will work. The most reliable way is to set ip address to ‘0.0.0.0’ and announcedIp to the address of some real local interface. I.e., something like:
listenIps: [ { ip: ‘0.0.0.0’, announcedIp: ‘192.168.1.1’ } ]
(where 192.168.1.1 is just for example).

thanks it worked; i set the local ip address of the machine using ip.address() to the announced ip address

hello, while trying to host my Livestream website on a remote server I set the announced IP to the public IP address of the server; but I got WEBRTC: ICE failed, add a stun server mediasoup in firefox, and in chrome, the connection states remain on connecting