-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Update CMCD APIs * feat: Add namespaced exports * chore: add aliases to readme and license files
- Loading branch information
1 parent
31da28e
commit 8d7aa4d
Showing
28 changed files
with
135 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib/LICENSE.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), '{}'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
6 changes: 3 additions & 3 deletions
6
lib/src/cmcd/appendToUrl.ts → lib/src/cmcd/appendCmcdQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './utils/uuid.js'; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.