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

rtsp-streaming-server

v2.0.6

Published

Lightweight RTSP/RTP streaming media server written in Javascript

Downloads

565

Readme

rtsp-streaming-server

Lightweight RTSP/RTP streaming media server written in Javascript.

First things first, credit to @revmischa for their work on the perl-based server. This is basically a blatant rip-off of that but ported to Javascript (and now typescript!). See the original here revmischa/rtsp-server

Use this module to run an RTSP server in javascript. Common use case is for load balancing

Running

npm install --save rtsp-streaming-server

Add the following to your script where you want to run the server:


import RtspServer from 'rtsp-streaming-server'

const server = new RtspServer({
	serverPort: 5554,
	clientPort: 6554,
	rtpPortStart: 10000,
	rtpPortCount: 10000
});


async function run (): void {
	try {
		await server.start();
	} catch (e) {
		console.error(e);
	}
}

run();

If you're using javascript, you'll have to require the default export:

const RtspServer = require('rtsp-streaming-server').default;

Use an RTSP producer that supports ANNOUNCE (such as ffmpeg):

ffmpeg -i <your_input>.mp4 -c:v copy -f rtsp rtsp://127.0.0.1:5554/stream1

Consume that stream from your favourite RTSP Client (note that you have to use the client port, not the publish port):

ffplay -i rtsp://127.0.0.1:6554/stream1

stream1 can be whatever you want, this server supports many producers and consumers on different mount points

Options

  • serverPort: port to listen to incoming RTSP/RTP streams from producers on
  • clientPort: port to listen to incoming RTSP requests from clients on
  • rtpPortStart: UDP port to start at for requests
  • rtpPortCount: Number of UDP Ports to use for requests. This needs to be a multiple of 2 as pairs of ports are assigned for RTP sessions. If this is set too low and it runs out then no more streams will work
  • publishServerHooks: object of hooks for the publishing server
  • clientServerHooks: object of hooks for the client server

Hooks

Hooks are ways to allow / disallow connections to the server based on certain conditions. These need to be placed in the publishServerHooks or clientServerHooks objects

Authentication is to authenticate users connecting. A failed authentication sends a 401.

async function authentication (username: string, password: string): Promise<boolean> {
	if (username === 'test' && password === 'test') return true;
	
	return false;
}

Check mount is to allow / deny publishing or consuming depending on the uri of the stream being requested:

async function checkMount (req: RtspRequest): Promise<boolean | number> {
  const url = new URL(req.uri);
  if (url.pathname === '/test/1') {
    return true;
  }

	// If you want to reject the client side consuming with a specific code, return a number:
	if (somereason) {
		return 503; //Bad Gateway
	}

  return false;
}

Client Close is to do some tidy up when a client leaves (i.e you might want to signal to your publisher it can stop the stream). This is only valid in clientServerHooks

async function clientClose (mount: Mount): Promise<void> {
  console.log(`A client has disconnected from ${mount.path}`);
}

Typescript information

If you're wanting to access any of the internal server components that reference the rtsp-server module, you'll have to add the types for this module types/rtsp-server.d.ts to your own project. These types are not in the server module itself.

Improvements coming soon (or PR's welcome!)

  • RTP interleaved in RTSP (RTP over RTSP)
  • Check RTP is being received by the server and tear down the connection / mount if not