Giter VIP home page Giter VIP logo

media-server-node's Introduction

WebRTC Medooze Media Server for Node.js

This media server will allow you to receive and send media streams from remote WebRTC peers and manage how you want to route them.

Supported systems:

  • Linux
  • Mac Os X
  • Raspberry Pi

Install

Just add the Medooze media server as a dependency to your node proyect:

    npm i --save medooze-media-server

Distribution

If you don't want to compile the native code each time you use the media server, you could precompile Medooze Media server and generate a binary package for your platform. On the Medooze media server directory just do:

   git submodule update
   npm i
   npm run-script dist

It will generate the binary package in dist\medooze-media-server-x.y.x.tgz.

To use it on your project just install it instead of the npm repository dependency:

    npm i --save medooze-media-server-x.y.x.tgz

Usage

const MediaServer = require('medooze-media-server');

API Documention

You can check the full object documentation here.

Support

To discuss issues related to this project or ask for help please join the google community group.

Demo application

You can check a demo application here

Functionality

We intend to implement support the following features:

Tutorial

Intialization

First import both Medooze media server and Semantic SDP dependecies:

//Get the Medooze Media Server interface
const MediaServer = require('medooze-media-server');
const SemanticSDP = require("semantic-sdp");

Then you need to create an Endpoint, which will create an UDP socket for receiving connection. You need to pass the ip address in which this Enpoint will be accesible by the WebRTC clients. This is typically the public IP address of the server, ans will be used on the ICE candidates sent to the browser on the SDP.

//Create UDP server endpoint
const endpoint = MediaServer.createEndpoint(ip);

Now you are ready to connect to your server.

Connect a client

On your browser, create an SDP offer and sent it to your server (via websockets for example). Once you have it, you will have to parse it to extract the requried information. With that information, you can create an ICE+DTLS transport on the Endpoint.

//Process the sdp
var offer = SemanticSDP.SDPInfo.process(sdp);

//Create an DTLS ICE transport in that enpoint
const transport = endpoint.createTransport({
	dtls : offer.getDTLS(),
	ice  : offer.getICE() 
});

Now set the RTP remote properties for both audio and video:

//Set RTP remote properties
 transport.setRemoteProperties({
	audio : offer.getMedia("audio"),
	video : offer.getMedia("video")
});

You can start creating the answer now. First get the ICE and DTLS info from the Transport and the ICE candidate into from the Endpoint

//Get local DTLS and ICE info
const dtls = transport.getLocalDTLSInfo();
const ice  = transport.getLocalICEInfo();

//Get local candidates
const candidates = endpoint.getLocalCandidates();

//Create local SDP info
const answer = new SDPInfo();

//Add ice and dtls info
answer.setDTLS(dtls);
answer.setICE(ice);
//Add candidates
answer.addCandidate(candidates);

Choose your codecs and set RTP parameters to answer the offer:

//Get remote audio m-line info 
const audioOffer = offer.getMedia("audio");

//If we have audio
if (audioOffer)
{
	//Create audio media
	const audio = audioOffer.answer({
		codecs		: CodecInfo.MapFromNames(["opus"]),
		extensions	: new Set([
			"urn:ietf:params:rtp-hdrext:ssrc-audio-level",
			"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
	]);
	//Add it to answer
	answer.addMedia(audio);
}

//Get remote video m-line info 
const videoOffer = offer.getMedia("video");

//If offer had video
if (videoOffer)
{
	//Create video media
	const  video = videoOffer.answer({
		codecs		: CodecInfo.MapFromNames(["vp9","flexfec-03"],true),
		extensions	: new Set([
			"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
			"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
		])
	});
	//Add it to answer
	answer.addMedia(video);
}

Set the our negotiated RTP properties on the transport

//Set RTP local  properties
transport.setLocalProperties({
	audio : answer.getMedia("audio"),
	video : answer.getMedia("video")
});

Stream management

You need to process the stream offered by the client, so extract the stream info from the SDP offer, and create an IncomingStream object.

//Get first stream offered
const offered = offer.getStreams()[0];

//Create the remote stream into the transport
const incomingStream = transport.createIncomingStream(offered);

Now, for example, create an outgoing stream, and add it to the answer so the browser is aware of it.

//Create new local stream
const outgoingStream  = transport.createOutgoingStream({
	audio: true,
	video: true
});

//Get local stream info
const info = outgoingStream.getStreamInfo();

//Add local stream info it to the answer
answer.addStream(info);

You can attach an OutgoingStream to an IncomingStream, this will create a Transponder array that will forward the incoming data to the ougoing stream, it will allow you also to apply transoformations to it (like SVC layer selection).

In this case, as you are attaching an incoming stream to an outgoing stream from the same client, you will get audio and video loopback on the client.

//Copy incoming data from the remote stream to the local one
const transponders = outgoingStream.attachTo(incomingStream);

You can now send answer the SDP to the client.

//Get answer SDP
const str = answer.toString();

Recording

Playback

Streaming

Author

Sergio Garcia Murillo @ Medooze

Contributing

To get started, Sign the Contributor License Agreement.

License

MIT

media-server-node's People

Contributors

murillo128 avatar josemrecio avatar aksperiod avatar nicholi avatar pierrefritsch avatar codacy-badger avatar

Watchers

James Cloos avatar wisherzhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.