dashjs
Version:
A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers.
1,561 lines (1,496 loc) • 809 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["dashjs"] = factory();
else
root["dashjs"] = factory();
})(self, function() {
return /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/fast-deep-equal/index.js":
/*!***********************************************!*\
!*** ./node_modules/fast-deep-equal/index.js ***!
\***********************************************/
/***/ (function(module) {
// do not edit .js files directly - edit src/index.jst
module.exports = function equal(a, b) {
if (a === b) return true;
if (a && b && typeof a == 'object' && typeof b == 'object') {
if (a.constructor !== b.constructor) return false;
var length, i, keys;
if (Array.isArray(a)) {
length = a.length;
if (length != b.length) return false;
for (i = length; i-- !== 0;) if (!equal(a[i], b[i])) return false;
return true;
}
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
keys = Object.keys(a);
length = keys.length;
if (length !== Object.keys(b).length) return false;
for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
for (i = length; i-- !== 0;) {
var key = keys[i];
if (!equal(a[key], b[key])) return false;
}
return true;
}
// true if both NaN, false otherwise
return a !== a && b !== b;
};
/***/ }),
/***/ "./node_modules/path-browserify/index.js":
/*!***********************************************!*\
!*** ./node_modules/path-browserify/index.js ***!
\***********************************************/
/***/ (function(module) {
// 'path' module extracted from Node.js v8.11.1 (only the posix part)
// transplited with Babel
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function assertPath(path) {
if (typeof path !== 'string') {
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
}
}
// Resolves . and .. elements in a path with directory names
function normalizeStringPosix(path, allowAboveRoot) {
var res = '';
var lastSegmentLength = 0;
var lastSlash = -1;
var dots = 0;
var code;
for (var i = 0; i <= path.length; ++i) {
if (i < path.length) code = path.charCodeAt(i);else if (code === 47 /*/*/) break;else code = 47 /*/*/;
if (code === 47 /*/*/) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
if (res.length > 2) {
var lastSlashIndex = res.lastIndexOf('/');
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
}
lastSlash = i;
dots = 0;
continue;
}
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSegmentLength = 0;
lastSlash = i;
dots = 0;
continue;
}
}
if (allowAboveRoot) {
if (res.length > 0) res += '/..';else res = '..';
lastSegmentLength = 2;
}
} else {
if (res.length > 0) res += '/' + path.slice(lastSlash + 1, i);else res = path.slice(lastSlash + 1, i);
lastSegmentLength = i - lastSlash - 1;
}
lastSlash = i;
dots = 0;
} else if (code === 46 /*.*/ && dots !== -1) {
++dots;
} else {
dots = -1;
}
}
return res;
}
function _format(sep, pathObject) {
var dir = pathObject.dir || pathObject.root;
var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
if (!dir) {
return base;
}
if (dir === pathObject.root) {
return dir + base;
}
return dir + sep + base;
}
var posix = {
// path.resolve([from ...], to)
resolve: function resolve() {
var resolvedPath = '';
var resolvedAbsolute = false;
var cwd;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path;
if (i >= 0) path = arguments[i];else {
if (cwd === undefined) cwd = process.cwd();
path = cwd;
}
assertPath(path);
// Skip empty entries
if (path.length === 0) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
if (resolvedAbsolute) {
if (resolvedPath.length > 0) return '/' + resolvedPath;else return '/';
} else if (resolvedPath.length > 0) {
return resolvedPath;
} else {
return '.';
}
},
normalize: function normalize(path) {
assertPath(path);
if (path.length === 0) return '.';
var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
// Normalize the path
path = normalizeStringPosix(path, !isAbsolute);
if (path.length === 0 && !isAbsolute) path = '.';
if (path.length > 0 && trailingSeparator) path += '/';
if (isAbsolute) return '/' + path;
return path;
},
isAbsolute: function isAbsolute(path) {
assertPath(path);
return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
},
join: function join() {
if (arguments.length === 0) return '.';
var joined;
for (var i = 0; i < arguments.length; ++i) {
var arg = arguments[i];
assertPath(arg);
if (arg.length > 0) {
if (joined === undefined) joined = arg;else joined += '/' + arg;
}
}
if (joined === undefined) return '.';
return posix.normalize(joined);
},
relative: function relative(from, to) {
assertPath(from);
assertPath(to);
if (from === to) return '';
from = posix.resolve(from);
to = posix.resolve(to);
if (from === to) return '';
// Trim any leading backslashes
var fromStart = 1;
for (; fromStart < from.length; ++fromStart) {
if (from.charCodeAt(fromStart) !== 47 /*/*/) break;
}
var fromEnd = from.length;
var fromLen = fromEnd - fromStart;
// Trim any leading backslashes
var toStart = 1;
for (; toStart < to.length; ++toStart) {
if (to.charCodeAt(toStart) !== 47 /*/*/) break;
}
var toEnd = to.length;
var toLen = toEnd - toStart;
// Compare paths to find the longest common path from root
var length = fromLen < toLen ? fromLen : toLen;
var lastCommonSep = -1;
var i = 0;
for (; i <= length; ++i) {
if (i === length) {
if (toLen > length) {
if (to.charCodeAt(toStart + i) === 47 /*/*/) {
// We get here if `from` is the exact base path for `to`.
// For example: from='/foo/bar'; to='/foo/bar/baz'
return to.slice(toStart + i + 1);
} else if (i === 0) {
// We get here if `from` is the root
// For example: from='/'; to='/foo'
return to.slice(toStart + i);
}
} else if (fromLen > length) {
if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
// We get here if `to` is the exact base path for `from`.
// For example: from='/foo/bar/baz'; to='/foo/bar'
lastCommonSep = i;
} else if (i === 0) {
// We get here if `to` is the root.
// For example: from='/foo'; to='/'
lastCommonSep = 0;
}
}
break;
}
var fromCode = from.charCodeAt(fromStart + i);
var toCode = to.charCodeAt(toStart + i);
if (fromCode !== toCode) break;else if (fromCode === 47 /*/*/) lastCommonSep = i;
}
var out = '';
// Generate the relative path based on the path difference between `to`
// and `from`
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
if (out.length === 0) out += '..';else out += '/..';
}
}
// Lastly, append the rest of the destination (`to`) path that comes after
// the common path parts
if (out.length > 0) return out + to.slice(toStart + lastCommonSep);else {
toStart += lastCommonSep;
if (to.charCodeAt(toStart) === 47 /*/*/) ++toStart;
return to.slice(toStart);
}
},
_makeLong: function _makeLong(path) {
return path;
},
dirname: function dirname(path) {
assertPath(path);
if (path.length === 0) return '.';
var code = path.charCodeAt(0);
var hasRoot = code === 47 /*/*/;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
if (!matchedSlash) {
end = i;
break;
}
} else {
// We saw the first non-path separator
matchedSlash = false;
}
}
if (end === -1) return hasRoot ? '/' : '.';
if (hasRoot && end === 1) return '//';
return path.slice(0, end);
},
basename: function basename(path, ext) {
if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
assertPath(path);
var start = 0;
var end = -1;
var matchedSlash = true;
var i;
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
if (ext.length === path.length && ext === path) return '';
var extIdx = ext.length - 1;
var firstNonSlashEnd = -1;
for (i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else {
if (firstNonSlashEnd === -1) {
// We saw the first non-path separator, remember this index in case
// we need it if the extension ends up not matching
matchedSlash = false;
firstNonSlashEnd = i + 1;
}
if (extIdx >= 0) {
// Try to match the explicit extension
if (code === ext.charCodeAt(extIdx)) {
if (--extIdx === -1) {
// We matched the extension, so mark this as the end of our path
// component
end = i;
}
} else {
// Extension does not match, so our result is the entire path
// component
extIdx = -1;
end = firstNonSlashEnd;
}
}
}
}
if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
return path.slice(start, end);
} else {
for (i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// path component
matchedSlash = false;
end = i + 1;
}
}
if (end === -1) return '';
return path.slice(start, end);
}
},
extname: function extname(path) {
assertPath(path);
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
return '';
}
return path.slice(startDot, end);
},
format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
}
return _format('/', pathObject);
},
parse: function parse(path) {
assertPath(path);
var ret = {
root: '',
dir: '',
base: '',
ext: '',
name: ''
};
if (path.length === 0) return ret;
var code = path.charCodeAt(0);
var isAbsolute = code === 47 /*/*/;
var start;
if (isAbsolute) {
ret.root = '/';
start = 1;
} else {
start = 0;
}
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
var i = path.length - 1;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
// Get non-dir info
for (; i >= start; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
if (end !== -1) {
if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
}
} else {
if (startPart === 0 && isAbsolute) {
ret.name = path.slice(1, startDot);
ret.base = path.slice(1, end);
} else {
ret.name = path.slice(startPart, startDot);
ret.base = path.slice(startPart, end);
}
ret.ext = path.slice(startDot, end);
}
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
return ret;
},
sep: '/',
delimiter: ':',
win32: null,
posix: null
};
posix.posix = posix;
module.exports = posix;
/***/ }),
/***/ "./node_modules/@svta/cml-cmcd/dist/index.js":
/*!***************************************************!*\
!*** ./node_modules/@svta/cml-cmcd/dist/index.js ***!
\***************************************************/
/***/ (function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ CMCD_DEFAULT_TIME_INTERVAL: function() { return /* binding */ CMCD_DEFAULT_TIME_INTERVAL; },
/* harmony export */ CMCD_EVENT_AD_BREAK_END: function() { return /* binding */ CMCD_EVENT_AD_BREAK_END; },
/* harmony export */ CMCD_EVENT_AD_BREAK_START: function() { return /* binding */ CMCD_EVENT_AD_BREAK_START; },
/* harmony export */ CMCD_EVENT_AD_END: function() { return /* binding */ CMCD_EVENT_AD_END; },
/* harmony export */ CMCD_EVENT_AD_START: function() { return /* binding */ CMCD_EVENT_AD_START; },
/* harmony export */ CMCD_EVENT_BACKGROUNDED_MODE: function() { return /* binding */ CMCD_EVENT_BACKGROUNDED_MODE; },
/* harmony export */ CMCD_EVENT_BITRATE_CHANGE: function() { return /* binding */ CMCD_EVENT_BITRATE_CHANGE; },
/* harmony export */ CMCD_EVENT_CONTENT_ID: function() { return /* binding */ CMCD_EVENT_CONTENT_ID; },
/* harmony export */ CMCD_EVENT_CUSTOM_EVENT: function() { return /* binding */ CMCD_EVENT_CUSTOM_EVENT; },
/* harmony export */ CMCD_EVENT_ERROR: function() { return /* binding */ CMCD_EVENT_ERROR; },
/* harmony export */ CMCD_EVENT_KEYS: function() { return /* binding */ CMCD_EVENT_KEYS; },
/* harmony export */ CMCD_EVENT_MODE: function() { return /* binding */ CMCD_EVENT_MODE; },
/* harmony export */ CMCD_EVENT_MUTE: function() { return /* binding */ CMCD_EVENT_MUTE; },
/* harmony export */ CMCD_EVENT_PLAYER_COLLAPSE: function() { return /* binding */ CMCD_EVENT_PLAYER_COLLAPSE; },
/* harmony export */ CMCD_EVENT_PLAYER_EXPAND: function() { return /* binding */ CMCD_EVENT_PLAYER_EXPAND; },
/* harmony export */ CMCD_EVENT_PLAY_STATE: function() { return /* binding */ CMCD_EVENT_PLAY_STATE; },
/* harmony export */ CMCD_EVENT_RESPONSE_RECEIVED: function() { return /* binding */ CMCD_EVENT_RESPONSE_RECEIVED; },
/* harmony export */ CMCD_EVENT_SKIP: function() { return /* binding */ CMCD_EVENT_SKIP; },
/* harmony export */ CMCD_EVENT_TIME_INTERVAL: function() { return /* binding */ CMCD_EVENT_TIME_INTERVAL; },
/* harmony export */ CMCD_EVENT_UNMUTE: function() { return /* binding */ CMCD_EVENT_UNMUTE; },
/* harmony export */ CMCD_FORMATTER_MAP: function() { return /* binding */ CMCD_FORMATTER_MAP; },
/* harmony export */ CMCD_HEADERS: function() { return /* binding */ CMCD_HEADERS; },
/* harmony export */ CMCD_HEADER_FIELDS: function() { return /* binding */ CMCD_HEADER_FIELDS; },
/* harmony export */ CMCD_HEADER_MAP: function() { return /* binding */ CMCD_HEADER_MAP; },
/* harmony export */ CMCD_JSON: function() { return /* binding */ CMCD_JSON; },
/* harmony export */ CMCD_KEYS: function() { return /* binding */ CMCD_KEYS; },
/* harmony export */ CMCD_MIME_TYPE: function() { return /* binding */ CMCD_MIME_TYPE; },
/* harmony export */ CMCD_OBJECT: function() { return /* binding */ CMCD_OBJECT; },
/* harmony export */ CMCD_PARAM: function() { return /* binding */ CMCD_PARAM; },
/* harmony export */ CMCD_QUERY: function() { return /* binding */ CMCD_QUERY; },
/* harmony export */ CMCD_REQUEST: function() { return /* binding */ CMCD_REQUEST; },
/* harmony export */ CMCD_REQUEST_KEYS: function() { return /* binding */ CMCD_REQUEST_KEYS; },
/* harmony export */ CMCD_REQUEST_MODE: function() { return /* binding */ CMCD_REQUEST_MODE; },
/* harmony export */ CMCD_RESPONSE_KEYS: function() { return /* binding */ CMCD_RESPONSE_KEYS; },
/* harmony export */ CMCD_SESSION: function() { return /* binding */ CMCD_SESSION; },
/* harmony export */ CMCD_STATUS: function() { return /* binding */ CMCD_STATUS; },
/* harmony export */ CMCD_V1: function() { return /* binding */ CMCD_V1; },
/* harmony export */ CMCD_V1_KEYS: function() { return /* binding */ CMCD_V1_KEYS; },
/* harmony export */ CMCD_V2: function() { return /* binding */ CMCD_V2; },
/* harmony export */ CMCD_VALIDATION_SEVERITY_ERROR: function() { return /* binding */ CMCD_VALIDATION_SEVERITY_ERROR; },
/* harmony export */ CMCD_VALIDATION_SEVERITY_WARNING: function() { return /* binding */ CMCD_VALIDATION_SEVERITY_WARNING; },
/* harmony export */ CmcdEventType: function() { return /* binding */ CmcdEventType; },
/* harmony export */ CmcdHeaderField: function() { return /* binding */ CmcdHeaderField; },
/* harmony export */ CmcdObjectType: function() { return /* binding */ CmcdObjectType; },
/* harmony export */ CmcdPlayerState: function() { return /* binding */ CmcdPlayerState; },
/* harmony export */ CmcdReporter: function() { return /* binding */ CmcdReporter; },
/* harmony export */ CmcdReportingMode: function() { return /* binding */ CmcdReportingMode; },
/* harmony export */ CmcdStreamType: function() { return /* binding */ CmcdStreamType; },
/* harmony export */ CmcdStreamingFormat: function() { return /* binding */ CmcdStreamingFormat; },
/* harmony export */ CmcdTransmissionMode: function() { return /* binding */ CmcdTransmissionMode; },
/* harmony export */ CmcdValidationSeverity: function() { return /* binding */ CmcdValidationSeverity; },
/* harmony export */ appendCmcdHeaders: function() { return /* binding */ appendCmcdHeaders; },
/* harmony export */ appendCmcdQuery: function() { return /* binding */ appendCmcdQuery; },
/* harmony export */ decodeCmcd: function() { return /* binding */ decodeCmcd; },
/* harmony export */ encodeCmcd: function() { return /* binding */ encodeCmcd; },
/* harmony export */ fromCmcdHeaders: function() { return /* binding */ fromCmcdHeaders; },
/* harmony export */ fromCmcdQuery: function() { return /* binding */ fromCmcdQuery; },
/* harmony export */ fromCmcdUrl: function() { return /* binding */ fromCmcdUrl; },
/* harmony export */ groupCmcdHeaders: function() { return /* binding */ groupCmcdHeaders; },
/* harmony export */ isCmcdCustomKey: function() { return /* binding */ isCmcdCustomKey; },
/* harmony export */ isCmcdEventKey: function() { return /* binding */ isCmcdEventKey; },
/* harmony export */ isCmcdRequestKey: function() { return /* binding */ isCmcdRequestKey; },
/* harmony export */ isCmcdResponseReceivedKey: function() { return /* binding */ isCmcdResponseReceivedKey; },
/* harmony export */ isCmcdV1Data: function() { return /* binding */ isCmcdV1Data; },
/* harmony export */ isCmcdV1Key: function() { return /* binding */ isCmcdV1Key; },
/* harmony export */ isCmcdV2Data: function() { return /* binding */ isCmcdV2Data; },
/* harmony export */ prepareCmcdData: function() { return /* binding */ prepareCmcdData; },
/* harmony export */ toCmcdHeaders: function() { return /* binding */ toCmcdHeaders; },
/* harmony export */ toCmcdQuery: function() { return /* binding */ toCmcdQuery; },
/* harmony export */ toCmcdUrl: function() { return /* binding */ toCmcdUrl; },
/* harmony export */ toCmcdValue: function() { return /* binding */ toCmcdValue; },
/* harmony export */ validateCmcd: function() { return /* binding */ validateCmcd; },
/* harmony export */ validateCmcdEventReport: function() { return /* binding */ validateCmcdEventReport; },
/* harmony export */ validateCmcdEvents: function() { return /* binding */ validateCmcdEvents; },
/* harmony export */ validateCmcdHeaders: function() { return /* binding */ validateCmcdHeaders; },
/* harmony export */ validateCmcdKeys: function() { return /* binding */ validateCmcdKeys; },
/* harmony export */ validateCmcdRequest: function() { return /* binding */ validateCmcdRequest; },
/* harmony export */ validateCmcdStructure: function() { return /* binding */ validateCmcdStructure; },
/* harmony export */ validateCmcdValues: function() { return /* binding */ validateCmcdValues; }
/* harmony export */ });
/* harmony import */ var _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @svta/cml-structured-field-values */ "./node_modules/@svta/cml-structured-field-values/dist/index.js");
/* harmony import */ var _svta_cml_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @svta/cml-utils */ "./node_modules/@svta/cml-utils/dist/index.js");
//#region src/CMCD_FORMATTER_MAP.ts
const roundValue = value => {
if (value instanceof _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem) return new _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem(Math.round(value.value), value.params);
return Math.round(value);
};
const toRounded = value => {
if (Array.isArray(value)) return value.map(roundValue);
return roundValue(value);
};
const toUrlSafe = (value, options) => {
if (Array.isArray(value)) return value.map(item => toUrlSafe(item, options));
if (value instanceof _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem && typeof value.value === "string") return new _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem(toUrlSafe(value.value, options), value.params);else {
if (options.baseUrl) value = (0,_svta_cml_utils__WEBPACK_IMPORTED_MODULE_1__.urlToRelativePath)(value, (0,_svta_cml_utils__WEBPACK_IMPORTED_MODULE_1__.getBaseUrl)(options.baseUrl));
return options.version === 1 ? encodeURIComponent(value) : value;
}
};
const hundredValue = value => {
if (value instanceof _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem) return new _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem(Math.round(value.value / 100) * 100, value.params);
return Math.round(value / 100) * 100;
};
const toHundred = value => {
if (Array.isArray(value)) return value.map(hundredValue);
return hundredValue(value);
};
const nor = (value, options) => {
let norValue = value;
if (options.version >= 2) {
if (value instanceof _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem && typeof value.value === "string") norValue = new _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem([value]);else if (typeof value === "string") norValue = [value];
}
return toUrlSafe(norValue, options);
};
/**
* The default formatters for CMCD values.
*
* @public
*/
const CMCD_FORMATTER_MAP = {
br: toRounded,
d: toRounded,
bl: toHundred,
dl: toHundred,
mtp: toHundred,
nor,
rtp: toHundred,
tb: toRounded
};
//#endregion
//#region src/CMCD_V2.ts
/**
* CMCD Version 2
*
* @public
*/
const CMCD_V2 = 2;
//#endregion
//#region src/CmcdEventType.ts
/**
* CMCD event type for the 'bc' key (bitrate change).
*
* @public
*/
const CMCD_EVENT_BITRATE_CHANGE = "bc";
/**
* CMCD event type for the 'ps' key (play state change).
*
* @public
*/
const CMCD_EVENT_PLAY_STATE = "ps";
/**
* CMCD event type for the 'e' key (error).
*
* @public
*/
const CMCD_EVENT_ERROR = "e";
/**
* CMCD event type for the 't' key (time interval).
*
* @public
*/
const CMCD_EVENT_TIME_INTERVAL = "t";
/**
* CMCD event type for the 'c' key (content ID).
*
* @public
*/
const CMCD_EVENT_CONTENT_ID = "c";
/**
* CMCD event type for the 'b' key (backgrounded mode).
*
* @public
*/
const CMCD_EVENT_BACKGROUNDED_MODE = "b";
/**
* CMCD event type for the 'm' key (mute).
*
* @public
*/
const CMCD_EVENT_MUTE = "m";
/**
* CMCD event type for the 'um' key (unmute).
*
* @public
*/
const CMCD_EVENT_UNMUTE = "um";
/**
* CMCD event type for the 'pe' key (player expand).
*
* @public
*/
const CMCD_EVENT_PLAYER_EXPAND = "pe";
/**
* CMCD event type for the 'pc' key (player collapse).
*
* @public
*/
const CMCD_EVENT_PLAYER_COLLAPSE = "pc";
/**
* CMCD event type for the 'rr' key (response received).
*
* @public
*/
const CMCD_EVENT_RESPONSE_RECEIVED = "rr";
/**
* CMCD event type for the 'as' key (ad start).
*
* @public
*/
const CMCD_EVENT_AD_START = "as";
/**
* CMCD event type for the 'ae' key (ad end).
*
* @public
*/
const CMCD_EVENT_AD_END = "ae";
/**
* CMCD event type for the 'abs' key (ad break start).
*
* @public
*/
const CMCD_EVENT_AD_BREAK_START = "abs";
/**
* CMCD event type for the 'abe' key (ad break end).
*
* @public
*/
const CMCD_EVENT_AD_BREAK_END = "abe";
/**
* CMCD event type for the 'sk' key (skip).
*
* @public
*/
const CMCD_EVENT_SKIP = "sk";
/**
* CMCD event type for the 'ce' key (custom event).
*
* @public
*/
const CMCD_EVENT_CUSTOM_EVENT = "ce";
/**
* CMCD event types for the 'e' key (event mode).
*
* @enum
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#event | CTA-5004-B Event}
*
* @public
*/
const CmcdEventType = {
BITRATE_CHANGE: CMCD_EVENT_BITRATE_CHANGE,
PLAY_STATE: CMCD_EVENT_PLAY_STATE,
ERROR: CMCD_EVENT_ERROR,
TIME_INTERVAL: CMCD_EVENT_TIME_INTERVAL,
CONTENT_ID: CMCD_EVENT_CONTENT_ID,
BACKGROUNDED_MODE: CMCD_EVENT_BACKGROUNDED_MODE,
MUTE: CMCD_EVENT_MUTE,
UNMUTE: CMCD_EVENT_UNMUTE,
PLAYER_EXPAND: CMCD_EVENT_PLAYER_EXPAND,
PLAYER_COLLAPSE: CMCD_EVENT_PLAYER_COLLAPSE,
RESPONSE_RECEIVED: CMCD_EVENT_RESPONSE_RECEIVED,
AD_START: CMCD_EVENT_AD_START,
AD_END: CMCD_EVENT_AD_END,
AD_BREAK_START: CMCD_EVENT_AD_BREAK_START,
AD_BREAK_END: CMCD_EVENT_AD_BREAK_END,
SKIP: CMCD_EVENT_SKIP,
CUSTOM_EVENT: CMCD_EVENT_CUSTOM_EVENT
};
//#endregion
//#region src/CmcdReportingMode.ts
/**
* CMCD event mode variable name.
*
* @public
*/
const CMCD_EVENT_MODE = "event";
/**
* CMCD request mode variable name.
*
* @public
*/
const CMCD_REQUEST_MODE = "request";
/**
* CMCD reporting mode types.
*
* @enum
*
* @public
*/
const CmcdReportingMode = {
REQUEST: CMCD_REQUEST_MODE,
EVENT: CMCD_EVENT_MODE
};
//#endregion
//#region src/CMCD_EVENT_KEYS.ts
/**
* Defines the event-specific keys for CMCD (Common Media Client Data) version 2.
*
* @public
*/
const CMCD_EVENT_KEYS = ["cen", "e", "h", "ts"];
//#endregion
//#region src/CMCD_REQUEST_KEYS.ts
/**
* Defines the request-specific keys for CMCD (Common Media Client Data) version 2.
*
* @public
*/
const CMCD_REQUEST_KEYS = ["ab", "bg", "bl", "br", "bs", "bsa", "bsd", "bsda", "cdn", "cid", "cs", "d", "dfa", "dl", "ec", "lab", "lb", "ltc", "msd", "mtp", "nor", "nr", "ot", "pb", "pr", "pt", "rtp", "sf", "sid", "sn", "st", "sta", "su", "tab", "tb", "tbl", "tpb", "v"];
//#endregion
//#region src/isCmcdCustomKey.ts
const CUSTOM_KEY_REGEX = /^[a-zA-Z0-9-.]+-[a-zA-Z0-9-.]+$/;
/**
* Check if a key is a custom key.
*
* @param key - The key to check.
*
* @returns `true` if the key is a custom key, `false` otherwise.
*
* @public
*/
function isCmcdCustomKey(key) {
return CUSTOM_KEY_REGEX.test(key);
}
//#endregion
//#region src/isCmcdRequestKey.ts
const CMCD_REQUEST_KEY_SET = new Set(CMCD_REQUEST_KEYS);
/**
* Check if a key is a valid CMCD request key.
*
* @param key - The key to check.
*
* @returns `true` if the key is a valid CMCD request key, `false` otherwise.
*
* @public
*
* @example
* {@includeCode ../test/isCmcdRequestKey.test.ts#example}
*/
function isCmcdRequestKey(key) {
return CMCD_REQUEST_KEY_SET.has(key) || isCmcdCustomKey(key);
}
//#endregion
//#region src/CMCD_RESPONSE_KEYS.ts
/**
* CMCD v2 - Response-only and timing keys.
*
* @public
*/
const CMCD_RESPONSE_KEYS = ["cmsdd", "cmsds", "rc", "smrt", "ttfb", "ttfbb", "ttlb", "url"];
//#endregion
//#region src/isCmcdResponseReceivedKey.ts
const CMCD_RESPONSE_KEY_SET = new Set(CMCD_RESPONSE_KEYS);
/**
* Check if a key is a valid CMCD response key.
*
* @param key - The key to check.
*
* @returns `true` if the key is a valid CMCD request key, `false` otherwise.
*
* @public
*
* @example
* {@includeCode ../test/isCmcdResponseReceivedKey.test.ts#example}
*/
function isCmcdResponseReceivedKey(key) {
return CMCD_RESPONSE_KEY_SET.has(key);
}
//#endregion
//#region src/isCmcdEventKey.ts
const CMCD_EVENT_KEY_SET = new Set(CMCD_EVENT_KEYS);
/**
* Check if a key is a valid CMCD event key.
*
* @param key - The key to check.
*
* @returns `true` if the key is a valid CMCD event key, `false` otherwise.
*
* @public
*
* @example
* {@includeCode ../test/isCmcdEventKey.test.ts#example}
*/
function isCmcdEventKey(key) {
return isCmcdRequestKey(key) || isCmcdResponseReceivedKey(key) || CMCD_EVENT_KEY_SET.has(key);
}
//#endregion
//#region src/CMCD_INNER_LIST_KEYS.ts
/**
* Keys that are inner lists in V2 but plain scalars in V1.
*
* Used by both encoding (down-conversion) and decoding (up-conversion).
*
* @internal
*/
const CMCD_INNER_LIST_KEYS = new Set(["ab", "bl", "br", "bsa", "bsd", "bsda", "lab", "lb", "mtp", "pb", "tab", "tb", "tbl", "tpb"]);
//#endregion
//#region src/CMCD_V1_KEYS.ts
/**
* Defines the keys for CMCD (Common Media Client Data) version 1.
*
* @public
*/
const CMCD_V1_KEYS = ["bl", "br", "bs", "cid", "d", "dl", "mtp", "nor", "nrr", "ot", "pr", "rtp", "sf", "sid", "st", "su", "tb", "v"];
//#endregion
//#region src/isCmcdV1Key.ts
const CMCD_V1_KEY_SET$1 = new Set(CMCD_V1_KEYS);
/**
* Filter function for CMCD v1 keys.
*
* @param key - The CMCD key to filter.
*
* @returns `true` if the key should be included, `false` otherwise.
*
* @public
*
* @example
* {@includeCode ../test/isCmcdV1Key.test.ts#example}
*/
function isCmcdV1Key(key) {
return CMCD_V1_KEY_SET$1.has(key) || isCmcdCustomKey(key);
}
//#endregion
//#region src/isTokenField.ts
const TOKEN_FIELDS = new Set(["ot", "sf", "st", "e", "sta"]);
/**
* Checks if the given key is a token field.
*
* @param key - The key to check.
*
* @returns `true` if the key is a token field.
*
* @internal
*/
function isTokenField(key) {
return TOKEN_FIELDS.has(key);
}
//#endregion
//#region src/isValid.ts
/**
* Checks if the given value is valid
*
* @param value - The value to check.
*
* @returns `true` if the key is a value is valid.
*
* @internal
*/
function isValid(value) {
if (typeof value === "number") return Number.isFinite(value);
return value != null && value !== "" && value !== false;
}
//#endregion
//#region src/prepareCmcdData.ts
const filterMap = {
[CMCD_EVENT_MODE]: isCmcdEventKey,
[CMCD_REQUEST_MODE]: isCmcdRequestKey
};
/**
* Unwrap an inner list or SfItem value to a plain scalar.
*/
function unwrapValue(value, ot) {
if (Array.isArray(value)) {
let item;
if (ot) item = value.find(item$1 => item$1.params?.ot === ot);
if (!item) item = value[0];
return unwrapValue(item);
}
if (value instanceof _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem) return value.value;
return value;
}
/**
* Down-convert V2 CMCD data to V1 format.
*
* - Extracts `nrr` from `nor` SfItem `r` parameter.
* - Unwraps inner-list values to plain scalars.
*/
function downConvertToV1(obj) {
const result = {};
for (const [key, value] of Object.entries(obj)) {
if (value == null) {
result[key] = value;
continue;
}
if (key === "nor") {
const first = (Array.isArray(value) ? value : [value])[0];
if (first instanceof _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfItem) {
result["nor"] = first.value;
if (first.params?.r) result["nrr"] = first.params.r;
} else result["nor"] = first;
} else if (CMCD_INNER_LIST_KEYS.has(key)) result[key] = unwrapValue(value, obj["ot"]);else result[key] = value;
}
return result;
}
/**
* Convert a generic object to CMCD data.
*
* @param obj - The CMCD object to process.
* @param options - Options for encoding.
*
* @public
*/
function prepareCmcdData(obj, options = {}) {
const results = {};
if (obj == null || typeof obj !== "object") return results;
const version = options.version || obj["v"] || CMCD_V2;
const reportingMode = options.reportingMode || CMCD_REQUEST_MODE;
const data = version === 1 ? downConvertToV1(obj) : obj;
const keyFilter = version === 1 ? isCmcdV1Key : filterMap[reportingMode];
let keys = Object.keys(data).filter(keyFilter);
if (data["e"] && data["e"] !== CMCD_EVENT_RESPONSE_RECEIVED) keys = keys.filter(key => !isCmcdResponseReceivedKey(key));
const filter = options.filter;
if (typeof filter === "function") keys = keys.filter(filter);
const isEventMode = reportingMode === CMCD_EVENT_MODE;
if (isEventMode) {
const eventType = data["e"];
if (!keys.includes("e") && eventType != null) keys.push("e");
if (!keys.includes("ts")) keys.push("ts");
if (!keys.includes("cen") && data["cen"] != null && eventType === CMCD_EVENT_CUSTOM_EVENT) keys.push("cen");
}
if (keys.length === 0) return results;
if (version > 1 && !keys.includes("v")) keys.push("v");
const formatterOptions = {
version,
reportingMode,
baseUrl: options.baseUrl
};
keys.sort();
for (const key of keys) {
let value = data[key];
const formatter = options.formatters?.[key] ?? CMCD_FORMATTER_MAP[key];
if (typeof formatter === "function") value = formatter(value, formatterOptions);
if (key === "v") if (version === 1) continue;else value = version;
if (key === "pr" && value === 1) continue;
if (isEventMode && key === "ts" && !Number.isFinite(value)) value = Date.now();
if (!isValid(value)) continue;
if (isTokenField(key) && typeof value === "string") value = new _svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.SfToken(value);
results[key] = value;
}
return results;
}
//#endregion
//#region src/CmcdHeaderField.ts
/**
* CMCD object header name.
*
* @public
*/
const CMCD_OBJECT = "CMCD-Object";
/**
* CMCD request header name.
*
* @public
*/
const CMCD_REQUEST = "CMCD-Request";
/**
* CMCD session header name.
*
* @public
*/
const CMCD_SESSION = "CMCD-Session";
/**
* CMCD status header name.
*
* @public
*/
const CMCD_STATUS = "CMCD-Status";
/**
* CMCD header fields.
*
*
* @enum
*
* @public
*/
const CmcdHeaderField = {
OBJECT: CMCD_OBJECT,
REQUEST: CMCD_REQUEST,
SESSION: CMCD_SESSION,
STATUS: CMCD_STATUS
};
/**
* All CMCD header fields as an array.
*
* @public
*/
const CMCD_HEADER_FIELDS = [CMCD_OBJECT, CMCD_REQUEST, CMCD_SESSION, CMCD_STATUS];
//#endregion
//#region src/CMCD_HEADER_MAP.ts
/**
* The map of CMCD keys to their appropriate header shard.
*
* Note: Event-only keys (e, ts, cen, h) and response-received keys
* (rc, ttfb, ttlb, url, etc.) are intentionally absent. They are
* transmitted via the event-mode POST body, not HTTP headers.
*
* @public
*/
const CMCD_HEADER_MAP = {
ab: CMCD_OBJECT,
br: CMCD_OBJECT,
d: CMCD_OBJECT,
lab: CMCD_OBJECT,
lb: CMCD_OBJECT,
ot: CMCD_OBJECT,
tab: CMCD_OBJECT,
tb: CMCD_OBJECT,
tpb: CMCD_OBJECT,
bl: CMCD_REQUEST,
cs: CMCD_REQUEST,
dfa: CMCD_REQUEST,
dl: CMCD_REQUEST,
ltc: CMCD_REQUEST,
mtp: CMCD_REQUEST,
nor: CMCD_REQUEST,
nrr: CMCD_REQUEST,
pb: CMCD_REQUEST,
sn: CMCD_REQUEST,
sta: CMCD_REQUEST,
su: CMCD_REQUEST,
tbl: CMCD_REQUEST,
cid: CMCD_SESSION,
msd: CMCD_SESSION,
sf: CMCD_SESSION,
sid: CMCD_SESSION,
st: CMCD_SESSION,
v: CMCD_SESSION,
bg: CMCD_STATUS,
bs: CMCD_STATUS,
bsa: CMCD_STATUS,
bsd: CMCD_STATUS,
bsda: CMCD_STATUS,
cdn: CMCD_STATUS,
ec: CMCD_STATUS,
nr: CMCD_STATUS,
pr: CMCD_STATUS,
pt: CMCD_STATUS,
rtp: CMCD_STATUS
};
//#endregion
//#region src/groupCmcdHeaders.ts
function createHeaderMap(headerMap) {
return Object.keys(headerMap).reduce((acc, field) => {
headerMap[field]?.forEach(key => acc[key] = field);
return acc;
}, {});
}
/**
* Group a CMCD data object into header shards
*
* @param cmcd - The CMCD data object to convert.
* @param customHeaderMap - A map of CMCD header fields to custom CMCD keys.
*
* @returns The CMCD header shards.
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#header-field-definition | CTA-5004-B Header Field Definition}
*
* @public
*/
function groupCmcdHeaders(cmcd, customHeaderMap) {
const result = {};
if (!cmcd) return result;
const keys = Object.keys(cmcd);
const custom = customHeaderMap ? createHeaderMap(customHeaderMap) : {};
for (const key of keys) {
const field = CMCD_HEADER_MAP[key] || custom[key] || CmcdHeaderField.REQUEST;
const data = result[field] ??= {};
data[key] = cmcd[key];
}
return result;
}
//#endregion
//#region src/toPreparedCmcdHeaders.ts
/**
* Encode already-prepared CMCD data to CMCD header shards.
*
* @param data - The prepared CMCD data to encode.
* @param customHeaderMap - A map of CMCD header fields to custom CMCD keys.
* @returns The CMCD header shards.
*
* @internal
*/
function toPreparedCmcdHeaders(data, customHeaderMap) {
const result = {};
const shards = groupCmcdHeaders(data, customHeaderMap);
for (const [field, value] of Object.entries(shards)) {
const shard = (0,_svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.encodeSfDict)(value, {
whitespace: false
});
if (shard) result[field] = shard;
}
return result;
}
//#endregion
//#region src/toCmcdHeaders.ts
/**
* Convert a CMCD data object to request headers
*
* @param cmcd - The CMCD data object to convert.
* @param options - Options for encoding the CMCD object.
*
* @returns The CMCD header shards.
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#header-field-definition | CTA-5004-B Header Field Definition}
*
* @public
*
* @example
* {@includeCode ../test/toCmcdHeaders.test.ts#example}
*/
function toCmcdHeaders(cmcd, options = {}) {
if (!cmcd) return {};
return toPreparedCmcdHeaders(prepareCmcdData(cmcd, options), options?.customHeaderMap);
}
//#endregion
//#region src/appendCmcdHeaders.ts
/**
* Append CMCD query args to a header object.
*
* @param headers - The headers to append to.
* @param cmcd - The CMCD object to append.
* @param options - Encode options.
*
* @returns The headers with the CMCD header shards appended.
*
* @public
*
* @example
* {@includeCode ../test/appendCmcdHeaders.test.ts#example}
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#header-field-definition | CTA-5004-B Header Field Definition}
*/
function appendCmcdHeaders(headers, cmcd, options) {
return Object.assign(headers, toCmcdHeaders(cmcd, options));
}
//#endregion
//#region src/CMCD_PARAM.ts
/**
* CMCD parameter name.
*
* @public
*/
const CMCD_PARAM = "CMCD";
//#endregion
//#region src/encodePreparedCmcd.ts
/**
* Encode already-prepared CMCD data to a structured field dictionary string.
*
* @param data - The prepared CMCD data to encode.
* @returns The encoded CMCD string.
*
* @internal
*/
function encodePreparedCmcd(data) {
return (0,_svta_cml_structured_field_values__WEBPACK_IMPORTED_MODULE_0__.encodeSfDict)(data, {
whitespace: false
});
}
//#endregion
//#region src/encodeCmcd.ts
/**
* Encode a CMCD object to a string.
*
* @param cmcd - The CMCD object to encode.
* @param options - Options for encoding.
*
* @returns The encoded CMCD string.
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#payload-definition-for-headers-and-query-argument-transmission | CTA-5004-B Payload Definition}
*
* @public
*
* @example
* {@includeCode ../test/encodeCmcd.test.ts#example}
*/
function encodeCmcd(cmcd, options = {}) {
if (!cmcd) return "";
return encodePreparedCmcd(prepareCmcdData(cmcd, options));
}
//#endregion
//#region src/toCmcdUrl.ts
/**
* Convert a CMCD data object to a URL encoded string.
*
* @param cmcd - The CMCD object to convert.
* @param options - Options for encoding the CMCD object.
*
* @returns The URL encoded CMCD data.
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#query-argument-definition | CTA-5004-B Query Argument Definition}
*
* @public
*/
function toCmcdUrl(cmcd, options = {}) {
if (!cmcd) return "";
const params = encodeCmcd(cmcd, options);
return encodeURIComponent(params);
}
//#endregion
//#region src/toCmcdQuery.ts
/**
* Convert a CMCD data object to a query arg.
*
* @param cmcd - The CMCD object to convert.
* @param options - Options for encoding the CMCD object.
*
* @returns The CMCD query arg.
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#query-argument-definition | CTA-5004-B Query Argument Definition}
*
* @public
*
* @example
* {@includeCode ../test/toCmcdQuery.test.ts#example}
*/
function toCmcdQuery(cmcd, options = {}) {
if (!cmcd) return "";
return `${CMCD_PARAM}=${toCmcdUrl(cmcd, options)}`;
}
//#endregion
//#region src/appendCmcdQuery.ts
const REGEX = /CMCD=[^&#]+/;
/**
* Append CMCD query args to a URL.
*
* @param url - The URL to append to.
* @param cmcd - The CMCD object to append.
* @param options - Options for encoding the CMCD object.
*
* @returns The URL with the CMCD query args appended.
*
* @public
*
* @example
* {@includeCode ../test/appendCmcdQuery.test.ts#example}
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#query-argument-definition | CTA-5004-B Query Argument Definition}
*/
function appendCmcdQuery(url, cmcd, options) {
const query = toCmcdQuery(cmcd, options);
if (!query) return url;
if (REGEX.test(url)) return url.replace(REGEX, query);
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
}
//#endregion
//#region src/CMCD_DEFAULT_TIME_INTERVAL.ts
/**
* The default time interval in seconds when using using event mode
*
* @public
*/
const CMCD_DEFAULT_TIME_INTERVAL = 30;
//#endregion
//#region src/CMCD_KEYS.ts
/**
* A list of all CMCD keys.
*
* @public
*/
const CMCD_KEYS = [...CMCD_V1_KEYS, ...CMCD_REQUEST_KEYS, ...CMCD_RESPONSE_KEYS, ...CMCD_EVENT_KEYS].filter((key, index, arr) => arr.indexOf(key) === index);
//#endregion
//#region src/CMCD_MIME_TYPE.ts
/**
* CMCD MIME type for event report payloads.
*
* @public
*/
const CMCD_MIME_TYPE = "application/cmcd";
//#endregion
//#region src/CMCD_V1.ts
/**
* CMCD Version 1
*
* @public
*/
const CMCD_V1 = 1;
//#endregion
//#region src/CmcdObjectType.ts
/**
* Common Media Client Data Object Type
*
* @public
*
* @enum
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#object-type | CTA-5004-B Object Type}
*/
const CmcdObjectType = {
MANIFEST: "m",
AUDIO: "a",
VIDEO: "v",
MUXED: "av",
INIT: "i",
CAPTION: "c",
TIMED_TEXT: "tt",
KEY: "k",
OTHER: "o"
};
//#endregion
//#region src/CmcdPlayerState.ts
/**
* CMCD v2 player states for the 'sta' key.
*
*
* @enum
*
* @public
*
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#state | CTA-5004-B State}
*/
const CmcdPlayerState = {
STARTING: "s",
PLAYING: "p",
SEEKING: "k",
REBUFFERING: "r",
PAUSED: "a",
WAITING: "w",
ENDED: "e",
FATAL_ERROR: "f",
QUIT: "q",
PRELOADING: "d"
};
//#endregion
//#region src/CmcdTransmissionMode.ts
/**
* CMCD `query` transmission mode.
*
* @public
*/
const CMCD_QUERY = "query";
/**
* CMCD `headers` transmission mode.
*
* @public
*/
const CMCD_HEADERS = "headers";
/**
* CMCD `json` transmission mode.
*
* @public
*
* @deprecated JSON transmission mode is deprecated and will be removed in future versions.
*/
const CMCD_JSON = "json";
/**
* CMCD transmission modes.
*
* @enum
*
* @public
*/
const CmcdTransmissionMode = {
JSON: CMCD_JSON,
QUERY: CMCD_QUERY,
HEADERS: CMCD_HEADERS
};
//#endregion
//#region src/CmcdReporter.ts
function createEncodingOptions(reportingMode, config, baseUrl) {
const enabledKeySet = new Set(config.enabledKeys ?? []);
return {
version: config.version || CMCD_V2,
reportingMode,
filter: key => enabledKeySet.has(key),
baseUrl
};
}
function defaultRequester(request) {
const {
url,
...init
} = request;
return fetch(url, init);
}
function createCmcdReporterConfig(config) {
const {
version = CMCD_V2,
eventTargets = [],
sid = (0,_svta_cml_utils__WEBPACK_IMPORTED_MODULE_1__.uuid)(),
transmissionMode = CMCD_QUERY,
...rest
} = config;
return {
...rest,
version,
transmissionMode,
sid,
eventTargets: eventTargets.reduce((acc, target) => {
if (target?.url && target.events?.length) ac