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

sdp-compact

v0.0.6

Published

Shorten WebRTC Session Description Protocol (SDP)

Downloads

394

Readme

SDP Compact

npm version

Shorten WebRTC Session Description Protocol (SDP) based on Unified Plan SDP

Why?

a WebRTC SDP can removing some of attributes can compress/compact and share config on both offer and answer sides.

Features

  • Shorten WebRTC SDP.
  • Options to fixed parameters for both offer and answer side.
  • Compress with zlib deflate.
  • Bytes based allow to choose any encoding.

Installation

npm install sdp-compact

Examples

import * as spdCompact from "sdp-compact";

const sessDesc: RTCSessionDescriptionInit = {
  type: "offer",
  sdp: `v=0\r\no=- 4109260023080860376 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS\r\n`,
};


const options: spdCompact.Options = { compress: true };

// compact the `RTCSessionDescriptionInit`
const compactedSessDesc = spdCompact.compact(sessDesc, options);
const decompactedSessDesc = spdCompact.decompact(compactedSPD, options);

// compact only the SDP string
const compactedSPD = spdCompact.compactSDP(sessDesc.sdp, options);
// for decompact need to specify if it's offer or answer because it's not include in SDP
const decompactedSPD = spdCompact.decompactSDP(compactedSPD, true, options);

// compact only the SDP string to bytes
const compactedSPDBytes = spdCompact.compactSDPBytes(sessDesc.sdp, options);
// decompact the compacted SDP bytes to decompacted string
const decompactedSPD = spdCompact.decompactSDPBytes(compactedSPDBytes, true, options);

Options

You can override the default options to suit your application's requirements, while still keeping the default values for any unspecified properties.

Default Options

const DefaultOptions: Options = {
  compress: true,
  replaceFieldNames: true,
  sdpVersion: 0,
  sessionName: "-",
  origin: {
    username: "-",
    sessionId: "4109260023080860376",
    netType: "IN",
    addrtype: "IP4",
    unicastAddress: "127.0.0.1",
  },
  timing: "0 0",
  extmapAllowMixed: true,
  msidSemantic: "WMS",
  mediaOptions: {
    removeMediaID: true,
    removeSetup: true,
    replaceCandidateString: true,
    replaceMediaString: true,
    forceTrickle: true,
    compressFingerprint: true,
  },
};

Here is an explanation of each option and its default value:

compress (default: true)

Enables compression using zlib deflate, followed by base64 encoding.

replaceFieldNames (default: true)

Replaces field names using FieldReplaceMap and FieldReplaceMapReverse.

sdpVersion (default: 0)

The fixed SDP version (v=), which is usually 0 for now.

sessionName (default: "-")

The fixed session name (s=), which is usually "-".

origin (default: see below)

Fixed origin options (o=). This includes the following properties:

  • username: Fixed username, can be "-" for an undefined user. (default: "-")
  • sessionId: Fixed session ID, can be the same value on all peers. (default: "4109260023080860376")
  • netType: Fixed network type, must be "IN" for the internet. (default: "IN")
  • addrtype: Fixed address type, must be either "IP4" or "IP6". Usually, it will be "IP4". (default: "IP4")
  • unicastAddress: Fixed unicast address, usually "127.0.0.1". (default: "127.0.0.1")

timing (default: "0 0")

The fixed timing (t=). It can be "0 0" for unbounded.

extmapAllowMixed (default: true)

Allows mixing attributes (a=extmap-allow-mixed), usually allowed by default.

msidSemantic (default: "WMS")

The fixed msid semantic (a=msid-semantic:). It should be "WMS" for WebRTC Media Stream.

mediaOptions (default: see below)

Customize media options. This includes the following properties:

  • removeMediaID: Remove media ID (a=mid:) and group (a=group:) (a=group:BUNDLE) to use sequence medias instead. (default: true)
  • removeSetup: Remove DTLS role (a=setup:). It will set to actpass for offer and active for answer. (default: true)
  • replaceCandidateString: replaced string in ice candidate (a=candidate:) following CandidateReplaceList. (default: true)
  • replaceMediaString: replace string in media (m=) following MediaReplaceList. (default: true)
  • forceTrickle: force ice-options to trickle (a=ice-options:trickle). (default: true)
  • compressFingerprint: compress fingerprint (a=fingerprint:). (default: true)
  • compressConnection: compress media connection (c=). (default: true)

WebRTC SDP Anatomy

You can read the WebRTC SDP Anatomy Here for how it's works.