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

medooze-media-server-client

v1.5.3

Published

Medooze Media Server Client

Downloads

8

Readme

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.

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