medooze-media-server-client

1.5.3 • Public • Published

Medooze Media Server Client

This client libray alllows to easily connect to the Medooze Media Server with a simple API.

Features

  • Automatically sets Unified Plan SDP semantics for chrome
  • Automatically creates a new server side Transport object when a new managed PeerConnection is created by the client
  • Performs SDP offer/answer when a new track is added or removed in either client or server side
  • Synchronizes stream and tracks in client and server, creating and deleting them as appropiate
  • Perform SDP mangling for enabling simulcast in Chrome

Demo

You can find a demo in the demo directory. To run it just do:

npm i
npm run-script dist
cd demo
npm i
node index.js <your ip address>

Usage

In order to connect with the server you will need to connect via websocket and open a new transaction manager:

//Connect with websocket
const ws = new WebSocket(url);
	
//Create transaction manager 
const tm = new TransactionManager(ws);
	
//Create managed peer connection
const client = new MediaServerClient(tm);
	
//Start on open
ws.onopen = async ()=>{
  //Create new managed pc 
  pc = await client.createManagedPeerConnection();
};

Server side you will have to be listening for new clients by using the PeerConnectionserver:

const connection = request.accept(protocol);

//Create new transaction manager
const tm = new TransactionManager(connection);
   		
//Create new managed peerconnection server for this
const mngr = endpoint.createPeerConnectionServer(tm,Capabilities);
   
//LIsten for remotelly created peer connections
mngr.on("transport",(transport)=>{
 //Here you will get the transport associated to the PeerConnection created in client.createManagedPeerConnection()
});

Once you have both the managed peerconnection client and the server transport created you can add tracks in either side, for example if you do it in the browser:

//Browser
const sender = await pc.addTrack(track,stream);

Will trigger the incomingtrack event on the server transport.

//Server 
transport.on("incomingtrack",(track,stream)=>{});
  

And vice versa, a track added in the transport

//Crete empty stream
transport.createOutgoingStream(outgoingStreamId);
			
//Create ougoing track
const outgoing = outgoingStream.createTrack("video");

Will trigger the ontrack event on the managed peer connection on the browser:

//Event handler
pc.ontrack = (event) => console.log(event);

Similarily, removing the tracks on browser or stopping the tracks on the server, will trigger the appropiate event on the other side.

API

MediaServerClient

Factory object used to synchronze with the server.

constructor( transactionManager )

Creates a new client object.

  • transactionManager A transaction manager connected with the server (see TransactionManager for more info).

Promise createManagedPeerConnection(options)

Creates a new managed peer connection client object.

Addintionaly the following options can be used:

  • options.forceSDPMunging Do always SDP munging for setting up simulcast on Chrome
  • options.strictW3C Force strict W3C api compatibility (disables hacks)

This will create a new Transport object on the server.

PeerConnectionClient

Promise< RTCSender > addTrack(track,stream,params?)

Adds a new track to the client and creates a new IncomingStreamTrack (and IncomingStream if needed) server side.

  • track The track to send
  • stream The stream to send
  • params Send params (Optional)
    • codecs An array of desired codecs (eg. ["h264]), this will remove the non present codecs from the local sdp offer (Optional)
    • encodings An array of RTCRtpEncodingParameters which can be used for enabling simulcast. If the encodings array is provided it will be set accordingly on the transcevier (on the sender.setParameters if on Firefox) and if it is not supported, it will mangle the SDP for chrome adding the required ssrcs to enable simulcast (Optional)

void removeTrack(sender)

Stops sending the track, will stop the IncomingStreamTrack server side also.

  • sender The RTCSender returned on the addTrack

Promise< RTCStatsReport > getStats(selector)

Proxy for TCPeerConnection getStats.

  • selector See RTCPeerConnection getStats

void stop()

Closes local peerconnection and remote transport

attribute EventHandler ontrack

Proxy for the RTCPeerConnection ontrack event handler. As local ids will not match the remote ids anymore in WebRTC, we have extended the event to make them available:

  • remoteStreamId The stream id of the OutgoingStream on the server
  • remoteTrackId The track id of the OutgoingStreamTrack on the server

attribute EventHandler ontrackended

Event handler for the new ontrackended event. The event fired will be an RTCTrackEvent with event name trackended.

attribute EventHandler onstatsended

Proxy for the RTCPeerConnection onstatsended event handler.

Install

Just create a js bundle and link it in your web app.

npm i
npm run-script dist

You will need browserify to be installed globally, you can do it by:

npm i -g browserify

The js file will be located on the dist directory. Note that you will also need to use the Transaction Manager library.

Author

Sergio Garcia Murillo

License

MIT

Dependents (0)

Package Sidebar

Install

npm i medooze-media-server-client

Weekly Downloads

1

Version

1.5.3

License

MIT

Unpacked Size

474 kB

Total Files

13

Last publish

Collaborators

  • bryan-lester-dolby
  • mildsunrise
  • murillo128
  • sgarcia