How to use mediasoup - 10 common examples

To help you get started, we’ve selected a few mediasoup examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kurento / mediasoup-demos / mediasoup-recording / server.js View on Github external
async function handleStartMediasoup(vCodecName) {
  const worker = await Mediasoup.createWorker(CONFIG.mediasoup.worker);
  global.mediasoup.worker = worker;

  worker.on("died", () => {
    console.error(
      "mediasoup worker died, exit in 3 seconds... [pid:%d]",
      worker.pid
    );
    setTimeout(() => process.exit(1), 3000);
  });

  console.log("mediasoup worker created [pid:%d]", worker.pid);

  // Build a RouterOptions based on 'CONFIG.mediasoup.router' and the
  // requested 'vCodecName'
  const routerOptions = {
    mediaCodecs: []
github Kurento / mediasoup-demos / mediasoup-kurento-filter / server.js View on Github external
async function handleStartMediasoup() {
  const worker = await Mediasoup.createWorker(CONFIG.mediasoup.worker);
  global.mediasoup.worker = worker;

  worker.on("died", () => {
    console.error(
      "mediasoup worker died, exit in 3 seconds... [pid:%d]",
      worker.pid
    );
    setTimeout(() => process.exit(1), 3000);
  });

  console.log("mediasoup worker created [pid:%d]", worker.pid);

  const router = await worker.createRouter(CONFIG.mediasoup.router);
  global.mediasoup.router = router;

  // At this point, the computed router.rtpCapabilities includes the
github daily-co / mediasoup-sandbox / single-page / server.js View on Github external
async function startMediasoup() {
  let worker = await mediasoup.createWorker({
    logLevel: config.mediasoup.worker.logLevel,
    logTags: config.mediasoup.worker.logTags,
    rtcMinPort: config.mediasoup.worker.rtcMinPort,
    rtcMaxPort: config.mediasoup.worker.rtcMaxPort,
  });

  worker.on('died', () => {
    console.error('mediasoup worker died (this should never happen)');
    process.exit(1);
  });

  const mediaCodecs = config.mediasoup.router.mediaCodecs;
  const router = await worker.createRouter({ mediaCodecs });

  // audioLevelObserver for signaling active speaker
  //
github footniko / mediasoup-sample / server / index.js View on Github external
const app = require('http').createServer();
const io = require('socket.io')(app);
const config = require('./config');
const mediasoup = require('mediasoup');
const port = config.server.port;

// Map of Room instances indexed by roomId.
const rooms = new Map();

app.listen(port, () => console.log(`MediaSoup server is listening on port ${port}!`));

// MediaSoup server
const mediaServer = mediasoup.Server({
  numWorkers: null, // Use as many CPUs as available.
  logLevel: config.mediasoup.logLevel,
  logTags: config.mediasoup.logTags,
  rtcIPv4: config.mediasoup.rtcIPv4,
  rtcIPv6: config.mediasoup.rtcIPv6,
  rtcAnnouncedIPv4: config.mediasoup.rtcAnnouncedIPv4,
  rtcAnnouncedIPv6: config.mediasoup.rtcAnnouncedIPv6,
  rtcMinPort: config.mediasoup.rtcMinPort,
  rtcMaxPort: config.mediasoup.rtcMaxPort
});

// Handle socket connection and its messages
io.on('connection', (socket) => {
  console.log('New socket connection:', socket.handshake.query);

  // Used for mediaSoup room
github michaelfig / mediasoup-broadcast-example / server / wsserver.js View on Github external
if (process.env.RTC_ANNOUNCED_IPV4) {
    // This is the external IP address that routes to the current
    // instance.  For cloud providers or Kubernetes, this
    // will be a different address than the connected network
    // interface will use.
    msOptions.rtcAnnouncedIPv4 = process.env.RTC_ANNOUNCED_IPV4;
}
if (process.env.RTC_ANNOUNCED_IPV6) {
    msOptions.rtcAnnouncedIPv6 = process.env.RTC_ANNOUNCED_IPV6;
}
if (process.env.LOG_LEVEL) {
    console.log('Setting logLevel to', process.env.LOG_LEVEL)
    msOptions.logLevel = process.env.LOG_LEVEL;
    msOptions.logTags = [ 'info', 'ice', 'dlts', 'rtp', 'srtp', 'rtcp', 'rbe', 'rtx' ];
}
const ms = mediasoup.Server(msOptions);

const PUBLISHER_PEER = 'publisher';
const rooms = {};
const MEDIA_CODECS = [
    {
      kind        : "audio",
      name        : "opus",
      clockRate   : 48000,
      channels    : 2,
      parameters  :
      {
        useinbandfec : 1
      }
    },
    /*
    // FIXME: Safari 11 doesn't suppport vp8, so we need just h264 for portability.
github ethand91 / mediasoup3-record-demo / server / src / mediasoup.js View on Github external
const mediasoup = require('mediasoup');

const config = require('./config');

console.log('mediasoup loaded [version:%s]', mediasoup.version);

let workers = [];
let nextWorkerIndex = 0;

// Start the mediasoup workers
module.exports.initializeWorkers = async () => {
  const { logLevel, logTags, rtcMinPort, rtcMaxPort } = config.worker;

  console.log('initializeWorkers() creating %d mediasoup workers', config.numWorkers);

  for (let i = 0; i < config.numWorkers; ++i) {
    const worker = await mediasoup.createWorker({
      logLevel, logTags, rtcMinPort, rtcMaxPort
    });

    worker.once('died', () => {
github havfo / multiparty-meeting / server / mediasoup.js View on Github external
const mediasoup = require('mediasoup');
const readline = require('readline');
const colors = require('colors/safe');
const repl = require('repl');
const homer = require('./lib/homer');
const config = require('./config');

// mediasoup server.
const mediaServer = mediasoup.Server(
	{
		numWorkers       : 1,
		logLevel         : config.mediasoup.logLevel,
		logTags          : config.mediasoup.logTags,
		rtcIPv4          : config.mediasoup.rtcIPv4,
		rtcIPv6          : config.mediasoup.rtcIPv6,
		rtcAnnouncedIPv4 : config.mediasoup.rtcAnnouncedIPv4,
		rtcAnnouncedIPv6 : config.mediasoup.rtcAnnouncedIPv6,
		rtcMinPort       : config.mediasoup.rtcMinPort,
		rtcMaxPort       : config.mediasoup.rtcMaxPort
	});

// Do Homer stuff.
if (process.env.MEDIASOUP_HOMER_OUTPUT)
	homer(mediaServer);
github tan-tan-kanarek / mediasoup-server / lib / connection.js View on Github external
'use strict';

const EventEmitter = require('events');

const mediasoup = require('mediasoup');
const RTCPeerConnection = mediasoup.webrtc.RTCPeerConnection;

class WebRtcConnection extends EventEmitter {
	constructor(server, socket){
		super();

		this.server = server;
		this.socket = socket;
		this.peerConnection = null;

		this.id = socket.id;
		this.sdp = null;
		this.roomId = null;
		this.mediaPeer = null;

		// socket.io
		socket.on('disconnect', () => {
github mkhahani / mediasoup-sample-app / server.js View on Github external
async function runMediasoupWorker() {
  worker = await mediasoup.createWorker({
    logLevel: config.mediasoup.worker.logLevel,
    logTags: config.mediasoup.worker.logTags,
    rtcMinPort: config.mediasoup.worker.rtcMinPort,
    rtcMaxPort: config.mediasoup.worker.rtcMaxPort,
  });

  worker.on('died', () => {
    console.error('mediasoup worker died, exiting in 2 seconds... [pid:%d]', worker.pid);
    setTimeout(() => process.exit(1), 2000);
  });

  const mediaCodecs = config.mediasoup.router.mediaCodecs;
  mediasoupRouter = await worker.createRouter({ mediaCodecs });
}
github havfo / multiparty-meeting / server / server.js View on Github external
async function runMediasoupWorkers()
{
	const { numWorkers } = config.mediasoup;

	logger.info('running %d mediasoup Workers...', numWorkers);

	for (let i = 0; i < numWorkers; ++i)
	{
		const worker = await mediasoup.createWorker(
			{
				logLevel   : config.mediasoup.worker.logLevel,
				logTags    : config.mediasoup.worker.logTags,
				rtcMinPort : config.mediasoup.worker.rtcMinPort,
				rtcMaxPort : config.mediasoup.worker.rtcMaxPort
			});

		worker.on('died', () =>
		{
			logger.error(
				'mediasoup Worker died, exiting  in 2 seconds... [pid:%d]', worker.pid);

			setTimeout(() => process.exit(1), 2000);
		});

		mediasoupWorkers.push(worker);

mediasoup

Cutting Edge WebRTC Video Conferencing

ISC
Latest version published 30 days ago

Package Health Score

87 / 100
Full package analysis