Skip to content
versaticaPublic

About

RTP stack for Node and browser written in TypeScript

Topics

Resources

Stars

53 stars

Watchers

4 watching

Forks

Repository files navigation

rtp.js

RTP stack for Node.js and browser written in TypeScript. rtp.js provides with an API to parse, generate and modify RTP and RTCP packets.

Installation

npm install rtp.js

rtp.js is an ES module. In Node.js it requires version 22.12 or later, which also allows loading it with require() from CommonJS code. In the browser it works through any bundler (webpack, Rollup, esbuild, Vite, etc.) with no extra configuration.

Usage

  • API documentation

  • RTP packets and RTP extensions are exported by the packets/RTP module:

    import {
      isRtp,
      RtpPacket,
      ExtensionType,
      // [...]
    } from 'rtp.js/packets/RTP';
    
    if (isRtp(buffer)) {
      const rtpPacket = RtpPacket.parse(buffer);
    
      rtpPacket.setExtensionMapping({ [ExtensionType.MID]: 1 });
    
      const mid = rtpPacket.getMidExtension();
    }
  • RTCP packets are exported by the packets/RTCP module:

    import {
      isRtcp,
      ReceiverReportPacket,
      SenderReportPacket,
      SdesPacket,
      ByePacket,
      // [...]
    } from 'rtp.js/packets/RTCP';
    
    const byePacket = ByePacket.factory(new Uint8Array(1500));
    
    byePacket.addSsrc(1234);
    byePacket.setReason('bye bye');
  • Every packet lives within the Uint8Array given to parse() or factory() and every modification is applied in place within it, so packet.getBuffer() always returns the serialized packet.

  • In Node.js a Buffer can be given instead, since it's a Uint8Array.

Note about TypeScript

rtp.js exposes its entry points via the exports field of its package.json file, so TypeScript projects importing them must have moduleResolution set to "node16", "NodeNext" or "bundler". CommonJS projects also need TypeScript >= 5.8 and module set to "node20" or "NodeNext".

Author

License

ISC

About

RTP stack for Node and browser written in TypeScript

Topics

Resources

Stars

53 stars

Watchers

4 watching

Forks

Sponsor this project

Used by

Contributors

Languages