npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mediasoup-server

v1.0.7

Published

WebRTC SFU mediasoup implementation

Downloads

14

Readme

mediasoup-server

WebRTC SFU mediasoup implementation

Installation

How to use library

Install NPM modules

Python 2, make, g++ or clang are required for installing mediasoup.

$ npm install mediasoup-server

Run WebRTC server

const WebRtcServer = require('mediasoup-server').WebRtcServer;

const hostname = os.hostname();

const webRtcServer = new WebRtcServer();
webRtcServer
.listen({
	enableDebug: true,
	key: fs.readFileSync('keys/server.key'),
	cert: fs.readFileSync('keys/server.crt'),
	port: 3888,
	path: 'public',
})
.on('listen', () => {
	console.log('Mediasoup demo started');
})
.on('web-listen', (port) => {
	console.log(`Open https://${hostname}:${port} with browser`);
})
.on('new-connection', (connection) => {
	console.log(`New connection [${connection.id}]`);
	
	connection
	.on('error', (err) => {
		console.log(`Connection [${connection.id}] error: ${err}`);
	})
	.on('receive', (action, data) => {
		console.log(`Connection [${connection.id}] receive [${action}]`);
	})
	.on('send', (action, data) => {
		console.log(`Connection [${connection.id}] send [${action}]`);
	})
	.on('new-stream', (stream) => {
		console.log(`Connection [${connection.id}] peer [${stream.peer.id}] new stream [${stream.id}]`);
	})
	.on('ready', (peerConnection) => {
		console.log(`Connection [${connection.id}] peer [${peerConnection.peer.id}] ready`);
	})
	.on('close', (peerId) => {
		console.log(`Connection [${connection.id}] peer [${peerId}] closed`);
	})
	.on('disconnect', (err) => {
		console.log(`Connection [${connection.id}] signaling disconnected`);
		connection = null;
	});
});

Run RTSP server

const RtspServer = require('mediasoup-server').RtspServer;

const rtspServer = new RtspServer(webRtcServer);
rtspServer
.listen(5000)
.on('listen', (port) => {
	console.log(`RTSP server started rtsp://${hostname}:${port}`);
})
.on('new-source', (source) => {
	let rtspUrl = `rtsp://${hostname}:${rtspServer.port}/${source.id}.sdp`;
	source.on('enabled', () => {
		console.log(`RTSP source available: ${rtspUrl}`);
	});
});

Record to disc

const rtspServer = new RtspServer(webRtcServer);
rtspServer
.listen(5000)
.on('new-source', (source) => {
	source.on('enabled', () => {
		let rtspUrl = `rtsp://${hostname}:${rtspServer.port}/${source.id}.sdp`;
		let filepath = `${recordingsPath}/${source.id}.mp4`;
		let logpath = `${recordingsPath}/${source.id}.log`;
		
		console.log(`Recording [${source.id}]: ${filepath}`);
		let process = streamer.record(rtspUrl, filepath, logpath)
		.on('error', (err) => {
			console.error(`Streamer [${source.id}] error: ${err}`);
		})
		.on('exit', (code, signal) => {
			console.log(`Streamer [${source.id}] closed, log: ${logpath}`);
		});
	});
});

Publish to RTMP server

const rtspServer = new RtspServer(webRtcServer);
rtspServer
.listen(5000)
.on('new-source', (source) => {
	source.on('enabled', () => {
		let rtspUrl = `rtsp://${hostname}:${rtspServer.port}/${source.id}.sdp`;
		let rtmpUrl = `rtmp://${hostname}:1935/live/${source.id}`;
		let logpath = `${recordingsPath}/${source.id}.log`;
		
		console.log(`Publishing [${source.id}]: ${rtmpUrl}`);
		let process = streamer.publish(rtspUrl, rtmpUrl, logpath)
		.on('error', (err) => {
			console.error(`Streamer [${source.id}] error: ${err}`);
		})
		.on('exit', (code, signal) => {
			console.log(`Streamer [${source.id}] closed, log: ${logpath}`);
		});
	});
});

How to use example

Git clone

git clone https://github.com/tan-tan-kanarek/mediasoup-server.git
cd mediasoup-server/

Install NPM modules

Python 2, make, g++ or clang are required for installing mediasoup.

$ npm install

Run server example

$ node example

or

$ npm start

access with borwser

TODO

Server

  • Execute ffmpeg remotely (send message to different server to execute ffmpeg)
  • To support scalability and redundancy, hold list of rooms in all servers and redirect socket.io commands to the server that handles the room, SDPs should be generated on the server that holds the room.

Client

  • Rejoin room when socket.io reconnected.
  • Accept new room created event.