Skip to content
Media Server Client
Branch: master
Clone or download
Sergio Garcia Murillo
Sergio Garcia Murillo 1.5.1
Latest commit a107031 Jun 7, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo Update transaction manager Jun 7, 2019
lib Fix pc stop #3 Jun 7, 2019
.gitignore Initial commit handle with care! Nov 13, 2018
LICENSE Initial commit Nov 8, 2018 Added stricW3C and forceSDPMunging options for createPeerConnection Jun 3, 2019
package-lock.json 1.5.1 Jun 7, 2019
package.json 1.5.1 Jun 7, 2019

Medooze Media Server Client

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


  • 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


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

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


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);
//Crete 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
 //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:

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

Will trigger the incomingtrack event on the server transport.


And vice versa, a track added in the transport

//Crete empty stream
//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.



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.


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.


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.


Sergio Garcia Murillo



You can’t perform that action at this time.