Socket
Book a DemoInstallSign in
Socket

cmcd.js

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

cmcd.js

CMCD (Common Media Client Data) library with Typescript definitions

unpublished
latest
npmnpm
Version
0.6.2
Version published
Maintainers
1
Created
Source

cmcd.js

CMCD (Common Media Client Data) library with Typescript definitions.

Install

npm i cmcd.js

Usage

All CMCD properties are optional. Properties that with nullish values will not be serialized.

import {
  Cmcd,
  CmcdHeader,
  CmcdObjectType,
  CmcdStreamingFormat,
  CmcdStreamType,
  toHeaders,
  toJson,
  toQuery
} from 'cmcd.js';

const data: Cmcd = {
  cid: '9f7f349b-baba-43d7-bbe7-b0dc8a65af0d',
  sf: CmcdStreamingFormat.DASH,
  st: CmcdStreamType.VOD,
  su: false,
  mtp: 10000,
  bs: true,
  br: 200,
  ot: CmcdObjectType.MANIFEST,
};

const query = toQuery(data);
console.log(query);
/* 
'CMCD=br%3D200%2Cbs%2Ccid%3D%229f7f349b-baba-43d7-bbe7-b0dc8a65af0d%22%2Cmtp%3D10000%2Cot%3Dm%2Csf%3Dd%2Cst%3Dv'
*/

const headers = toHeaders(data);
console.log(headers);
/*
{
  'CMCD-Object': 'br=200,ot=m',
  'CMCD-Request': 'mtp=10000',
  'CMCD-Session': 'cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",sf=d,st=v',
  'CMCD-Status': 'bs'
}
*/

const json = toJson(data);
console.log(json);
/*
'{"br":200,"bs":true,"cid":"9f7f349b-baba-43d7-bbe7-b0dc8a65af0d","mtp":10000,"ot":"m","sf":"d","st":"v"}'
*/

/**
 * Custom Fields 
 */

data['com.example-a'] = 'hello';
data['com.example-b'] = 1234;
data['com.example-c'] = true;
data['com.example-d'] = Symbol('s');

console.log(toQuery(data));
/*
'CMCD=br%3D200%2Cbs%2Ccid%3D%229f7f349b-baba-43d7-bbe7-b0dc8a65af0d%22%2Ccom.example-a%3D%22hello%22%2Ccom.example-b%3D1234%2Ccom.example-c%2Ccom.example-d%3Ds%2Cmtp%3D10000%2Cot%3Dm%2Csf%3Dd%2Cst%3Dv'
*/

/**
 * Custom fields can be mapped to specific headers by providing a mapping 
 * object to the `toHeader` function. Unmapped custom fields are added to 
 * the CMCD-Request header.
 */
const headerMap = {
  ['com.example-a']: CmcdHeader.Object,
  ['com.example-b']: CmcdHeader.Session,
  ['com.example-c']: CmcdHeader.Status,
};

console.log(toHeaders(data, headerMap));
/*
{
  'CMCD-Object': 'br=200,com.example-a="hello",ot=m',
  'CMCD-Request': 'com.example-d=s,mtp=10000',
  'CMCD-Session': 'cid="9f7f349b-baba-43d7-bbe7-b0dc8a65af0d",com.example-b=1234,sf=d,st=v',
  'CMCD-Status': 'bs,com.example-c'
}
*/

API Docs

https://littlespex.github.io/cmcd.js/

References

Keywords

cmcd

FAQs

Package last updated on 08 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts