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

@novadynamics/rtp

v0.4.3

Published

Real-time transport protocol

Downloads

78

Readme

Node-RTP

Real-time Transport Protocol (RTP) is an Internet standards track protocol for real-time data such as audio or video. For more information on RTP see IETF RFC 3550.

This library provides a wrapper for librtp

Usage

This package supports both RTP and RTCP packets. RTP packets deliver data and are typically sent on an even numbered UDP port. RTCP packets carry statistical and control data and are typically sent on the next higher odd-numbered port.

Packet objects have a common serialize() method to convert the packet into a NodeJS Buffer. A Buffer can be converted back to it's corresponding packet object by passing it into the packet constructor. A convience method parse() is provided which will attempt to convert an unknown Buffer into its corresponding packet object based on type.

An example of Buffer parsing:

const { RtpPacket, parse } = require("rtp");

// Create a Buffer containing a serialized RTP packet
const pkt1 = new RtpPacket(96);
pkt1.payload = Buffer.from([1, 2, 3]);
const buffer = pkt1.serialize(); // <Buffer ... >

// Parse the Buffer
const pkt2 = parse(buffer);
console.log(pkt2 instanceof RtpPacket); // true
console.log(pkt2.payload); // <Buffer 01 02 03>

What follows are initialization examples for each packet type.

RtpPacket: RTP Data Packet

const { RtpPacket } = require("rtp");

// Create the payload
const rate_hz = 48000;
const duration_ms = 20;
const channels = 1;

const frame_samples = (rate_hz * duration_ms) / 1000;
const frame_size = (channels * frame_samples * 2) // int16_t
const frame_buffer = Buffer.alloc(frame_size);

// ... fill the frame buffer

// Create the packet
const pkt = new RtpPacket(96);

// Add the payload
pkt.seq += 1;
pkt.ts += samples;
pkt.payload = frame_buffer;

// Serialize
const data = pkt.serialize(); // <Buffer ... >

// ... send the buffer

AppPacket: Application-Defined RTCP Packet

const { AppPacket } = require("rtp");

// Creating a new AppPacket
const pkt = new AppPacket();
pkt.ssrc = 0;
pkt.subtype = 1;
pkt.name = 0x646178; // dax
pkt.data = Buffer.alloc(10);

// Serialize
const data = pkt.serialize(); // <Buffer ... >

// ... send the buffer

ByePacket: Goodbye RTCP Packet

const { ByePacket } = require("rtp");

// Creating a new ByePacket
const pkt = new ByePacket();

// Add sources
pkt.addSource(0);
pkt.addSource(1);

// Set "reason" message
pkt.message = "Disconnect";

// Serialize
const data = pkt.serialize(); // <Buffer ... >

// ... send the buffer

RrPacket: Receiver Report RTCP Packet

const { RrPacket } = require("rtp");

// Creating a new RrPacket
const pkt = new RrPacket();

// Add reports
pkt.addReport({
    ssrc: 1,            // Source identifier
    fraction: 0,        // Percentage of packets lost
    lost: 0,            // Cumulative number of packets lost
    last_seq: 1024,     // Highest sequence number received
    jitter: 0,          // Interarrival jitter
    lsr: 0,             // Last SR timestamp
    dlsr: 0,            // Delay since last SR
});

// Add optional extension data
pkt.ext = Buffer.alloc(12);

// Serialize
const data = pkt.serialize(); // <Buffer ... >

// ... send the buffer

SdesPacket: Source Description RTCP Packet

const { SdesPacket } = require("rtp");

// Creating a new SdesPacket
const pkt = new SdesPacket();

// Add sources
pkt.addSource({
    ssrc: 1,
    cname: "33994c30-773c-4bc7-8514-a2e8f398940b",
    name: "John Doe",
    email: "[email protected]"
    phone: "+1 000 555 0100"
    loc: "Portland, Oregon",
    tool: "node-rtp",
    note: "optional note",
    priv: "private extension",
});

// Serialize
const data = pkt.serialize(); // <Buffer ... >

// ... send the buffer

SrPacket: Sender Report RTCP Packet

const { SrPacket } = require("rtp");

// Creating a new SrPacket
const pkt = new SrPacket();
pkt.ssrc = 1;
pkt.ntp_ts = new Date();
pkt.rtp_ts = 0;

// Add reports
pkt.addReport({
    ssrc: 1,            // Source identifier
    fraction: 0,        // Percentage of packets lost
    lost: 0,            // Cumulative number of packets lost
    last_seq: 1024,     // Highest sequence number received
    jitter: 0,          // Interarrival jitter
    lsr: 0,             // Last SR timestamp
    dlsr: 0,            // Delay since last SR
});

// Add optional extension data
pkt.ext = Buffer.alloc(12);

// Serialize
const data = pkt.serialize(); // <Buffer ... >

// ... send the buffer