Skip to content

Commit

Permalink
release/0.2.0 (#15)
Browse files Browse the repository at this point in the history
* feat: Update CMCD APIs
* feat: Add namespaced exports
* chore: add aliases to readme and license files
  • Loading branch information
littlespex authored Apr 28, 2023
1 parent 31da28e commit 8d7aa4d
Show file tree
Hide file tree
Showing 28 changed files with 135 additions and 116 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]


## [0.2.0] - 2023-04-28

### Changed
- Update CMCD APIs

### Added
- Add namespaced exports


## [0.1.2] - 2023-04-28

### Fixed
Expand All @@ -37,7 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bootstrap project [#2](https://github.com/streaming-video-technology-alliance/common-media-library/issues/2)


[Unreleased]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.2...HEAD
[Unreleased]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.2.0...HEAD
[0.2.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.2...v0.2.0
[0.1.2]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.1...v0.1.2
[0.1.1]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.1.0...v0.1.1
[0.1.0]\: https://github.com/streaming-video-technology-alliance/common-media-library/compare/v0.0.0...v0.1.0
21 changes: 0 additions & 21 deletions LICENSE.md

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE.md
5 changes: 0 additions & 5 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions README.md
2 changes: 1 addition & 1 deletion dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@svta.org/common-media-library-dev",
"version": "0.1.2",
"version": "0.2.0",
"license": "MIT",
"type": "module",
"homepage": "https://github.com/streaming-video-technology-alliance/common-media-library",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { appendToHeaders } from '@svta.org/common-media-library/cmcd/appendToHeaders';
import { appendCmcdHeaders } from '@svta.org/common-media-library';
import { deepEqual } from 'node:assert';
import { describe, it } from 'node:test';

Expand All @@ -12,11 +12,11 @@ describe('CMCD appendToHeaders', () => {
};

it('handles null data object', () => {
deepEqual(appendToHeaders(headers, null as any), headers);
deepEqual(appendCmcdHeaders(headers, null as any), headers);
});

it('appends headers', () => {
deepEqual(appendToHeaders(headers, data), {
deepEqual(appendCmcdHeaders(headers, data), {
...headers,
['CMCD-Object']: 'br=1000',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { appendToUrl } from '@svta.org/common-media-library/cmcd/appendToUrl';
import { appendCmcdQuery } from '@svta.org/common-media-library';
import { equal } from 'node:assert';
import { describe, it } from 'node:test';

Expand All @@ -9,14 +9,14 @@ describe('CMCD appendToUrl', () => {
};

it('handles null data object', () => {
equal(appendToUrl(null as any, url), url);
equal(appendCmcdQuery(null as any, url), url);
});

it('add ? when query does not exist', () => {
equal(appendToUrl(data, url), `${url}?CMCD=br%3D1000`);
equal(appendCmcdQuery(data, url), `${url}?CMCD=br%3D1000`);
});

it('add & when query does exist', () => {
equal(appendToUrl(data, `${url}?hello=world`), `${url}?hello=world&CMCD=br%3D1000`);
equal(appendCmcdQuery(data, `${url}?hello=world`), `${url}?hello=world&CMCD=br%3D1000`);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CmcdHeaderField } from '@svta.org/common-media-library/cmcd/CmcdHeaderField';
import { toHeaders } from '@svta.org/common-media-library/cmcd/toHeaders';
import { CmcdHeaderField, toCmcdHeaders } from '@svta.org/common-media-library';
import { deepEqual } from 'node:assert';
import { describe, it } from 'node:test';
import { data } from './data.js';
Expand All @@ -13,7 +12,7 @@ const customHeaderMap = {

describe('CMCD Header serialization', () => {
it('produces all shards', () => {
deepEqual(toHeaders(data, { customHeaderMap }), {
deepEqual(toCmcdHeaders(data, { customHeaderMap }), {
'CMCD-Object': 'br=200,com.example-hello="world",d=325,ot=m',
'CMCD-Request': 'com.example-quote="\\"Quote\\"",com.example-token=s,mtp=10049,nor="..%2Ftesting%2F3.m4v",nrr="0-99"',
'CMCD-Session': 'cid="content-id",com.example-testing=1234,sid="session-id"',
Expand All @@ -22,12 +21,12 @@ describe('CMCD Header serialization', () => {
});

it('ignores empty shards', () => {
deepEqual(toHeaders({ br: 200 }), {
deepEqual(toCmcdHeaders({ br: 200 }), {
'CMCD-Object': 'br=200',
});
});

it('handles null data object', () => {
deepEqual(toHeaders(null as any), {});
deepEqual(toCmcdHeaders(null as any), {});
});
});
14 changes: 14 additions & 0 deletions dev/src/cmcd/toCmcdJson.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { toCmcdJson } from '@svta.org/common-media-library';
import { equal } from 'node:assert';
import { describe, it } from 'node:test';
import { data } from './data.js';

describe('CMCD JSON serialization', () => {
it('produces json', () => {
equal(toCmcdJson(data), '{"br":200,"bs":true,"cid":"content-id","com.example-exists":true,"com.example-hello":"world","com.example-quote":"\\"Quote\\"","com.example-testing":1234,"com.example-token":"s","d":325,"mtp":10049,"nor":"..%2Ftesting%2F3.m4v","nrr":"0-99","ot":"m","sid":"session-id"}');
});

it('handles empty data', () => {
equal(toCmcdJson(null as any), '{}');
});
});
14 changes: 14 additions & 0 deletions dev/src/cmcd/toCmcdQuery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { toCmcdQuery } from '@svta.org/common-media-library';
import { equal } from 'node:assert';
import { describe, it } from 'node:test';
import { data } from './data.js';

describe('CMCD Query serialization', () => {
it('handles null data object', () => {
equal(toCmcdQuery(null as any), '');
});

it('returns encoded query string', () => {
equal(toCmcdQuery(data), 'CMCD=br%3D200%2Cbs%2Ccid%3D%22content-id%22%2Ccom.example-exists%2Ccom.example-hello%3D%22world%22%2Ccom.example-quote%3D%22%5C%22Quote%5C%22%22%2Ccom.example-testing%3D1234%2Ccom.example-token%3Ds%2Cd%3D325%2Cmtp%3D10049%2Cnor%3D%22..%252Ftesting%252F3.m4v%22%2Cnrr%3D%220-99%22%2Cot%3Dm%2Csid%3D%22session-id%22');
});
});
14 changes: 0 additions & 14 deletions dev/src/cmcd/toJson.test.ts

This file was deleted.

14 changes: 0 additions & 14 deletions dev/src/cmcd/toQuery.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@svta.org/common-media-library-docs",
"version": "0.1.2",
"version": "0.2.0",
"license": "MIT",
"type": "module",
"homepage": "https://github.com/streaming-video-technology-alliance/common-media-library",
Expand Down
28 changes: 27 additions & 1 deletion lib/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# common-media-library
A common library for media playback in JavaScript.
A common library for media playback in JavaScript

Looking at open source players like [hls.js](https://github.com/video-dev/hls.js/), [dash.js](https://github.com/Dash-Industry-Forum/dash.js/) and [shaka-player](https://github.com/shaka-project/shaka-player) there are common pieces of functionality that have been implemented independently, and sometimes copy and pasted, 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 three workspaces: `dev`, `lib` and `docs`. The lib package contains the compiled code for the library which is published to npm. The dev package contains code to develop and test the lib package and is not published to npm. The docs package contains the documentation for the library and is published to GitHub pages.

## Installation
```bash
npm install @scta/common-media-library
```

## Usage
```typescript
import { appendCmcdQuery, CmcdObjectType } from '@svta.org/common-media-library';

const url = 'https://example.com/playlist.m3u8';
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(cmcd, url);
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
```
6 changes: 5 additions & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@svta.org/common-media-library",
"version": "0.1.2",
"version": "0.2.0",
"license": "MIT",
"type": "module",
"homepage": "https://github.com/streaming-video-technology-alliance/common-media-library",
Expand All @@ -22,6 +22,10 @@
"dist/**/*"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./*": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
Expand Down
19 changes: 19 additions & 0 deletions lib/src/cmcd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type { Cmcd } from './cmcd/Cmcd.js';
export type { CmcdCustomKey } from './cmcd/CmcdCustomKey.js';
export type { CmcdEncodeOptions } from './cmcd/CmcdEncodeOptions.js';
export { CmcdEncoding } from './cmcd/CmcdEncoding.js';
export type { CmcdFormatter } from './cmcd/CmcdFormatter.js';
export { CmcdHeaderField } from './cmcd/CmcdHeaderField.js';
export type { CmcdKey } from './cmcd/CmcdKey.js';
export { CmcdObjectType } from './cmcd/CmcdObjectType.js';
export { CmcdStreamType } from './cmcd/CmcdStreamType.js';
export { CmcdStreamingFormat } from './cmcd/CmcdStreamingFormat.js';
export type { CmcdValue } from './cmcd/CmcdValue.js';
export { appendCmcdHeaders } from './cmcd/appendCmcdHeaders.js';
export { appendCmcdQuery } from './cmcd/appendCmcdQuery.js';
export { decodeCmcd } from './cmcd/decodeCmcd.js';
export { encodeCmcd } from './cmcd/encodeCmcd.js';
export { toCmcdHeaders } from './cmcd/toCmcdHeaders.js';
export { toCmcdJson } from './cmcd/toCmcdJson.js';
export { toCmcdQuery } from './cmcd/toCmcdQuery.js';

11 changes: 11 additions & 0 deletions lib/src/cmcd/appendCmcdHeaders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Cmcd } from './Cmcd.js';
import { CmcdCustomKey } from './CmcdCustomKey.js';
import { CmcdHeaderField } from './CmcdHeaderField.js';
import { toCmcdHeaders } from './toCmcdHeaders.js';

/**
* Append CMCD query args to a header object.
*/
export function appendCmcdHeaders(headers: Record<string, string>, cmcd: Cmcd, customHeaderMap?: Record<CmcdCustomKey, CmcdHeaderField>) {
return Object.assign(headers, toCmcdHeaders(cmcd, customHeaderMap));
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Cmcd } from './Cmcd.js';
import { toQuery } from './toQuery.js';
import { toCmcdQuery } from './toCmcdQuery.js';

/**
* Append CMCD query args to a URL.
*/
export function appendToUrl(cmcd: Cmcd, url: string) {
const query = toQuery(cmcd);
export function appendCmcdQuery(cmcd: Cmcd, url: string) {
const query = toCmcdQuery(cmcd);
if (!query) {
return url;
}
Expand Down
11 changes: 0 additions & 11 deletions lib/src/cmcd/appendToHeaders.ts

This file was deleted.

18 changes: 0 additions & 18 deletions lib/src/cmcd/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const toHeaderCase = (value: string) => `${value[0].toUpperCase()}${value.slice(
/**
* Convert a CMCD data object to request headers
*/
export function toHeaders(cmcd: Cmcd, options: CmcdEncodeOptions = {}) {
export function toCmcdHeaders(cmcd: Cmcd, options: CmcdEncodeOptions = {}) {
const results: Record<string, string> = {};

if (!cmcd) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cmcd/toJson.ts → lib/src/cmcd/toCmcdJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { processCmcd } from './processCmcd.js';
/**
* Convert a CMCD data object to JSON
*/
export function toJson(cmcd: Partial<Cmcd>, options?: CmcdEncodeOptions) {
export function toCmcdJson(cmcd: Partial<Cmcd>, options?: CmcdEncodeOptions) {
const toValue = (value: CmcdValue) => typeof value == 'symbol' ? value.description : value;
const data = processCmcd(cmcd, (key, value) => [key, toValue(value)], options);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/cmcd/toQuery.ts → lib/src/cmcd/toCmcdQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { encodeCmcd } from './encodeCmcd.js';
/**
* Convert a CMCD data object to query args
*/
export function toQuery(cmcd: Cmcd, options: CmcdEncodeOptions = {}) {
export function toCmcdQuery(cmcd: Cmcd, options: CmcdEncodeOptions = {}) {
if (!cmcd) {
return '';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './cmcd/index.js';
export * from './utils/index.js';
export * from './cmcd.js';
export * from './utils.js';

1 change: 1 addition & 0 deletions lib/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './utils/uuid.js';
1 change: 0 additions & 1 deletion lib/src/utils/index.ts

This file was deleted.

Loading

0 comments on commit 8d7aa4d

Please sign in to comment.