Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@svta/common-media-library

A common library for media playback in JavaScript

CTA-5004, Common Media Client Data, CMCD, CTA-5006, Common Media Server Data, CMSD, RFC8941, Structured Field Values, ID3, Common Media Request, Common Media Response, CTA-608, CEA-608, EIA-608

readme

common-media-library

A common library for media playback in JavaScript

Looking at open source players like hls.js, dash.js, and shaka-player there are common pieces of functionality that have been implemented independently across the libraries. This is particularly true when looking at standards based features, like ID3 parsing, 608 parsing and CMCD. Since the functionality is shared in spirit but not implementation, they can fall out of sync where certain bugs are fixed in one player but not the others. The goal of this library is to create a single place where these utilities can be maintained and distributed.

Project structure

This project is a mono-repo with the following workspaces: lib, docs. The lib package contains the compiled code for the library which is published to npm. The docs package contains the documentation for the library and is published to GitHub pages.

Installation

npm install @svta/common-media-library

Usage

Too ensure the smallest bundle sizes possible, it is best practice to import all members and type definitions individually from the library.

import { appendCmcdQuery } from '@svta/common-media-library/cmcd/appendCmcdQuery';
import { CmcdObjectType } from '@svta/common-media-library/cmcd/CmcdObjectType';

const cmcd = {
    sid: '4f2867f2-b0fd-4db7-a3e0-cea7dff44cfb',
    cid: 'cc002fc3-d9e1-418d-9a5f-3d0eac601882',
    d: 324.69,
    ot: CmcdObjectType.MANIFEST,
    ['com.example-hello']: 'world',
};

const cmcdUrl = appendCmcdQuery('https://example.com/playlist.m3u8', cmcd);
console.log(cmcdUrl);
// https://example.com/playlist.m3u8?CMCD=cid%3D%22cc002fc3-d9e1-418d-9a5f-3d0eac601882%22%2Ccom.example-hello%3D%22world%22%2Cd%3D325%2Cot%3Dm%2Csid%3D%224f2867f2-b0fd-4db7-a3e0-cea7dff44cfb%22

If bundle size isn't a concern, all members and type definitions can also be imported from the root of the library, or from the feature namespace.

import { appendCmcdQuery, CmcdObjectType } from '@svta/common-media-library';
import { appendCmcdQuery, CmcdObjectType } from '@svta/common-media-library/cmcd';

Documentation

API docs can be found here.

Thanks

This project builds upon the work of the open source community. Special thanks to the maintainers of hls.js, dash.js, shaka-player, and structured-field-values as well as organizations like the Streaming Video Technology Alliance, DASH Industry Forum, and the CTA WAVE Project.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

0.11.0 - 2025-04-03

Added

  • Common DRM Models and Constants (#154)
  • Core DRM Utilities - CommonEncryption, KeySystemUtils (#156)

Changed

  • CommonMediaRequest / CommonMediaResponse Updates (#163)

Fixed

  • The format command no longer works (#166)

0.10.0 - 2025-03-10

Added

  • FairPlay Utilities (#131)
  • Add prefix and localName support to the XML types and utilities (#145)
  • Common DRM Models and Constants (#154)

0.9.0 - 2025-02-21

Added

  • ISO BMFF parser and utilities (#118)

0.8.0 - 2025-02-14

Added

  • Add DASH Segment Template Utility (#129)
  • Add XML parsing utils (#125)

Changed

  • Updated NOTICE file to use Markdown formatting to preserve the text of included licenses.
  • Export ISO 8601 duration utilities.

Fix

  • Corrected Changelog formatting.

0.7.4 - 2024-11-05

Changed

  • Replace Typescript enums with constants (#103)
  • Remove CMAF HAM dependencies (#119)

0.7.3 - 2024-08-30

Fix

  • Cannot import library in jest tests (#98)
  • Replace ts-node (#101)

0.7.2 - 2024-08-28

Fix

  • Cannot import library in jest tests (#98)

0.7.1 - 2024-06-21

Fix

  • Missing dependencies in package.json (#96)

0.7.0 - 2024-06-05

Added

  • Add CMAF-Ham types, mappers and services to convert and manipulate VOD HLS and VOD DASH manifests.
  • Add cmaf-ham-converter sample to showcase the CMAF-Ham functions.
  • Implement CEA 608/708 parser (#62)

Fix

  • Integrate outstanding 608 PR (#88)

0.6.4 - 2024-03-04

Fixed

  • Resolve module import error on id3 feature (#83)

0.6.3 - 2024-03-01

Added

  • Unit tests for ID3 feature helper functions (#74)
  • ID3 APIC frame decode functionality, and it's respective unit tests (#77)

0.6.2 - 2023-01-18

Fixed

  • Some imports are pulling in unnecessary files (#64)

0.6.1 - 2023-12-14

Fixed

  • Incorrect return type for decodeCmsdDynamic function (#55)

0.6.0 - 2023-11-29

Added

  • Add the ability to pass a base URL to all CMCD encode utilities to construct relative paths for nor (#50)
  • Export constants for CMCD and CMSD version numbers (#44)

Fixed

  • CMCD does not protect against non-Finite numeric values (#45)
  • appendCmcdQuery does not account for existing CMCD query params (#48)

0.5.1 - 2023-11-16

Changed

  • Remove BigInt notation

0.5.0 - 2023-11-14

Added

  • Implement Common Media Server Data (CMSD) utilities (#35)
  • Add request and response interceptors API

0.4.5 - 2023-10-12

Fixed

  • CMCD_PARAM constant does not match file name (#27)
  • lint errors when using typedoc specific tags (#32)
  • Allow imports with file extensions (#26)

0.4.4 - 2023-10-11

Fixed

  • Module not found: Error: Default condition should be last one (#22)

0.4.3 - 2023-07-25

Added

  • Add NOTICE file for attributions
  • Export library in cjs format (#11)

Changed

  • Switch to inline source maps

0.4.2 - 2023-05-25

Changed

  • The project has moved to a new NPM org. First release under @svta/common-media-library.

0.4.1 - 2023-05-25

Changed

  • The project has moved to a new NPM org. Last release under `@svta.org/common-media-library`.

0.4.0 - 2023-05-05

Added

  • Add ID3 APIs (#16)

0.3.0 - 2023-05-04

Added

  • Add new decode APIs fromCmcdHeaders and fromCmcdQuery

0.2.6 - 2023-05-03

Fixed

  • Fix issue where decodeCmcd produces incorrect results for token values

0.2.5 - 2023-05-03

Fixed

  • Fix issue where decodeCmcd produces incorrect results for empty strings

0.2.4 - 2023-05-03

Changed

  • Update npm dependencies
  • Improve uuid randomness
  • Streamline build processes
  • Update README

0.2.3 - 2023-05-03

Added

  • Export CmcdParam

0.2.2 - 2023-05-02

Fixed

  • Argument order mismatch in appendCmcdQuery

0.2.1 - 2023-05-02

Added

  • Additional formatting of CMCD integer values

0.2.0 - 2023-04-28

Added

  • Add namespaced exports

Changed

  • Update CMCD APIs

0.1.2 - 2023-04-28

Fixed

  • Republish of NPM package

0.1.1 - 2023-04-27

Added

  • Add CMCD encode and decode APIs (#1)

0.1.0 - 2023-04-27

Added

  • Bootstrap project (#2)