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.
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.
-
RTP packets and RTP extensions are exported by the
packets/RTPmodule: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/RTCPmodule: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
Uint8Arraygiven toparse()orfactory()and every modification is applied in place within it, sopacket.getBuffer()always returns the serialized packet. -
In Node.js a
Buffercan be given instead, since it's aUint8Array.
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".