1.0.9 • Published 5 months ago

@montevideo-tech/videojs-cmcd v1.0.9

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
5 months ago

Alt text

A video.js plugin for adding Common-Media-Client-Data (CMCD) to the player requests.

NOTE: This plugin only works for VideoJs 8.4.0 and above.

Content

Installation and Usage

Vanilla Javascript

This is the simplest case. Get the script in whichever way you prefer and include the plugin after you include video.js, so that the videojs global is available. Yoy can copy paste the next <script> tag

<script  src='https://cdn.jsdelivr.net/npm/@montevideo-tech/videojs-cmcd@latest/dist/videojs-cmcd.min.js'></script>

Then you will have to initalize the plugin after the creation of the player.

<script>


var player = videojs('my-video');

player.cmcd({sid:'SessionID', cid:'ContentID'});

</script>

NOTE: You can use the instance of the plugin to set the CID and SID parameters as it's shown above.

To include CMCD data in the request headers instead of query arguments, simply set the 'useHeaders' configuration value to 'true' when initializing the plugin. By default, CMCD data is transmitted via query arguments.

<script>


var player = videojs('my-video');

player.cmcd({sid:'SessionID', cid:'ContentID', useHeaders: true});

</script>

This is a complete example of the plugin.

<html>


<head>

<title>videojs-cmcd demo</title>

<link  href="https://cdn.jsdelivr.net/npm/video.js@8.5.0/dist/video-js.min.css"  rel="stylesheet">

</head>

  

<body>

<video  id="videojs-cmcd-player"  class="video-js vjs-default-skin"  controls></video>

  

<script  src="https://cdn.jsdelivr.net/npm/video.js@8.5.0/dist/video.min.js"></script>

<script  src="https://cdn.jsdelivr.net/npm/@montevideo-tech/videojs-cmcd@latest/dist/videojs-cmcd.min.js"></script>

<script>

// Init the palyer

var  player = videojs('videojs-cmcd-player');

  

// Init the CMCD Plugin

player.cmcd({sid:'SessionID', cid:'ContentID'});

// Load a video

player.src("https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8");

</script>

</body>

  
</html>

NPM

Install the plugin using npm in your project.

npm  i  @montevideo-tech/videojs-cmcd

Usage

To use the plug-in, instance the player and then initialize it.

import  videojs  from  'video.js';
import  '@montevideo-tech/videojs-cmcd'
  
var  player = videojs('videojs-cmcd-player');

player.cmcd({sid:'SessionID', cid:'ContentID'});

NOTE: You can use the instance of the plugin to set the CID and SID parameters as it's shown above.

You can also use the plugin function SetId() to set a Session ID or a Content ID dinamically.

player.cmcd().setId({sid: 'SessionID', cid: 'ContentID'});

NOTE: If you don't provide a SID and CID, the plugin will automatically generate them (A hash code for CID and a UUID for SID). You can retrieve any of them by instancing "player.cmcd().sid" or "player.cmcd().cid" respectively.

CMCD Standard implementation status

This table provides information about the CMCD keys, how they are obtained, the difficulty of doing so and if they are implemented or even required.

DescriptionKey NameHeader NameType and UnitHow to obtain it's valueComments and calculationEasy / DiffImplemented
Encoded bitratebrCMCD-ObjectInteger kbpsin vhs, playlists.media, attributes.BANDWIDTH propertyChange the unit of BANDWIDTH from bps to kbps (/1000)DiffYes
Buffer lengthblCMCD-RequestInteger millisecondsin tech() buffered().length, buffered().end(index) and currentTime() propertiesUse the last saved segment index as a parameter that receives the end() method, and with the result, subtract it from the current time position of the playerDiffYes
Buffer starvationbsCMCD-StatusBoolean'loadedmetadata' and 'waiting' eventsNot taken into account when not initializedDiffYes
Content IDcidCMCD-SessionStringIf not specified it will be a hash of the MPD/M3U8 URLThis idea is implemented on dash.js pluginDiffYes
Object durationdCMCD-ObjectInteger millisecondsin vhs playlists.media, segmentsindex.duration propertyUse the segment index. * 1000 to convert to millisecondsDiffYes
DeadlinedlCMCD-RequestInteger milliseconds"player.playbackRate()" method(bufferLength / playbackRate) * 1000, bufferLength as obtained in bl keyDiffYes
Measured throughputmtpCMCD-RequestInteger kilobits per second (kbps)in tech, vhs.systemBandwidth propertychange the unit of systemBandwidth from bps to kbps (/1000)EasyYes
Next object requestnorCMCD-RequestStringin vhs, playlists.media, segments propertyFor VOD: Use the property to find the segment that is being requested and keep the next one. The relative path is in segmentsi.uri Note: does not work in Live streamsDiffYes (no Live Streams)
Next range requestnrrCMCD-RequestString of the form "\-<range-end>"UnknownIt will not be implementedDiffNo
Object typeotCMCD-ObjectToken - one of m, a,v,av,i,c,tt,k,oUse the request uri file extension (.m3u8, .ts, etc.)This implementation is temporary for the first Version of the PlugInDiffYes
Playback rateprCMCD-SessionDecimal"player.playbackRate()" methodEasyYes
Requested maximum throughputrtpCMCD-StatusInteger kilobits per second (kbps)UnknownIt will not be implemented for the first releaseDiffNo
Streaming formatsfCMCD-SessionToken - one of d,h,s,o"player.currentType()" methodVideoJS does not support smooth streamingEasyYes
Session IDsidCMCD-SessionStringA function that create an universally unique identifiers (UUID)We use crypto.randomUUID(), have to check what other implementations doEasyYes
Stream typestCMCD-SessionToken - one of v,lif "player.duration()" is infinite then it's live, otherwise it's VODEasyYes
StartupsuCMCD-RequestBoolean'loadedmetadata' and 'waiting' eventsDebt: find a method to identify "recovery after a buffer-empty event"DiffYes
Top bitratetbCMCD-ObjectInteger KbpsExtract highest bandwidth possible in the manifestHave to investigate what other implementations doDiffYes
CMCD versionvCMCD-SessionIntegerCurrently there is only one version available which is version 1Ommited according to CTA-5004 specsEasyYes

Contributing

We welcome contributions from the community. To contribute to the project, follow these steps:

  1. Fork the repository.

  2. Check the active issues and project board to see what we're working on.

  3. Create a new branch for your feature or bug fix.

  4. Make your changes.

  5. Submit a pull request.

Setup your development environment

  1. Install all the packages dependencies: npm install

  2. Build the plugin and keep watching for changes in the source code: npm run start

  3. Open in a browser the index.html to test your changes in the code. Remember to refresh the page each time you make a change in the source code.

  4. The index.html page has the cmcd-validator installed, open the console of your browser to find errors in the CMCD implementation.

License

Apache-2.0. Copyright (c)

1.0.9

5 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

11 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago