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

media-rtsp

v1.0.1

Published

RTSP Server for NodeJS support tcp/udp

Downloads

15

Readme

RTSP Server:

rtsp tcp/udp media server

Support protocol:

  • TCP
  • UDP

Testing:

  • tcp->tcp
  • udp->udp
  • tcp->udp
  • udp->tcp

Usage:


(async () => {
    /**
     * Test debug function
     * @param argument
     * @private
     */
    const _debug = (...argument) => {
        console.info.apply(this, ['['+Date.now()+']', ...argument]);
    }
    
    /**
     * Config server
     * @type {object}
     */
    const CONFIG = {
        // * Port server listen (Default: 544)
        "port" : 5544,
        // * Host server listen (Default: 127.0.0.1)
        "host" : "127.0.0.1",
        // * Name of the server (Use in response header) (Default: RTSP SERVER)
        "serverName" : "RTSP SERVER",
        // * Require request access permission from (method: access(name, callback)) (Default: empty)
        "access" : ["auth", "media"],
        // * Port udp range (Default: 56000-57000)
        "portList" : {
            "start" : 56000, 
            "end" : 57000
        }
    };
    
    const RTSP_SERVER = require('media-rtsp');
    
    // Create server
    const rtspServer = new RTSP_SERVER(CONFIG);

    /**
     * Event connection new client
     * @event connect
     */
    rtspServer.on('connect', (clientObject) => {

        clientObject.on('RTSP:command', (command, data) => {
            console.debug('RTSP:command', command, clientObject.getID(), data);
        });

        clientObject.on('write', (message, isCommand) => {
            if(isCommand){
                console.debug('write', clientObject.getID(), message);
            }

        });

        /**
         * Event auth client
         * @event auth
         */
        clientObject.on('auth', () => {
            _debug(
                'event:[client|auth]',
                'ID: '+clientObject.getID(),
                'HeaderData: '+clientObject.getHeaderData()
            );
        });

        /**
         * Event create new media object from client
         * @event media
         */
        clientObject.on('media', (mediaObject) => {

            /**
             * Event destroy media object
             */
            mediaObject.once('destroy', () => {
                _debug(
                    'event:[client|media|destroy]',
                    'ID: '+mediaObject.getID(),
                    'Name: '+mediaObject.getName(),
                    'Type: '+mediaObject.getType(),
                    'ClientID: '+clientObject.getID(),
                    'DestroyInfo: '+mediaObject.getDestroy(),
                );
            });

            _debug(
                'event:[client|media|create]',
                'ID: '+mediaObject.getID(),
                'Name: '+mediaObject.getName(),
                'Type: '+mediaObject.getType(), // publish, views
                'ClientID: '+clientObject.getID(),
            );
        });


        /**
         * Event destroy client
         */
        clientObject.on('destroy', () => {
            _debug(
                'event:[client|destroy]',
                'ID: '+clientObject.getID(),
                'DestroyInfo: '+clientObject.getDestroy()
            );
        });

        _debug(
            'event:[client|connect]',
            'ID: '+clientObject.getID()
        );
    });


    /**
     * Event listen server
     * @event listen
     */
    rtspServer.on('listen', () => {
        _debug(
            'event:[listen]',
            'Host: '+rtspServer.getHost(),
            'Port: '+rtspServer.getPort()
        );
    });


    /**
     * Client authorization request
     * @param clientObject
     * @returns {Promise<object>|boolean|Error}
     */
    rtspServer.access('auth', async (clientObject) => {
        _debug('request:[access|auth]',
            'ClientID: '+clientObject.getID(),
            'HeaderData: '+clientObject.getHeaderData()
        );
        return true;
    });


    /**
     * Client create media request
     * @param mediaObject
     * @returns {Promise<object>|boolean|Error}
     */
    rtspServer.access('media', async (mediaObject, clientObject) => {
        _debug(
            'request:[access|media]',
            'MediaID: '+mediaObject.getID(),
            'MediaName: '+mediaObject.getName(),
            'MediaType: '+mediaObject.getType(),
            'MediaClientID: '+clientObject.getID(),
        );
        return true;
    });

    // Start listen
    await rtspServer.listen();

})();

Publish

ffmpeg -re -i test.mp4  -c copy -f rtsp -rtsp_transport udp rtsp://127.0.0.1:5544/test

or


ffmpeg -re -i test.mp4  -c copy -f rtsp -rtsp_transport tcp rtsp://127.0.0.1:5544/test

Views

ffplay -rtsp_transport udp rtsp://127.0.0.1:5544/test

or

ffplay -rtsp_transport tcp rtsp://127.0.0.1:5544/test