@svta/cml-cmcd 2.8.1 → 2.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2665 -2616
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +381 -223
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SfItem, SfToken, decodeSfDict, encodeSfDict, symbolToStr } from "@svta/cml-structured-field-values";
|
|
2
2
|
import { getBaseUrl, urlToRelativePath, uuid } from "@svta/cml-utils";
|
|
3
|
-
|
|
4
3
|
//#region src/CMCD_INNER_LIST_KEYS.ts
|
|
5
4
|
/**
|
|
6
5
|
* Inner-list keys in version 2 that are scalars in version 1.
|
|
@@ -9,7 +8,7 @@ import { getBaseUrl, urlToRelativePath, uuid } from "@svta/cml-utils";
|
|
|
9
8
|
*
|
|
10
9
|
* @internal
|
|
11
10
|
*/
|
|
12
|
-
const CMCD_INNER_LIST_KEYS = new Set([
|
|
11
|
+
const CMCD_INNER_LIST_KEYS = /* @__PURE__ */ new Set([
|
|
13
12
|
"ab",
|
|
14
13
|
"bl",
|
|
15
14
|
"br",
|
|
@@ -25,17 +24,6 @@ const CMCD_INNER_LIST_KEYS = new Set([
|
|
|
25
24
|
"tbl",
|
|
26
25
|
"tpb"
|
|
27
26
|
]);
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/CMCD_KEY_SPECS.ts
|
|
31
|
-
const MEDIA = [
|
|
32
|
-
"a",
|
|
33
|
-
"v",
|
|
34
|
-
"av",
|
|
35
|
-
"tt",
|
|
36
|
-
"c",
|
|
37
|
-
"o"
|
|
38
|
-
];
|
|
39
27
|
/**
|
|
40
28
|
* The encoder rules of each key. The table has one row for each key of CTA-5004-B Table 1, plus `nrr` of CTA-5004 and `cdn`.
|
|
41
29
|
*
|
|
@@ -120,7 +108,14 @@ const CMCD_KEY_SPECS = {
|
|
|
120
108
|
d: {
|
|
121
109
|
type: "integer",
|
|
122
110
|
round: 1,
|
|
123
|
-
ot:
|
|
111
|
+
ot: [
|
|
112
|
+
"a",
|
|
113
|
+
"v",
|
|
114
|
+
"av",
|
|
115
|
+
"tt",
|
|
116
|
+
"c",
|
|
117
|
+
"o"
|
|
118
|
+
]
|
|
124
119
|
},
|
|
125
120
|
dfa: {
|
|
126
121
|
type: "integer",
|
|
@@ -311,7 +306,6 @@ const CMCD_KEY_SPECS = {
|
|
|
311
306
|
version: 2
|
|
312
307
|
}
|
|
313
308
|
};
|
|
314
|
-
|
|
315
309
|
//#endregion
|
|
316
310
|
//#region src/CMCD_V2.ts
|
|
317
311
|
/**
|
|
@@ -320,7 +314,6 @@ const CMCD_KEY_SPECS = {
|
|
|
320
314
|
* @public
|
|
321
315
|
*/
|
|
322
316
|
const CMCD_V2 = 2;
|
|
323
|
-
|
|
324
317
|
//#endregion
|
|
325
318
|
//#region src/CmcdReportingMode.ts
|
|
326
319
|
/**
|
|
@@ -343,10 +336,15 @@ const CMCD_REQUEST_MODE = "request";
|
|
|
343
336
|
* @public
|
|
344
337
|
*/
|
|
345
338
|
const CmcdReportingMode = {
|
|
339
|
+
/**
|
|
340
|
+
* Request mode
|
|
341
|
+
*/
|
|
346
342
|
REQUEST: CMCD_REQUEST_MODE,
|
|
343
|
+
/**
|
|
344
|
+
* Event mode
|
|
345
|
+
*/
|
|
347
346
|
EVENT: CMCD_EVENT_MODE
|
|
348
347
|
};
|
|
349
|
-
|
|
350
348
|
//#endregion
|
|
351
349
|
//#region src/downConvertToV1.ts
|
|
352
350
|
function hasParams(params) {
|
|
@@ -401,7 +399,6 @@ function downConvertToV1(obj, ot) {
|
|
|
401
399
|
}
|
|
402
400
|
return result;
|
|
403
401
|
}
|
|
404
|
-
|
|
405
402
|
//#endregion
|
|
406
403
|
//#region src/isCmcdCustomKey.ts
|
|
407
404
|
const CUSTOM_KEY_REGEX = /^[a-z][a-z0-9.-]*$/;
|
|
@@ -424,7 +421,6 @@ function isCmcdCustomKey(key) {
|
|
|
424
421
|
const separator = key.indexOf("-", 1);
|
|
425
422
|
return separator > 0 && separator < key.length - 1 && CUSTOM_KEY_REGEX.test(key);
|
|
426
423
|
}
|
|
427
|
-
|
|
428
424
|
//#endregion
|
|
429
425
|
//#region src/getKeySpec.ts
|
|
430
426
|
const CUSTOM_KEY_SPEC = {
|
|
@@ -446,7 +442,6 @@ function getKeySpec(key) {
|
|
|
446
442
|
if (Object.prototype.hasOwnProperty.call(CMCD_KEY_SPECS, key)) return CMCD_KEY_SPECS[key];
|
|
447
443
|
return isCmcdCustomKey(key) ? CUSTOM_KEY_SPEC : void 0;
|
|
448
444
|
}
|
|
449
|
-
|
|
450
445
|
//#endregion
|
|
451
446
|
//#region src/isValid.ts
|
|
452
447
|
/**
|
|
@@ -467,7 +462,6 @@ function isValid(value) {
|
|
|
467
462
|
if (Array.isArray(value)) return value.length > 0;
|
|
468
463
|
return value != null && value !== "" && value !== false;
|
|
469
464
|
}
|
|
470
|
-
|
|
471
465
|
//#endregion
|
|
472
466
|
//#region src/formatNor.ts
|
|
473
467
|
function toBase(baseUrl) {
|
|
@@ -521,7 +515,6 @@ function formatNor(value, options) {
|
|
|
521
515
|
const entry = formatEntry(value, base, version);
|
|
522
516
|
return version === 1 || entry === void 0 ? entry : [entry];
|
|
523
517
|
}
|
|
524
|
-
|
|
525
518
|
//#endregion
|
|
526
519
|
//#region src/toTokenString.ts
|
|
527
520
|
/**
|
|
@@ -541,7 +534,6 @@ function toTokenString(value) {
|
|
|
541
534
|
if (typeof value === "string") return value;
|
|
542
535
|
if (typeof value === "symbol" || value instanceof SfToken) return symbolToStr(value);
|
|
543
536
|
}
|
|
544
|
-
|
|
545
537
|
//#endregion
|
|
546
538
|
//#region src/normalizeValue.ts
|
|
547
539
|
function toText(value, spec, version) {
|
|
@@ -608,7 +600,6 @@ function normalizeValue(value, spec, options) {
|
|
|
608
600
|
if (spec.type === "string-list" || spec.type === "ot-list" && options.version !== 1) return normalizeList(value, spec, options.version);
|
|
609
601
|
return normalizeItem(value, spec, options.version);
|
|
610
602
|
}
|
|
611
|
-
|
|
612
603
|
//#endregion
|
|
613
604
|
//#region src/toBareValue.ts
|
|
614
605
|
/**
|
|
@@ -625,7 +616,6 @@ function normalizeValue(value, spec, options) {
|
|
|
625
616
|
function toBareValue(value) {
|
|
626
617
|
return value instanceof SfItem ? value.value : value;
|
|
627
618
|
}
|
|
628
|
-
|
|
629
619
|
//#endregion
|
|
630
620
|
//#region src/prepareCmcdData.ts
|
|
631
621
|
function hasKey(spec, reportingMode, isV1) {
|
|
@@ -680,10 +670,10 @@ function prepareValue(key, value, spec, options, formatterOptions) {
|
|
|
680
670
|
function prepareCmcdData(obj, options = {}) {
|
|
681
671
|
const results = {};
|
|
682
672
|
if (obj == null || typeof obj !== "object") return results;
|
|
683
|
-
const version = options.version || toBareValue(obj["v"]) ||
|
|
684
|
-
const reportingMode = options.reportingMode ||
|
|
673
|
+
const version = options.version || toBareValue(obj["v"]) || 2;
|
|
674
|
+
const reportingMode = options.reportingMode || "request";
|
|
685
675
|
const isV1 = version === 1;
|
|
686
|
-
const isEventReport = !isV1 && reportingMode ===
|
|
676
|
+
const isEventReport = !isV1 && reportingMode === "event";
|
|
687
677
|
const formatterOptions = {
|
|
688
678
|
version,
|
|
689
679
|
reportingMode,
|
|
@@ -743,7 +733,6 @@ function prepareCmcdData(obj, options = {}) {
|
|
|
743
733
|
}
|
|
744
734
|
return results;
|
|
745
735
|
}
|
|
746
|
-
|
|
747
736
|
//#endregion
|
|
748
737
|
//#region src/CmcdHeaderField.ts
|
|
749
738
|
/**
|
|
@@ -779,9 +768,21 @@ const CMCD_STATUS = "CMCD-Status";
|
|
|
779
768
|
* @public
|
|
780
769
|
*/
|
|
781
770
|
const CmcdHeaderField = {
|
|
771
|
+
/**
|
|
772
|
+
* keys whose values vary with the object being requested.
|
|
773
|
+
*/
|
|
782
774
|
OBJECT: CMCD_OBJECT,
|
|
775
|
+
/**
|
|
776
|
+
* keys whose values vary with each request.
|
|
777
|
+
*/
|
|
783
778
|
REQUEST: CMCD_REQUEST,
|
|
779
|
+
/**
|
|
780
|
+
* keys whose values are expected to be invariant over the life of the session.
|
|
781
|
+
*/
|
|
784
782
|
SESSION: CMCD_SESSION,
|
|
783
|
+
/**
|
|
784
|
+
* keys whose values do not vary with every request or object.
|
|
785
|
+
*/
|
|
785
786
|
STATUS: CMCD_STATUS
|
|
786
787
|
};
|
|
787
788
|
/**
|
|
@@ -795,7 +796,6 @@ const CMCD_HEADER_FIELDS = [
|
|
|
795
796
|
CMCD_SESSION,
|
|
796
797
|
CMCD_STATUS
|
|
797
798
|
];
|
|
798
|
-
|
|
799
799
|
//#endregion
|
|
800
800
|
//#region src/CMCD_HEADER_MAP.ts
|
|
801
801
|
/**
|
|
@@ -848,7 +848,6 @@ const CMCD_HEADER_MAP = {
|
|
|
848
848
|
pt: CMCD_STATUS,
|
|
849
849
|
rtp: CMCD_STATUS
|
|
850
850
|
};
|
|
851
|
-
|
|
852
851
|
//#endregion
|
|
853
852
|
//#region src/groupCmcdHeaders.ts
|
|
854
853
|
function createHeaderMap(headerMap) {
|
|
@@ -881,7 +880,6 @@ function groupCmcdHeaders(cmcd, customHeaderMap) {
|
|
|
881
880
|
}
|
|
882
881
|
return result;
|
|
883
882
|
}
|
|
884
|
-
|
|
885
883
|
//#endregion
|
|
886
884
|
//#region src/toPreparedCmcdHeaders.ts
|
|
887
885
|
/**
|
|
@@ -902,7 +900,6 @@ function toPreparedCmcdHeaders(data, customHeaderMap) {
|
|
|
902
900
|
}
|
|
903
901
|
return result;
|
|
904
902
|
}
|
|
905
|
-
|
|
906
903
|
//#endregion
|
|
907
904
|
//#region src/toCmcdHeaders.ts
|
|
908
905
|
/**
|
|
@@ -924,7 +921,6 @@ function toCmcdHeaders(cmcd, options = {}) {
|
|
|
924
921
|
if (!cmcd) return {};
|
|
925
922
|
return toPreparedCmcdHeaders(prepareCmcdData(cmcd, options), options?.customHeaderMap);
|
|
926
923
|
}
|
|
927
|
-
|
|
928
924
|
//#endregion
|
|
929
925
|
//#region src/appendCmcdHeaders.ts
|
|
930
926
|
/**
|
|
@@ -946,7 +942,6 @@ function toCmcdHeaders(cmcd, options = {}) {
|
|
|
946
942
|
function appendCmcdHeaders(headers, cmcd, options) {
|
|
947
943
|
return Object.assign(headers, toCmcdHeaders(cmcd, options));
|
|
948
944
|
}
|
|
949
|
-
|
|
950
945
|
//#endregion
|
|
951
946
|
//#region src/encodePreparedCmcd.ts
|
|
952
947
|
/**
|
|
@@ -960,7 +955,6 @@ function appendCmcdHeaders(headers, cmcd, options) {
|
|
|
960
955
|
function encodePreparedCmcd(data) {
|
|
961
956
|
return encodeSfDict(data, { whitespace: false });
|
|
962
957
|
}
|
|
963
|
-
|
|
964
958
|
//#endregion
|
|
965
959
|
//#region src/encodeCmcd.ts
|
|
966
960
|
/**
|
|
@@ -982,7 +976,6 @@ function encodeCmcd(cmcd, options = {}) {
|
|
|
982
976
|
if (!cmcd) return "";
|
|
983
977
|
return encodePreparedCmcd(prepareCmcdData(cmcd, options));
|
|
984
978
|
}
|
|
985
|
-
|
|
986
979
|
//#endregion
|
|
987
980
|
//#region src/CMCD_PARAM.ts
|
|
988
981
|
/**
|
|
@@ -991,7 +984,6 @@ function encodeCmcd(cmcd, options = {}) {
|
|
|
991
984
|
* @public
|
|
992
985
|
*/
|
|
993
986
|
const CMCD_PARAM = "CMCD";
|
|
994
|
-
|
|
995
987
|
//#endregion
|
|
996
988
|
//#region src/percentEncode.ts
|
|
997
989
|
const SUB_DELIMS_REGEX = /[!'()*]/g;
|
|
@@ -1023,11 +1015,10 @@ function percentEncode(value) {
|
|
|
1023
1015
|
}
|
|
1024
1016
|
return encoded.replace(SUB_DELIMS_REGEX, encodeSubDelim);
|
|
1025
1017
|
}
|
|
1026
|
-
|
|
1027
1018
|
//#endregion
|
|
1028
1019
|
//#region src/replaceCmcdParam.ts
|
|
1029
1020
|
function isCmcdParam(param) {
|
|
1030
|
-
return param ===
|
|
1021
|
+
return param === "CMCD" || param.startsWith(`CMCD=`);
|
|
1031
1022
|
}
|
|
1032
1023
|
/**
|
|
1033
1024
|
* Replace the `CMCD` query parameter of a URL.
|
|
@@ -1067,7 +1058,6 @@ function replaceCmcdParam(url, value) {
|
|
|
1067
1058
|
const query = params.join("&");
|
|
1068
1059
|
return `${url.slice(0, start)}${query ? `?${query}` : ""}${url.slice(end)}`;
|
|
1069
1060
|
}
|
|
1070
|
-
|
|
1071
1061
|
//#endregion
|
|
1072
1062
|
//#region src/appendCmcdQuery.ts
|
|
1073
1063
|
/**
|
|
@@ -1094,7 +1084,6 @@ function appendCmcdQuery(url, cmcd, options) {
|
|
|
1094
1084
|
const value = cmcd ? encodeCmcd(cmcd, options) : "";
|
|
1095
1085
|
return value ? replaceCmcdParam(url, value) : url;
|
|
1096
1086
|
}
|
|
1097
|
-
|
|
1098
1087
|
//#endregion
|
|
1099
1088
|
//#region src/CMCD_DEFAULT_TIME_INTERVAL.ts
|
|
1100
1089
|
/**
|
|
@@ -1103,7 +1092,6 @@ function appendCmcdQuery(url, cmcd, options) {
|
|
|
1103
1092
|
* @public
|
|
1104
1093
|
*/
|
|
1105
1094
|
const CMCD_DEFAULT_TIME_INTERVAL = 30;
|
|
1106
|
-
|
|
1107
1095
|
//#endregion
|
|
1108
1096
|
//#region src/CMCD_EVENT_KEYS.ts
|
|
1109
1097
|
/**
|
|
@@ -1117,7 +1105,6 @@ const CMCD_EVENT_KEYS = [
|
|
|
1117
1105
|
"h",
|
|
1118
1106
|
"ts"
|
|
1119
1107
|
];
|
|
1120
|
-
|
|
1121
1108
|
//#endregion
|
|
1122
1109
|
//#region src/CMCD_FORMATTER_MAP.ts
|
|
1123
1110
|
const formatNumbers = (value, format) => {
|
|
@@ -1149,37 +1136,123 @@ const toHundred = (value) => formatNumbers(value, roundToHundred);
|
|
|
1149
1136
|
* @public
|
|
1150
1137
|
*/
|
|
1151
1138
|
const CMCD_FORMATTER_MAP = {
|
|
1139
|
+
/**
|
|
1140
|
+
* Bitrate (kbps) rounded integer
|
|
1141
|
+
*/
|
|
1152
1142
|
br: toRounded,
|
|
1143
|
+
/**
|
|
1144
|
+
* Duration (milliseconds) rounded integer
|
|
1145
|
+
*/
|
|
1153
1146
|
d: toRounded,
|
|
1147
|
+
/**
|
|
1148
|
+
* Buffer Length (milliseconds) rounded nearest 100ms
|
|
1149
|
+
*/
|
|
1154
1150
|
bl: toHundred,
|
|
1151
|
+
/**
|
|
1152
|
+
* Deadline (milliseconds) rounded nearest 100ms
|
|
1153
|
+
*/
|
|
1155
1154
|
dl: toHundred,
|
|
1155
|
+
/**
|
|
1156
|
+
* Measured Throughput (kbps) rounded nearest 100kbps
|
|
1157
|
+
*/
|
|
1156
1158
|
mtp: toHundred,
|
|
1159
|
+
/**
|
|
1160
|
+
* Next Object Request URL encoded
|
|
1161
|
+
*/
|
|
1157
1162
|
nor: (value, options) => formatNor(value, options) ?? "",
|
|
1163
|
+
/**
|
|
1164
|
+
* Requested maximum throughput (kbps) rounded nearest 100kbps
|
|
1165
|
+
*/
|
|
1158
1166
|
rtp: toHundred,
|
|
1167
|
+
/**
|
|
1168
|
+
* Top Bitrate (kbps) rounded integer
|
|
1169
|
+
*/
|
|
1159
1170
|
tb: toRounded,
|
|
1171
|
+
/**
|
|
1172
|
+
* Target Buffer Length (milliseconds) rounded nearest 100ms
|
|
1173
|
+
*/
|
|
1160
1174
|
tbl: toHundred,
|
|
1175
|
+
/**
|
|
1176
|
+
* Aggregate Encoded Bitrate (kbps) rounded integer
|
|
1177
|
+
*/
|
|
1161
1178
|
ab: toRounded,
|
|
1179
|
+
/**
|
|
1180
|
+
* Buffer Starvation Absolute (count) rounded integer
|
|
1181
|
+
*/
|
|
1162
1182
|
bsa: toRounded,
|
|
1183
|
+
/**
|
|
1184
|
+
* Buffer Starvation Duration (milliseconds) rounded integer
|
|
1185
|
+
*/
|
|
1163
1186
|
bsd: toRounded,
|
|
1187
|
+
/**
|
|
1188
|
+
* Buffer Starvation Duration Absolute (milliseconds) rounded integer
|
|
1189
|
+
*/
|
|
1164
1190
|
bsda: toRounded,
|
|
1191
|
+
/**
|
|
1192
|
+
* Dropped Frames Absolute (count) rounded integer
|
|
1193
|
+
*/
|
|
1165
1194
|
dfa: toRounded,
|
|
1195
|
+
/**
|
|
1196
|
+
* Lowest Aggregated Encoded Bitrate (kbps) rounded integer
|
|
1197
|
+
*/
|
|
1166
1198
|
lab: toRounded,
|
|
1199
|
+
/**
|
|
1200
|
+
* Lowest Encoded Bitrate (kbps) rounded integer
|
|
1201
|
+
*/
|
|
1167
1202
|
lb: toRounded,
|
|
1203
|
+
/**
|
|
1204
|
+
* Live Stream Latency (milliseconds) rounded integer
|
|
1205
|
+
*/
|
|
1168
1206
|
ltc: toRounded,
|
|
1207
|
+
/**
|
|
1208
|
+
* Media Start Delay (milliseconds) rounded integer
|
|
1209
|
+
*/
|
|
1169
1210
|
msd: toRounded,
|
|
1211
|
+
/**
|
|
1212
|
+
* Playhead Bitrate (kbps) rounded integer
|
|
1213
|
+
*/
|
|
1170
1214
|
pb: toRounded,
|
|
1215
|
+
/**
|
|
1216
|
+
* Playback Rate decimal, not rounded
|
|
1217
|
+
*/
|
|
1171
1218
|
pr: toNumber,
|
|
1219
|
+
/**
|
|
1220
|
+
* Playhead Time (milliseconds) rounded integer
|
|
1221
|
+
*/
|
|
1172
1222
|
pt: toRounded,
|
|
1223
|
+
/**
|
|
1224
|
+
* Response Code rounded integer
|
|
1225
|
+
*/
|
|
1173
1226
|
rc: toRounded,
|
|
1227
|
+
/**
|
|
1228
|
+
* Sequence Number rounded integer
|
|
1229
|
+
*/
|
|
1174
1230
|
sn: toRounded,
|
|
1231
|
+
/**
|
|
1232
|
+
* Top Aggregated Encoded Bitrate (kbps) rounded integer
|
|
1233
|
+
*/
|
|
1175
1234
|
tab: toRounded,
|
|
1235
|
+
/**
|
|
1236
|
+
* Top Playable Bitrate (kbps) rounded integer
|
|
1237
|
+
*/
|
|
1176
1238
|
tpb: toRounded,
|
|
1239
|
+
/**
|
|
1240
|
+
* Timestamp (milliseconds) rounded integer
|
|
1241
|
+
*/
|
|
1177
1242
|
ts: toRounded,
|
|
1243
|
+
/**
|
|
1244
|
+
* Time To First Byte (milliseconds) rounded integer
|
|
1245
|
+
*/
|
|
1178
1246
|
ttfb: toRounded,
|
|
1247
|
+
/**
|
|
1248
|
+
* Time To First Body Byte (milliseconds) rounded integer
|
|
1249
|
+
*/
|
|
1179
1250
|
ttfbb: toRounded,
|
|
1251
|
+
/**
|
|
1252
|
+
* Time To Last Byte (milliseconds) rounded integer
|
|
1253
|
+
*/
|
|
1180
1254
|
ttlb: toRounded
|
|
1181
1255
|
};
|
|
1182
|
-
|
|
1183
1256
|
//#endregion
|
|
1184
1257
|
//#region src/CMCD_REQUEST_KEYS.ts
|
|
1185
1258
|
/**
|
|
@@ -1227,7 +1300,6 @@ const CMCD_REQUEST_KEYS = [
|
|
|
1227
1300
|
"tpb",
|
|
1228
1301
|
"v"
|
|
1229
1302
|
];
|
|
1230
|
-
|
|
1231
1303
|
//#endregion
|
|
1232
1304
|
//#region src/CMCD_RESPONSE_KEYS.ts
|
|
1233
1305
|
/**
|
|
@@ -1245,7 +1317,6 @@ const CMCD_RESPONSE_KEYS = [
|
|
|
1245
1317
|
"ttlb",
|
|
1246
1318
|
"url"
|
|
1247
1319
|
];
|
|
1248
|
-
|
|
1249
1320
|
//#endregion
|
|
1250
1321
|
//#region src/CMCD_V1_KEYS.ts
|
|
1251
1322
|
/**
|
|
@@ -1273,7 +1344,6 @@ const CMCD_V1_KEYS = [
|
|
|
1273
1344
|
"tb",
|
|
1274
1345
|
"v"
|
|
1275
1346
|
];
|
|
1276
|
-
|
|
1277
1347
|
//#endregion
|
|
1278
1348
|
//#region src/CMCD_KEYS.ts
|
|
1279
1349
|
/**
|
|
@@ -1287,7 +1357,6 @@ const CMCD_KEYS = /* @__PURE__ */ [
|
|
|
1287
1357
|
...CMCD_RESPONSE_KEYS,
|
|
1288
1358
|
...CMCD_EVENT_KEYS
|
|
1289
1359
|
].filter((key, index, arr) => arr.indexOf(key) === index);
|
|
1290
|
-
|
|
1291
1360
|
//#endregion
|
|
1292
1361
|
//#region src/CMCD_MIME_TYPE.ts
|
|
1293
1362
|
/**
|
|
@@ -1296,7 +1365,6 @@ const CMCD_KEYS = /* @__PURE__ */ [
|
|
|
1296
1365
|
* @public
|
|
1297
1366
|
*/
|
|
1298
1367
|
const CMCD_MIME_TYPE = "application/cmcd";
|
|
1299
|
-
|
|
1300
1368
|
//#endregion
|
|
1301
1369
|
//#region src/CMCD_REQUEST_PROVENANCE.ts
|
|
1302
1370
|
/**
|
|
@@ -1324,7 +1392,6 @@ const CMCD_MIME_TYPE = "application/cmcd";
|
|
|
1324
1392
|
* @public
|
|
1325
1393
|
*/
|
|
1326
1394
|
const CMCD_REQUEST_PROVENANCE = /* @__PURE__ */ Symbol.for("@svta/cml-cmcd/request-provenance");
|
|
1327
|
-
|
|
1328
1395
|
//#endregion
|
|
1329
1396
|
//#region src/CMCD_V1.ts
|
|
1330
1397
|
/**
|
|
@@ -1333,7 +1400,6 @@ const CMCD_REQUEST_PROVENANCE = /* @__PURE__ */ Symbol.for("@svta/cml-cmcd/reque
|
|
|
1333
1400
|
* @public
|
|
1334
1401
|
*/
|
|
1335
1402
|
const CMCD_V1 = 1;
|
|
1336
|
-
|
|
1337
1403
|
//#endregion
|
|
1338
1404
|
//#region src/CmcdEventType.ts
|
|
1339
1405
|
/**
|
|
@@ -1454,26 +1520,79 @@ const CMCD_EVENT_CUSTOM_EVENT = "ce";
|
|
|
1454
1520
|
* @public
|
|
1455
1521
|
*/
|
|
1456
1522
|
const CmcdEventType = {
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1523
|
+
/**
|
|
1524
|
+
* A change in the bitrate.
|
|
1525
|
+
*/
|
|
1526
|
+
BITRATE_CHANGE: "bc",
|
|
1527
|
+
/**
|
|
1528
|
+
* A change in the player state.
|
|
1529
|
+
*/
|
|
1530
|
+
PLAY_STATE: "ps",
|
|
1531
|
+
/**
|
|
1532
|
+
* A change in the playback rate.
|
|
1533
|
+
*/
|
|
1534
|
+
PLAYBACK_RATE: "pr",
|
|
1535
|
+
/**
|
|
1536
|
+
* An error event.
|
|
1537
|
+
*/
|
|
1538
|
+
ERROR: "e",
|
|
1539
|
+
/**
|
|
1540
|
+
* A periodic report sent on a time interval.
|
|
1541
|
+
*/
|
|
1542
|
+
TIME_INTERVAL: "t",
|
|
1543
|
+
/**
|
|
1544
|
+
* A change of the content ID.
|
|
1545
|
+
*/
|
|
1546
|
+
CONTENT_ID: "c",
|
|
1547
|
+
/**
|
|
1548
|
+
* A change in the player's backgrounded state.
|
|
1549
|
+
*/
|
|
1550
|
+
BACKGROUNDED_MODE: "b",
|
|
1551
|
+
/**
|
|
1552
|
+
* The player was muted.
|
|
1553
|
+
*/
|
|
1554
|
+
MUTE: "m",
|
|
1555
|
+
/**
|
|
1556
|
+
* The player was unmuted.
|
|
1557
|
+
*/
|
|
1558
|
+
UNMUTE: "um",
|
|
1559
|
+
/**
|
|
1560
|
+
* The player view was expanded.
|
|
1561
|
+
*/
|
|
1562
|
+
PLAYER_EXPAND: "pe",
|
|
1563
|
+
/**
|
|
1564
|
+
* The player view was collapsed.
|
|
1565
|
+
*/
|
|
1566
|
+
PLAYER_COLLAPSE: "pc",
|
|
1567
|
+
/**
|
|
1568
|
+
* The receipt of a response.
|
|
1569
|
+
*/
|
|
1570
|
+
RESPONSE_RECEIVED: "rr",
|
|
1571
|
+
/**
|
|
1572
|
+
* The start of an ad.
|
|
1573
|
+
*/
|
|
1574
|
+
AD_START: "as",
|
|
1575
|
+
/**
|
|
1576
|
+
* The end of an ad.
|
|
1577
|
+
*/
|
|
1578
|
+
AD_END: "ae",
|
|
1579
|
+
/**
|
|
1580
|
+
* The start of an ad break.
|
|
1581
|
+
*/
|
|
1582
|
+
AD_BREAK_START: "abs",
|
|
1583
|
+
/**
|
|
1584
|
+
* The end of an ad break.
|
|
1585
|
+
*/
|
|
1586
|
+
AD_BREAK_END: "abe",
|
|
1587
|
+
/**
|
|
1588
|
+
* The user skipped an ad.
|
|
1589
|
+
*/
|
|
1590
|
+
SKIP: "sk",
|
|
1591
|
+
/**
|
|
1592
|
+
* A custom event.
|
|
1593
|
+
*/
|
|
1594
|
+
CUSTOM_EVENT: "ce"
|
|
1475
1595
|
};
|
|
1476
|
-
|
|
1477
1596
|
//#endregion
|
|
1478
1597
|
//#region src/CmcdObjectType.ts
|
|
1479
1598
|
/**
|
|
@@ -1486,17 +1605,43 @@ const CmcdEventType = {
|
|
|
1486
1605
|
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#object-type | CTA-5004-B Object Type}
|
|
1487
1606
|
*/
|
|
1488
1607
|
const CmcdObjectType = {
|
|
1608
|
+
/**
|
|
1609
|
+
* text file, such as a manifest or playlist
|
|
1610
|
+
*/
|
|
1489
1611
|
MANIFEST: "m",
|
|
1612
|
+
/**
|
|
1613
|
+
* audio only
|
|
1614
|
+
*/
|
|
1490
1615
|
AUDIO: "a",
|
|
1616
|
+
/**
|
|
1617
|
+
* video only
|
|
1618
|
+
*/
|
|
1491
1619
|
VIDEO: "v",
|
|
1620
|
+
/**
|
|
1621
|
+
* muxed audio and video
|
|
1622
|
+
*/
|
|
1492
1623
|
MUXED: "av",
|
|
1624
|
+
/**
|
|
1625
|
+
* init segment
|
|
1626
|
+
*/
|
|
1493
1627
|
INIT: "i",
|
|
1628
|
+
/**
|
|
1629
|
+
* caption or subtitle
|
|
1630
|
+
*/
|
|
1494
1631
|
CAPTION: "c",
|
|
1632
|
+
/**
|
|
1633
|
+
* ISOBMFF timed text track
|
|
1634
|
+
*/
|
|
1495
1635
|
TIMED_TEXT: "tt",
|
|
1636
|
+
/**
|
|
1637
|
+
* cryptographic key, license or certificate.
|
|
1638
|
+
*/
|
|
1496
1639
|
KEY: "k",
|
|
1640
|
+
/**
|
|
1641
|
+
* other
|
|
1642
|
+
*/
|
|
1497
1643
|
OTHER: "o"
|
|
1498
1644
|
};
|
|
1499
|
-
|
|
1500
1645
|
//#endregion
|
|
1501
1646
|
//#region src/CmcdPlayerState.ts
|
|
1502
1647
|
/**
|
|
@@ -1510,18 +1655,47 @@ const CmcdObjectType = {
|
|
|
1510
1655
|
* @see {@link https://cta-wave.github.io/Resources/common-media-client-data--cta-5004-b.html#state | CTA-5004-B State}
|
|
1511
1656
|
*/
|
|
1512
1657
|
const CmcdPlayerState = {
|
|
1658
|
+
/**
|
|
1659
|
+
* Starting: Initial startup of the player.
|
|
1660
|
+
*/
|
|
1513
1661
|
STARTING: "s",
|
|
1662
|
+
/**
|
|
1663
|
+
* Playing: The player is actively rendering content.
|
|
1664
|
+
*/
|
|
1514
1665
|
PLAYING: "p",
|
|
1666
|
+
/**
|
|
1667
|
+
* Seeking: The player is seeking to a new position.
|
|
1668
|
+
*/
|
|
1515
1669
|
SEEKING: "k",
|
|
1670
|
+
/**
|
|
1671
|
+
* Rebuffering: The player is buffering data during playback.
|
|
1672
|
+
*/
|
|
1516
1673
|
REBUFFERING: "r",
|
|
1674
|
+
/**
|
|
1675
|
+
* Paused: The player is paused.
|
|
1676
|
+
*/
|
|
1517
1677
|
PAUSED: "a",
|
|
1678
|
+
/**
|
|
1679
|
+
* Waiting: The player is waiting for a user action or another event.
|
|
1680
|
+
*/
|
|
1518
1681
|
WAITING: "w",
|
|
1682
|
+
/**
|
|
1683
|
+
* Ended: The media has finished playing.
|
|
1684
|
+
*/
|
|
1519
1685
|
ENDED: "e",
|
|
1686
|
+
/**
|
|
1687
|
+
* Fatal Error: The player has encountered a fatal error.
|
|
1688
|
+
*/
|
|
1520
1689
|
FATAL_ERROR: "f",
|
|
1690
|
+
/**
|
|
1691
|
+
* Quit: User initiated end of playback before media asset completion.
|
|
1692
|
+
*/
|
|
1521
1693
|
QUIT: "q",
|
|
1694
|
+
/**
|
|
1695
|
+
* Preloading: The player is loading assets ahead of starting to provide a fast startup. The expectation is that playback will commence at a future time.
|
|
1696
|
+
*/
|
|
1522
1697
|
PRELOADING: "d"
|
|
1523
1698
|
};
|
|
1524
|
-
|
|
1525
1699
|
//#endregion
|
|
1526
1700
|
//#region src/CmcdRecordedReportMode.ts
|
|
1527
1701
|
/**
|
|
@@ -1558,7 +1732,6 @@ const CmcdRecordedReportMode = {
|
|
|
1558
1732
|
HEADER: CMCD_RECORDED_REPORT_MODE_HEADER,
|
|
1559
1733
|
EVENT: CMCD_RECORDED_REPORT_MODE_EVENT
|
|
1560
1734
|
};
|
|
1561
|
-
|
|
1562
1735
|
//#endregion
|
|
1563
1736
|
//#region src/CmcdRecordedRequestType.ts
|
|
1564
1737
|
/**
|
|
@@ -1601,7 +1774,6 @@ const CmcdRecordedRequestType = {
|
|
|
1601
1774
|
EVENT: CMCD_RECORDED_REQUEST_TYPE_EVENT,
|
|
1602
1775
|
UNKNOWN: CMCD_RECORDED_REQUEST_TYPE_UNKNOWN
|
|
1603
1776
|
};
|
|
1604
|
-
|
|
1605
1777
|
//#endregion
|
|
1606
1778
|
//#region src/createFetchTransport.ts
|
|
1607
1779
|
async function toHttpRequest(request) {
|
|
@@ -1651,7 +1823,6 @@ function createFetchTransport() {
|
|
|
1651
1823
|
};
|
|
1652
1824
|
} };
|
|
1653
1825
|
}
|
|
1654
|
-
|
|
1655
1826
|
//#endregion
|
|
1656
1827
|
//#region src/createXhrTransport.ts
|
|
1657
1828
|
async function completeXhrWith(xhr, response) {
|
|
@@ -1741,7 +1912,6 @@ function createXhrTransport() {
|
|
|
1741
1912
|
};
|
|
1742
1913
|
} };
|
|
1743
1914
|
}
|
|
1744
|
-
|
|
1745
1915
|
//#endregion
|
|
1746
1916
|
//#region src/CmcdReportRecorder.ts
|
|
1747
1917
|
const MANIFEST_EXTENSIONS = /\.(m3u8|mpd)(\?|$|\/)/i;
|
|
@@ -1760,7 +1930,7 @@ function hasCmcdHeader(headers) {
|
|
|
1760
1930
|
function detectReportingMode(url, headers, isEventTarget) {
|
|
1761
1931
|
if (isEventTarget) return "event";
|
|
1762
1932
|
if (hasCmcdHeader(headers)) return "header";
|
|
1763
|
-
return url.includes(
|
|
1933
|
+
return url.includes(`CMCD=`) ? "query" : null;
|
|
1764
1934
|
}
|
|
1765
1935
|
/**
|
|
1766
1936
|
* Test helper that records CMCD reports from the XHR and fetch
|
|
@@ -1774,58 +1944,59 @@ function detectReportingMode(url, headers, isEventTarget) {
|
|
|
1774
1944
|
* @public
|
|
1775
1945
|
*/
|
|
1776
1946
|
var CmcdReportRecorder = class {
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1947
|
+
constructor() {
|
|
1948
|
+
this.reports = [];
|
|
1949
|
+
this.detachers = [];
|
|
1950
|
+
this.attached = false;
|
|
1951
|
+
this.eventTargetUrls = [];
|
|
1952
|
+
this.waiters = /* @__PURE__ */ new Map();
|
|
1953
|
+
this.waitTimeout = 15e3;
|
|
1954
|
+
this.deliver = (request) => {
|
|
1955
|
+
const url = request.url;
|
|
1956
|
+
const isEventTarget = (request.method ?? "GET").toUpperCase() === "POST" && this.eventTargetUrls.some((t) => url.startsWith(t));
|
|
1957
|
+
const reportingMode = detectReportingMode(url, request.headers, isEventTarget);
|
|
1958
|
+
if (reportingMode === null) return;
|
|
1959
|
+
const captured = {
|
|
1960
|
+
request,
|
|
1961
|
+
type: classifyUrl(url, isEventTarget),
|
|
1962
|
+
reportingMode,
|
|
1963
|
+
timestamp: Date.now()
|
|
1964
|
+
};
|
|
1965
|
+
this.reports.push(captured);
|
|
1966
|
+
if (this.onReport) try {
|
|
1967
|
+
this.onReport(captured);
|
|
1968
|
+
} catch (err) {
|
|
1969
|
+
console.error("CmcdReportRecorder onReport listener threw:", err);
|
|
1970
|
+
}
|
|
1971
|
+
this.notifyWaiters();
|
|
1972
|
+
return isEventTarget ? new Response(null, { status: 204 }) : void 0;
|
|
1794
1973
|
};
|
|
1795
|
-
this.#reports.push(captured);
|
|
1796
|
-
if (this.#onReport) try {
|
|
1797
|
-
this.#onReport(captured);
|
|
1798
|
-
} catch (err) {
|
|
1799
|
-
console.error("CmcdReportRecorder onReport listener threw:", err);
|
|
1800
|
-
}
|
|
1801
|
-
this.#notifyWaiters();
|
|
1802
|
-
return isEventTarget ? new Response(null, { status: 204 }) : void 0;
|
|
1803
|
-
};
|
|
1804
|
-
#getMatching(type) {
|
|
1805
|
-
return type === void 0 ? [...this.#reports] : this.#reports.filter((r) => r.type === type);
|
|
1806
1974
|
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1975
|
+
getMatching(type) {
|
|
1976
|
+
return type === void 0 ? [...this.reports] : this.reports.filter((r) => r.type === type);
|
|
1977
|
+
}
|
|
1978
|
+
notifyWaiters() {
|
|
1979
|
+
for (const [timer, waiter] of this.waiters) {
|
|
1980
|
+
const matching = this.getMatching(waiter.type);
|
|
1810
1981
|
if (matching.length >= waiter.count) {
|
|
1811
1982
|
clearTimeout(timer);
|
|
1812
|
-
this
|
|
1983
|
+
this.waiters.delete(timer);
|
|
1813
1984
|
waiter.resolve(matching);
|
|
1814
1985
|
}
|
|
1815
1986
|
}
|
|
1816
1987
|
}
|
|
1817
|
-
|
|
1988
|
+
waitFor(type, options) {
|
|
1818
1989
|
const count = options.count ?? 1;
|
|
1819
|
-
const timeout = options.timeout ?? this
|
|
1820
|
-
const matching = this
|
|
1990
|
+
const timeout = options.timeout ?? this.waitTimeout;
|
|
1991
|
+
const matching = this.getMatching(type);
|
|
1821
1992
|
if (matching.length >= count) return Promise.resolve(matching);
|
|
1822
1993
|
return new Promise((resolve, reject) => {
|
|
1823
1994
|
const timer = setTimeout(() => {
|
|
1824
|
-
this
|
|
1825
|
-
const current = this
|
|
1826
|
-
reject(/* @__PURE__ */ new Error(`Timeout waiting for ${count} ${type ?? "any"} CMCD report(s). Got ${current.length}. Total recorded: ${this
|
|
1995
|
+
this.waiters.delete(timer);
|
|
1996
|
+
const current = this.getMatching(type);
|
|
1997
|
+
reject(/* @__PURE__ */ new Error(`Timeout waiting for ${count} ${type ?? "any"} CMCD report(s). Got ${current.length}. Total recorded: ${this.reports.length}.`));
|
|
1827
1998
|
}, timeout);
|
|
1828
|
-
this
|
|
1999
|
+
this.waiters.set(timer, {
|
|
1829
2000
|
type,
|
|
1830
2001
|
count,
|
|
1831
2002
|
resolve,
|
|
@@ -1843,13 +2014,13 @@ var CmcdReportRecorder = class {
|
|
|
1843
2014
|
* @public
|
|
1844
2015
|
*/
|
|
1845
2016
|
attach(options = {}) {
|
|
1846
|
-
if (this
|
|
1847
|
-
this
|
|
1848
|
-
this
|
|
1849
|
-
this
|
|
1850
|
-
this
|
|
2017
|
+
if (this.attached) return;
|
|
2018
|
+
this.attached = true;
|
|
2019
|
+
this.eventTargetUrls = options.eventTargetUrls ?? [];
|
|
2020
|
+
this.onReport = options.onReport;
|
|
2021
|
+
this.waitTimeout = options.waitTimeout ?? 15e3;
|
|
1851
2022
|
const transports = options.transports ?? [createXhrTransport(), createFetchTransport()];
|
|
1852
|
-
for (const transport of transports) this
|
|
2023
|
+
for (const transport of transports) this.detachers.push(transport.attach(this.deliver));
|
|
1853
2024
|
}
|
|
1854
2025
|
/**
|
|
1855
2026
|
* Remove transport patches and stop recording. Rejects any pending
|
|
@@ -1858,17 +2029,17 @@ var CmcdReportRecorder = class {
|
|
|
1858
2029
|
* @public
|
|
1859
2030
|
*/
|
|
1860
2031
|
detach() {
|
|
1861
|
-
if (!this
|
|
1862
|
-
for (const detacher of this
|
|
1863
|
-
this
|
|
1864
|
-
this
|
|
1865
|
-
this
|
|
1866
|
-
this
|
|
1867
|
-
for (const [timer, waiter] of this
|
|
2032
|
+
if (!this.attached) return;
|
|
2033
|
+
for (const detacher of this.detachers) detacher();
|
|
2034
|
+
this.detachers = [];
|
|
2035
|
+
this.attached = false;
|
|
2036
|
+
this.eventTargetUrls = [];
|
|
2037
|
+
this.onReport = void 0;
|
|
2038
|
+
for (const [timer, waiter] of this.waiters) {
|
|
1868
2039
|
clearTimeout(timer);
|
|
1869
2040
|
waiter.reject(/* @__PURE__ */ new Error("Recorder detached while waiting"));
|
|
1870
2041
|
}
|
|
1871
|
-
this
|
|
2042
|
+
this.waiters.clear();
|
|
1872
2043
|
}
|
|
1873
2044
|
/**
|
|
1874
2045
|
* Discard all recorded reports. Does not affect the attached state.
|
|
@@ -1876,7 +2047,7 @@ var CmcdReportRecorder = class {
|
|
|
1876
2047
|
* @public
|
|
1877
2048
|
*/
|
|
1878
2049
|
clear() {
|
|
1879
|
-
this
|
|
2050
|
+
this.reports = [];
|
|
1880
2051
|
}
|
|
1881
2052
|
/**
|
|
1882
2053
|
* Return a copy of all recorded reports.
|
|
@@ -1884,7 +2055,7 @@ var CmcdReportRecorder = class {
|
|
|
1884
2055
|
* @public
|
|
1885
2056
|
*/
|
|
1886
2057
|
getReports() {
|
|
1887
|
-
return [...this
|
|
2058
|
+
return [...this.reports];
|
|
1888
2059
|
}
|
|
1889
2060
|
/**
|
|
1890
2061
|
* Wait until at least `count` reports of any type are recorded.
|
|
@@ -1895,7 +2066,7 @@ var CmcdReportRecorder = class {
|
|
|
1895
2066
|
* @public
|
|
1896
2067
|
*/
|
|
1897
2068
|
waitForReports(options = {}) {
|
|
1898
|
-
return this
|
|
2069
|
+
return this.waitFor(void 0, options);
|
|
1899
2070
|
}
|
|
1900
2071
|
/**
|
|
1901
2072
|
* Wait until at least `count` manifest reports are recorded.
|
|
@@ -1906,7 +2077,7 @@ var CmcdReportRecorder = class {
|
|
|
1906
2077
|
* @public
|
|
1907
2078
|
*/
|
|
1908
2079
|
waitForManifest(options = {}) {
|
|
1909
|
-
return this
|
|
2080
|
+
return this.waitFor(CmcdRecordedRequestType.MANIFEST, options);
|
|
1910
2081
|
}
|
|
1911
2082
|
/**
|
|
1912
2083
|
* Wait until at least `count` segment reports are recorded.
|
|
@@ -1917,7 +2088,7 @@ var CmcdReportRecorder = class {
|
|
|
1917
2088
|
* @public
|
|
1918
2089
|
*/
|
|
1919
2090
|
waitForSegments(options = {}) {
|
|
1920
|
-
return this
|
|
2091
|
+
return this.waitFor(CmcdRecordedRequestType.SEGMENT, options);
|
|
1921
2092
|
}
|
|
1922
2093
|
/**
|
|
1923
2094
|
* Wait until at least `count` event-mode reports are recorded.
|
|
@@ -1928,10 +2099,9 @@ var CmcdReportRecorder = class {
|
|
|
1928
2099
|
* @public
|
|
1929
2100
|
*/
|
|
1930
2101
|
waitForEvents(options = {}) {
|
|
1931
|
-
return this
|
|
2102
|
+
return this.waitFor(CmcdRecordedRequestType.EVENT, options);
|
|
1932
2103
|
}
|
|
1933
2104
|
};
|
|
1934
|
-
|
|
1935
2105
|
//#endregion
|
|
1936
2106
|
//#region src/CMCD_STATE_EVENT_FIELDS.ts
|
|
1937
2107
|
/**
|
|
@@ -1958,13 +2128,12 @@ var CmcdReportRecorder = class {
|
|
|
1958
2128
|
* @internal
|
|
1959
2129
|
*/
|
|
1960
2130
|
const CMCD_STATE_EVENT_FIELDS = /* @__PURE__ */ new Map([
|
|
1961
|
-
[
|
|
1962
|
-
[
|
|
1963
|
-
[
|
|
1964
|
-
[
|
|
1965
|
-
[
|
|
2131
|
+
["ps", "sta"],
|
|
2132
|
+
["pr", "pr"],
|
|
2133
|
+
["c", "cid"],
|
|
2134
|
+
["b", "bg"],
|
|
2135
|
+
["bc", "br"]
|
|
1966
2136
|
]);
|
|
1967
|
-
|
|
1968
2137
|
//#endregion
|
|
1969
2138
|
//#region src/CmcdTransmissionMode.ts
|
|
1970
2139
|
/**
|
|
@@ -1995,11 +2164,21 @@ const CMCD_JSON = "json";
|
|
|
1995
2164
|
* @public
|
|
1996
2165
|
*/
|
|
1997
2166
|
const CmcdTransmissionMode = {
|
|
2167
|
+
/**
|
|
2168
|
+
* JSON
|
|
2169
|
+
*
|
|
2170
|
+
* @deprecated JSON transmission mode is deprecated and will be removed in future versions.
|
|
2171
|
+
*/
|
|
1998
2172
|
JSON: CMCD_JSON,
|
|
2173
|
+
/**
|
|
2174
|
+
* Query string
|
|
2175
|
+
*/
|
|
1999
2176
|
QUERY: CMCD_QUERY,
|
|
2177
|
+
/**
|
|
2178
|
+
* Request headers
|
|
2179
|
+
*/
|
|
2000
2180
|
HEADERS: CMCD_HEADERS
|
|
2001
2181
|
};
|
|
2002
|
-
|
|
2003
2182
|
//#endregion
|
|
2004
2183
|
//#region src/upConvertToV2.ts
|
|
2005
2184
|
/**
|
|
@@ -2015,7 +2194,7 @@ const CmcdTransmissionMode = {
|
|
|
2015
2194
|
* @internal
|
|
2016
2195
|
*/
|
|
2017
2196
|
function upConvertToV2(obj) {
|
|
2018
|
-
if (toBareValue(obj["v"]) ===
|
|
2197
|
+
if (toBareValue(obj["v"]) === 2) return obj;
|
|
2019
2198
|
const result = {};
|
|
2020
2199
|
for (const [key, value] of Object.entries(obj)) {
|
|
2021
2200
|
if (value == null) {
|
|
@@ -2028,7 +2207,6 @@ function upConvertToV2(obj) {
|
|
|
2028
2207
|
}
|
|
2029
2208
|
return result;
|
|
2030
2209
|
}
|
|
2031
|
-
|
|
2032
2210
|
//#endregion
|
|
2033
2211
|
//#region src/decodeCmcd.ts
|
|
2034
2212
|
function reduceValue(value, useSymbol) {
|
|
@@ -2045,13 +2223,12 @@ function decodeCmcd(cmcd, options) {
|
|
|
2045
2223
|
if (options?.convertToLatest) return upConvertToV2(result);
|
|
2046
2224
|
return result;
|
|
2047
2225
|
}
|
|
2048
|
-
|
|
2049
2226
|
//#endregion
|
|
2050
2227
|
//#region src/CmcdReporter.ts
|
|
2051
2228
|
function createEncodingOptions(reportingMode, config, baseUrl) {
|
|
2052
2229
|
const enabledKeySet = new Set(config.enabledKeys ?? []);
|
|
2053
2230
|
return {
|
|
2054
|
-
version: config.version ||
|
|
2231
|
+
version: config.version || 2,
|
|
2055
2232
|
reportingMode,
|
|
2056
2233
|
filter: (key) => enabledKeySet.has(key),
|
|
2057
2234
|
baseUrl,
|
|
@@ -2118,9 +2295,9 @@ const STATE_FIELDS_BY_EVENT = /* @__PURE__ */ new Map(/* @__PURE__ */ STATE_FIEL
|
|
|
2118
2295
|
function buildRequiredEventKeys() {
|
|
2119
2296
|
return new Map([
|
|
2120
2297
|
...CMCD_STATE_EVENT_FIELDS,
|
|
2121
|
-
[
|
|
2122
|
-
[
|
|
2123
|
-
[
|
|
2298
|
+
["ce", "cen"],
|
|
2299
|
+
["e", "ec"],
|
|
2300
|
+
["rr", "url"]
|
|
2124
2301
|
]);
|
|
2125
2302
|
}
|
|
2126
2303
|
/**
|
|
@@ -2201,11 +2378,11 @@ function mintProvenance(sid, cid) {
|
|
|
2201
2378
|
} : { sid });
|
|
2202
2379
|
}
|
|
2203
2380
|
function defaultRequester(request) {
|
|
2204
|
-
const { url
|
|
2381
|
+
const { url, ...init } = request;
|
|
2205
2382
|
return fetch(url, init);
|
|
2206
2383
|
}
|
|
2207
2384
|
function createCmcdReporterConfig(config) {
|
|
2208
|
-
const { version =
|
|
2385
|
+
const { version = 2, eventTargets = [], sid = uuid(), transmissionMode = CMCD_QUERY, ...rest } = config;
|
|
2209
2386
|
const retention = config.sessionRetention;
|
|
2210
2387
|
const sessionRetention = typeof retention === "number" ? Math.floor(retention) : NaN;
|
|
2211
2388
|
return {
|
|
@@ -2216,11 +2393,11 @@ function createCmcdReporterConfig(config) {
|
|
|
2216
2393
|
sessionRetention: sessionRetention >= 0 ? sessionRetention : 2,
|
|
2217
2394
|
eventTargets: eventTargets.reduce((acc, target) => {
|
|
2218
2395
|
if (target?.url && target.events?.length) acc.push({
|
|
2219
|
-
version: target.version ||
|
|
2396
|
+
version: target.version || 2,
|
|
2220
2397
|
enabledKeys: target.enabledKeys?.slice() || [],
|
|
2221
2398
|
url: target.url,
|
|
2222
2399
|
events: target.events.slice(),
|
|
2223
|
-
interval: target.interval ??
|
|
2400
|
+
interval: target.interval ?? 30,
|
|
2224
2401
|
batchSize: target.batchSize || 1,
|
|
2225
2402
|
transform: target.transform
|
|
2226
2403
|
});
|
|
@@ -2306,7 +2483,7 @@ var CmcdReporter = class {
|
|
|
2306
2483
|
this.disarmInterval(config);
|
|
2307
2484
|
if (target.disposed || !this.armInterval(config)) return;
|
|
2308
2485
|
try {
|
|
2309
|
-
this.recordTargetEvent(session, target, config,
|
|
2486
|
+
this.recordTargetEvent(session, target, config, "t");
|
|
2310
2487
|
this.processEventTargets();
|
|
2311
2488
|
} catch (error) {
|
|
2312
2489
|
failure ??= { error };
|
|
@@ -2320,12 +2497,12 @@ var CmcdReporter = class {
|
|
|
2320
2497
|
* whichever session is current when the timer fires.
|
|
2321
2498
|
*/
|
|
2322
2499
|
armInterval(config) {
|
|
2323
|
-
if (config.interval === 0 || !config.events.includes(
|
|
2500
|
+
if (config.interval === 0 || !config.events.includes("t")) return false;
|
|
2324
2501
|
this.intervals.set(config, setInterval(() => {
|
|
2325
2502
|
const session = this.session;
|
|
2326
2503
|
const target = session.eventTargets.get(config);
|
|
2327
2504
|
if (target) {
|
|
2328
|
-
this.recordTargetEvent(session, target, config,
|
|
2505
|
+
this.recordTargetEvent(session, target, config, "t");
|
|
2329
2506
|
this.processEventTargets();
|
|
2330
2507
|
}
|
|
2331
2508
|
}, config.interval * 1e3));
|
|
@@ -2539,7 +2716,7 @@ var CmcdReporter = class {
|
|
|
2539
2716
|
e: type,
|
|
2540
2717
|
ts: data.ts ?? Date.now()
|
|
2541
2718
|
};
|
|
2542
|
-
if (type ===
|
|
2719
|
+
if (type === "b" && toBareValue(item.bg) === false) delete item.bg;
|
|
2543
2720
|
const { transform } = config;
|
|
2544
2721
|
if (!transform) {
|
|
2545
2722
|
this.queueTargetEvent(session, target, config, item, type);
|
|
@@ -2655,7 +2832,7 @@ var CmcdReporter = class {
|
|
|
2655
2832
|
}
|
|
2656
2833
|
if (timing.duration != null) derived.ttlb = Math.round(timing.duration);
|
|
2657
2834
|
}
|
|
2658
|
-
this.emitEvent(session,
|
|
2835
|
+
this.emitEvent(session, "rr", {
|
|
2659
2836
|
...typeof cid === "string" && cid ? { cid } : void 0,
|
|
2660
2837
|
...cmcd,
|
|
2661
2838
|
...derived,
|
|
@@ -2742,7 +2919,7 @@ var CmcdReporter = class {
|
|
|
2742
2919
|
* @returns The request with the CMCD request report applied.
|
|
2743
2920
|
*/
|
|
2744
2921
|
createRequestReport(request, data) {
|
|
2745
|
-
const { customData = {}, headers = {}
|
|
2922
|
+
const { customData = {}, headers = {}, ...rest } = request;
|
|
2746
2923
|
const report = {
|
|
2747
2924
|
...rest,
|
|
2748
2925
|
headers: { ...headers },
|
|
@@ -2779,9 +2956,7 @@ var CmcdReporter = class {
|
|
|
2779
2956
|
case CMCD_QUERY:
|
|
2780
2957
|
if (encoded) report.url = replaceCmcdParam(report.url, encoded);
|
|
2781
2958
|
break;
|
|
2782
|
-
case CMCD_HEADERS:
|
|
2783
|
-
Object.assign(report.headers, toPreparedCmcdHeaders(cmcd, options.customHeaderMap));
|
|
2784
|
-
break;
|
|
2959
|
+
case CMCD_HEADERS: Object.assign(report.headers, toPreparedCmcdHeaders(cmcd, options.customHeaderMap));
|
|
2785
2960
|
}
|
|
2786
2961
|
return report;
|
|
2787
2962
|
}
|
|
@@ -2852,7 +3027,6 @@ var CmcdReporter = class {
|
|
|
2852
3027
|
});
|
|
2853
3028
|
}
|
|
2854
3029
|
};
|
|
2855
|
-
|
|
2856
3030
|
//#endregion
|
|
2857
3031
|
//#region src/CmcdStreamingFormat.ts
|
|
2858
3032
|
/**
|
|
@@ -2865,12 +3039,23 @@ var CmcdReporter = class {
|
|
|
2865
3039
|
* @public
|
|
2866
3040
|
*/
|
|
2867
3041
|
const CmcdStreamingFormat = {
|
|
3042
|
+
/**
|
|
3043
|
+
* MPEG DASH
|
|
3044
|
+
*/
|
|
2868
3045
|
DASH: "d",
|
|
3046
|
+
/**
|
|
3047
|
+
* HTTP Live Streaming (HLS)
|
|
3048
|
+
*/
|
|
2869
3049
|
HLS: "h",
|
|
3050
|
+
/**
|
|
3051
|
+
* Smooth Streaming
|
|
3052
|
+
*/
|
|
2870
3053
|
SMOOTH: "s",
|
|
3054
|
+
/**
|
|
3055
|
+
* Other
|
|
3056
|
+
*/
|
|
2871
3057
|
OTHER: "o"
|
|
2872
3058
|
};
|
|
2873
|
-
|
|
2874
3059
|
//#endregion
|
|
2875
3060
|
//#region src/CmcdStreamType.ts
|
|
2876
3061
|
/**
|
|
@@ -2883,11 +3068,19 @@ const CmcdStreamingFormat = {
|
|
|
2883
3068
|
* @public
|
|
2884
3069
|
*/
|
|
2885
3070
|
const CmcdStreamType = {
|
|
3071
|
+
/**
|
|
3072
|
+
* All segments are available, for example VOD
|
|
3073
|
+
*/
|
|
2886
3074
|
VOD: "v",
|
|
3075
|
+
/**
|
|
3076
|
+
* Segments become available over time, for example LIVE
|
|
3077
|
+
*/
|
|
2887
3078
|
LIVE: "l",
|
|
3079
|
+
/**
|
|
3080
|
+
* Low latency stream
|
|
3081
|
+
*/
|
|
2888
3082
|
LOW_LATENCY: "ll"
|
|
2889
3083
|
};
|
|
2890
|
-
|
|
2891
3084
|
//#endregion
|
|
2892
3085
|
//#region src/CmcdValidationSeverity.ts
|
|
2893
3086
|
/**
|
|
@@ -2911,7 +3104,6 @@ const CmcdValidationSeverity = {
|
|
|
2911
3104
|
ERROR: CMCD_VALIDATION_SEVERITY_ERROR,
|
|
2912
3105
|
WARNING: CMCD_VALIDATION_SEVERITY_WARNING
|
|
2913
3106
|
};
|
|
2914
|
-
|
|
2915
3107
|
//#endregion
|
|
2916
3108
|
//#region src/ensureHeaders.ts
|
|
2917
3109
|
/**
|
|
@@ -2925,7 +3117,6 @@ const CmcdValidationSeverity = {
|
|
|
2925
3117
|
function ensureHeaders(headers) {
|
|
2926
3118
|
return headers instanceof Headers ? headers : new Headers(headers);
|
|
2927
3119
|
}
|
|
2928
|
-
|
|
2929
3120
|
//#endregion
|
|
2930
3121
|
//#region src/fromCmcdHeaders.ts
|
|
2931
3122
|
function fromCmcdHeaders(headers, options) {
|
|
@@ -2938,20 +3129,17 @@ function fromCmcdHeaders(headers, options) {
|
|
|
2938
3129
|
if (options?.convertToLatest) return upConvertToV2(result);
|
|
2939
3130
|
return result;
|
|
2940
3131
|
}
|
|
2941
|
-
|
|
2942
3132
|
//#endregion
|
|
2943
3133
|
//#region src/fromCmcdQuery.ts
|
|
2944
3134
|
function fromCmcdQuery(query, options) {
|
|
2945
3135
|
if (typeof query === "string") query = new URLSearchParams(query);
|
|
2946
3136
|
return decodeCmcd(query.get(CMCD_PARAM) ?? "", options);
|
|
2947
3137
|
}
|
|
2948
|
-
|
|
2949
3138
|
//#endregion
|
|
2950
3139
|
//#region src/fromCmcdUrl.ts
|
|
2951
3140
|
function fromCmcdUrl(url, options) {
|
|
2952
3141
|
return decodeCmcd(decodeURIComponent(url.replace(/^CMCD=/, "").replace(/\+/g, " ")), options);
|
|
2953
3142
|
}
|
|
2954
|
-
|
|
2955
3143
|
//#endregion
|
|
2956
3144
|
//#region src/isCmcdRequestKey.ts
|
|
2957
3145
|
const CMCD_REQUEST_KEY_SET = /* @__PURE__ */ new Set(CMCD_REQUEST_KEYS);
|
|
@@ -2970,7 +3158,6 @@ const CMCD_REQUEST_KEY_SET = /* @__PURE__ */ new Set(CMCD_REQUEST_KEYS);
|
|
|
2970
3158
|
function isCmcdRequestKey(key) {
|
|
2971
3159
|
return CMCD_REQUEST_KEY_SET.has(key) || isCmcdCustomKey(key);
|
|
2972
3160
|
}
|
|
2973
|
-
|
|
2974
3161
|
//#endregion
|
|
2975
3162
|
//#region src/isCmcdResponseReceivedKey.ts
|
|
2976
3163
|
const CMCD_RESPONSE_KEY_SET = /* @__PURE__ */ new Set(CMCD_RESPONSE_KEYS);
|
|
@@ -2989,7 +3176,6 @@ const CMCD_RESPONSE_KEY_SET = /* @__PURE__ */ new Set(CMCD_RESPONSE_KEYS);
|
|
|
2989
3176
|
function isCmcdResponseReceivedKey(key) {
|
|
2990
3177
|
return CMCD_RESPONSE_KEY_SET.has(key);
|
|
2991
3178
|
}
|
|
2992
|
-
|
|
2993
3179
|
//#endregion
|
|
2994
3180
|
//#region src/isCmcdEventKey.ts
|
|
2995
3181
|
const CMCD_EVENT_KEY_SET = /* @__PURE__ */ new Set(CMCD_EVENT_KEYS);
|
|
@@ -3008,7 +3194,6 @@ const CMCD_EVENT_KEY_SET = /* @__PURE__ */ new Set(CMCD_EVENT_KEYS);
|
|
|
3008
3194
|
function isCmcdEventKey(key) {
|
|
3009
3195
|
return isCmcdRequestKey(key) || isCmcdResponseReceivedKey(key) || CMCD_EVENT_KEY_SET.has(key);
|
|
3010
3196
|
}
|
|
3011
|
-
|
|
3012
3197
|
//#endregion
|
|
3013
3198
|
//#region src/isCmcdV1Data.ts
|
|
3014
3199
|
/**
|
|
@@ -3024,9 +3209,8 @@ function isCmcdEventKey(key) {
|
|
|
3024
3209
|
* {@includeCode ../test/isCmcdV1Data.test.ts#example}
|
|
3025
3210
|
*/
|
|
3026
3211
|
function isCmcdV1Data(data) {
|
|
3027
|
-
return data.v !==
|
|
3212
|
+
return data.v !== 2;
|
|
3028
3213
|
}
|
|
3029
|
-
|
|
3030
3214
|
//#endregion
|
|
3031
3215
|
//#region src/isCmcdV1Key.ts
|
|
3032
3216
|
const CMCD_V1_KEY_SET$1 = /* @__PURE__ */ new Set(CMCD_V1_KEYS);
|
|
@@ -3045,7 +3229,6 @@ const CMCD_V1_KEY_SET$1 = /* @__PURE__ */ new Set(CMCD_V1_KEYS);
|
|
|
3045
3229
|
function isCmcdV1Key(key) {
|
|
3046
3230
|
return CMCD_V1_KEY_SET$1.has(key) || isCmcdCustomKey(key);
|
|
3047
3231
|
}
|
|
3048
|
-
|
|
3049
3232
|
//#endregion
|
|
3050
3233
|
//#region src/isCmcdV2Data.ts
|
|
3051
3234
|
/**
|
|
@@ -3061,9 +3244,8 @@ function isCmcdV1Key(key) {
|
|
|
3061
3244
|
* {@includeCode ../test/isCmcdV2Data.test.ts#example}
|
|
3062
3245
|
*/
|
|
3063
3246
|
function isCmcdV2Data(data) {
|
|
3064
|
-
return data.v ===
|
|
3247
|
+
return data.v === 2;
|
|
3065
3248
|
}
|
|
3066
|
-
|
|
3067
3249
|
//#endregion
|
|
3068
3250
|
//#region src/toCmcdUrl.ts
|
|
3069
3251
|
/**
|
|
@@ -3085,7 +3267,6 @@ function toCmcdUrl(cmcd, options = {}) {
|
|
|
3085
3267
|
if (!cmcd) return "";
|
|
3086
3268
|
return percentEncode(encodeCmcd(cmcd, options));
|
|
3087
3269
|
}
|
|
3088
|
-
|
|
3089
3270
|
//#endregion
|
|
3090
3271
|
//#region src/toCmcdQuery.ts
|
|
3091
3272
|
/**
|
|
@@ -3105,9 +3286,9 @@ function toCmcdUrl(cmcd, options = {}) {
|
|
|
3105
3286
|
*/
|
|
3106
3287
|
function toCmcdQuery(cmcd, options = {}) {
|
|
3107
3288
|
if (!cmcd) return "";
|
|
3108
|
-
|
|
3289
|
+
const value = toCmcdUrl(cmcd, options);
|
|
3290
|
+
return `${CMCD_PARAM}=${value}`;
|
|
3109
3291
|
}
|
|
3110
|
-
|
|
3111
3292
|
//#endregion
|
|
3112
3293
|
//#region src/toCmcdValue.ts
|
|
3113
3294
|
/**
|
|
@@ -3122,7 +3303,6 @@ function toCmcdQuery(cmcd, options = {}) {
|
|
|
3122
3303
|
function toCmcdValue(value, params) {
|
|
3123
3304
|
return new SfItem(value, params);
|
|
3124
3305
|
}
|
|
3125
|
-
|
|
3126
3306
|
//#endregion
|
|
3127
3307
|
//#region src/mergeValidationResults.ts
|
|
3128
3308
|
/**
|
|
@@ -3137,7 +3317,6 @@ function mergeValidationResults(...results) {
|
|
|
3137
3317
|
issues
|
|
3138
3318
|
};
|
|
3139
3319
|
}
|
|
3140
|
-
|
|
3141
3320
|
//#endregion
|
|
3142
3321
|
//#region src/resolveVersion.ts
|
|
3143
3322
|
/**
|
|
@@ -3149,9 +3328,8 @@ function resolveVersion(data, options) {
|
|
|
3149
3328
|
if (options?.version === 1 || options?.version === 2) return options.version;
|
|
3150
3329
|
const payloadVersion = toBareValue(data["v"]);
|
|
3151
3330
|
if (payloadVersion === 1 || payloadVersion === 2) return payloadVersion;
|
|
3152
|
-
return
|
|
3331
|
+
return 1;
|
|
3153
3332
|
}
|
|
3154
|
-
|
|
3155
3333
|
//#endregion
|
|
3156
3334
|
//#region src/validateCmcdKeys.ts
|
|
3157
3335
|
const CMCD_V1_KEY_SET = /* @__PURE__ */ new Set(CMCD_V1_KEYS);
|
|
@@ -3172,7 +3350,7 @@ const CMCD_KEY_SET = /* @__PURE__ */ new Set(CMCD_KEYS);
|
|
|
3172
3350
|
*/
|
|
3173
3351
|
function validateCmcdKeys(data, options) {
|
|
3174
3352
|
const version = resolveVersion(data, options);
|
|
3175
|
-
const validKeySet = version ===
|
|
3353
|
+
const validKeySet = version === 1 ? CMCD_V1_KEY_SET : CMCD_KEY_SET;
|
|
3176
3354
|
const issues = [];
|
|
3177
3355
|
for (const key of Object.keys(data)) {
|
|
3178
3356
|
if (isCmcdCustomKey(key)) continue;
|
|
@@ -3187,7 +3365,6 @@ function validateCmcdKeys(data, options) {
|
|
|
3187
3365
|
issues
|
|
3188
3366
|
};
|
|
3189
3367
|
}
|
|
3190
|
-
|
|
3191
3368
|
//#endregion
|
|
3192
3369
|
//#region src/CMCD_AGGREGATE_BITRATE_KEYS.ts
|
|
3193
3370
|
/**
|
|
@@ -3204,7 +3381,6 @@ const CMCD_AGGREGATE_BITRATE_KEYS = {
|
|
|
3204
3381
|
lab: "lb",
|
|
3205
3382
|
tab: "tb"
|
|
3206
3383
|
};
|
|
3207
|
-
|
|
3208
3384
|
//#endregion
|
|
3209
3385
|
//#region src/CMCD_KEY_OBJECT_TYPES.ts
|
|
3210
3386
|
/**
|
|
@@ -3232,7 +3408,6 @@ const CMCD_KEY_OBJECT_TYPES = {
|
|
|
3232
3408
|
"c"
|
|
3233
3409
|
]
|
|
3234
3410
|
};
|
|
3235
|
-
|
|
3236
3411
|
//#endregion
|
|
3237
3412
|
//#region src/validateCmcdStructure.ts
|
|
3238
3413
|
/**
|
|
@@ -3252,7 +3427,7 @@ const CMCD_KEY_OBJECT_TYPES = {
|
|
|
3252
3427
|
function validateCmcdStructure(data, options) {
|
|
3253
3428
|
const version = resolveVersion(data, options);
|
|
3254
3429
|
const issues = [];
|
|
3255
|
-
if (options?.reportingMode ===
|
|
3430
|
+
if (options?.reportingMode === "request") {
|
|
3256
3431
|
for (const key of CMCD_EVENT_KEYS) if (key in data) issues.push({
|
|
3257
3432
|
key,
|
|
3258
3433
|
message: `Event key "${key}" must not be present in request mode.`,
|
|
@@ -3264,7 +3439,7 @@ function validateCmcdStructure(data, options) {
|
|
|
3264
3439
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3265
3440
|
});
|
|
3266
3441
|
}
|
|
3267
|
-
if (options?.reportingMode ===
|
|
3442
|
+
if (options?.reportingMode === "event") {
|
|
3268
3443
|
if (!("e" in data)) issues.push({
|
|
3269
3444
|
key: "e",
|
|
3270
3445
|
message: "Event mode requires the \"e\" key to be present.",
|
|
@@ -3278,7 +3453,7 @@ function validateCmcdStructure(data, options) {
|
|
|
3278
3453
|
}
|
|
3279
3454
|
if ("e" in data) {
|
|
3280
3455
|
const eventType = toTokenString(data["e"]);
|
|
3281
|
-
if (eventType ===
|
|
3456
|
+
if (eventType === "ce") {
|
|
3282
3457
|
if (!("cen" in data)) issues.push({
|
|
3283
3458
|
key: "cen",
|
|
3284
3459
|
message: "Custom event (e=\"ce\") requires the \"cen\" key to be present.",
|
|
@@ -3289,7 +3464,7 @@ function validateCmcdStructure(data, options) {
|
|
|
3289
3464
|
message: "The \"cen\" key must only be present when e=\"ce\".",
|
|
3290
3465
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3291
3466
|
});
|
|
3292
|
-
if (eventType ===
|
|
3467
|
+
if (eventType === "rr") {
|
|
3293
3468
|
if (!("url" in data)) issues.push({
|
|
3294
3469
|
key: "url",
|
|
3295
3470
|
message: "Response received event (e=\"rr\") requires the \"url\" key to be present.",
|
|
@@ -3300,12 +3475,12 @@ function validateCmcdStructure(data, options) {
|
|
|
3300
3475
|
message: `Response key "${key}" must only be present when e="rr".`,
|
|
3301
3476
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3302
3477
|
});
|
|
3303
|
-
if (eventType ===
|
|
3478
|
+
if (eventType === "ps" && !("sta" in data)) issues.push({
|
|
3304
3479
|
key: "sta",
|
|
3305
3480
|
message: "Play state change event (e=\"ps\") requires the \"sta\" key to be present.",
|
|
3306
3481
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3307
3482
|
});
|
|
3308
|
-
if (eventType ===
|
|
3483
|
+
if (eventType === "e" && !("ec" in data)) issues.push({
|
|
3309
3484
|
key: "ec",
|
|
3310
3485
|
message: "Error event (e=\"e\") requires the \"ec\" key to be present.",
|
|
3311
3486
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
@@ -3339,7 +3514,7 @@ function validateCmcdStructure(data, options) {
|
|
|
3339
3514
|
message: "Version 2 payloads require the \"v\" key to be present.",
|
|
3340
3515
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3341
3516
|
});
|
|
3342
|
-
else if (version ===
|
|
3517
|
+
else if (version === 1 && "v" in data) issues.push({
|
|
3343
3518
|
key: "v",
|
|
3344
3519
|
message: "Version 1 payloads should omit the \"v\" key (v1 is the default).",
|
|
3345
3520
|
severity: CMCD_VALIDATION_SEVERITY_WARNING
|
|
@@ -3349,7 +3524,6 @@ function validateCmcdStructure(data, options) {
|
|
|
3349
3524
|
issues
|
|
3350
3525
|
};
|
|
3351
3526
|
}
|
|
3352
|
-
|
|
3353
3527
|
//#endregion
|
|
3354
3528
|
//#region src/CMCD_KEY_TYPES.ts
|
|
3355
3529
|
/**
|
|
@@ -3465,7 +3639,6 @@ const CMCD_V1_KEY_TYPE_OVERRIDES = {
|
|
|
3465
3639
|
tb: CMCD_KEY_TYPE_INTEGER,
|
|
3466
3640
|
nor: CMCD_KEY_TYPE_STRING
|
|
3467
3641
|
};
|
|
3468
|
-
|
|
3469
3642
|
//#endregion
|
|
3470
3643
|
//#region src/CMCD_STRING_LENGTH_LIMITS.ts
|
|
3471
3644
|
/**
|
|
@@ -3480,13 +3653,6 @@ const CMCD_STRING_LENGTH_LIMITS = {
|
|
|
3480
3653
|
h: 128,
|
|
3481
3654
|
cen: 64
|
|
3482
3655
|
};
|
|
3483
|
-
/**
|
|
3484
|
-
* Maximum length for custom key values.
|
|
3485
|
-
*
|
|
3486
|
-
* @internal
|
|
3487
|
-
*/
|
|
3488
|
-
const CMCD_CUSTOM_KEY_VALUE_MAX_LENGTH = 64;
|
|
3489
|
-
|
|
3490
3656
|
//#endregion
|
|
3491
3657
|
//#region src/CMCD_TOKEN_VALUES.ts
|
|
3492
3658
|
/**
|
|
@@ -3550,7 +3716,6 @@ const CMCD_TOKEN_VALUES = {
|
|
|
3550
3716
|
"d"
|
|
3551
3717
|
]
|
|
3552
3718
|
};
|
|
3553
|
-
|
|
3554
3719
|
//#endregion
|
|
3555
3720
|
//#region src/validateCmcdValues.ts
|
|
3556
3721
|
const HUNDRED_ROUNDING_UNITS = {
|
|
@@ -3569,7 +3734,7 @@ function isInteger(value) {
|
|
|
3569
3734
|
function validateRounding(key, value, version, issues, index) {
|
|
3570
3735
|
const unit = HUNDRED_ROUNDING_UNITS[key];
|
|
3571
3736
|
if (!unit || value % 100 === 0) return;
|
|
3572
|
-
const should = key === "tbl" || key === "bl" && version !==
|
|
3737
|
+
const should = key === "tbl" || key === "bl" && version !== 1;
|
|
3573
3738
|
const target = index === void 0 ? `Key "${key}"` : `Key "${key}" array element [${index}]`;
|
|
3574
3739
|
issues.push({
|
|
3575
3740
|
key,
|
|
@@ -3636,9 +3801,9 @@ function validateCmcdValues(data, options) {
|
|
|
3636
3801
|
message: `Custom key "${key}" value must be a string or token.`,
|
|
3637
3802
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3638
3803
|
});
|
|
3639
|
-
else if (value.length >
|
|
3804
|
+
else if (value.length > 64) issues.push({
|
|
3640
3805
|
key,
|
|
3641
|
-
message: `Custom key "${key}" value exceeds maximum length of
|
|
3806
|
+
message: `Custom key "${key}" value exceeds maximum length of 64.`,
|
|
3642
3807
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3643
3808
|
});
|
|
3644
3809
|
continue;
|
|
@@ -3653,7 +3818,7 @@ function validateCmcdValues(data, options) {
|
|
|
3653
3818
|
}
|
|
3654
3819
|
let expectedType = CMCD_KEY_TYPES[key];
|
|
3655
3820
|
if (!expectedType) continue;
|
|
3656
|
-
if (version ===
|
|
3821
|
+
if (version === 1 && key in CMCD_V1_KEY_TYPE_OVERRIDES) expectedType = CMCD_V1_KEY_TYPE_OVERRIDES[key];
|
|
3657
3822
|
switch (expectedType) {
|
|
3658
3823
|
case CMCD_KEY_TYPE_INTEGER:
|
|
3659
3824
|
if (!isInteger(value)) issues.push({
|
|
@@ -3702,9 +3867,7 @@ function validateCmcdValues(data, options) {
|
|
|
3702
3867
|
case CMCD_KEY_TYPE_NUMBER_LIST:
|
|
3703
3868
|
validateListValue(key, value, version, issues);
|
|
3704
3869
|
break;
|
|
3705
|
-
case CMCD_KEY_TYPE_STRING_LIST:
|
|
3706
|
-
validateStringArrayValue(key, value, issues);
|
|
3707
|
-
break;
|
|
3870
|
+
case CMCD_KEY_TYPE_STRING_LIST: validateStringArrayValue(key, value, issues);
|
|
3708
3871
|
}
|
|
3709
3872
|
}
|
|
3710
3873
|
return {
|
|
@@ -3712,7 +3875,6 @@ function validateCmcdValues(data, options) {
|
|
|
3712
3875
|
issues
|
|
3713
3876
|
};
|
|
3714
3877
|
}
|
|
3715
|
-
|
|
3716
3878
|
//#endregion
|
|
3717
3879
|
//#region src/validateCmcd.ts
|
|
3718
3880
|
/**
|
|
@@ -3732,7 +3894,6 @@ function validateCmcdValues(data, options) {
|
|
|
3732
3894
|
function validateCmcd(data, options) {
|
|
3733
3895
|
return mergeValidationResults(validateCmcdKeys(data, options), validateCmcdValues(data, options), validateCmcdStructure(data, options));
|
|
3734
3896
|
}
|
|
3735
|
-
|
|
3736
3897
|
//#endregion
|
|
3737
3898
|
//#region src/validateCmcdEvents.ts
|
|
3738
3899
|
/**
|
|
@@ -3798,7 +3959,6 @@ function validateCmcdEvents(cmcd, options) {
|
|
|
3798
3959
|
data: decodedLines
|
|
3799
3960
|
};
|
|
3800
3961
|
}
|
|
3801
|
-
|
|
3802
3962
|
//#endregion
|
|
3803
3963
|
//#region src/validateCmcdEventReport.ts
|
|
3804
3964
|
/**
|
|
@@ -3833,7 +3993,7 @@ function validateCmcdEventReport(request, options) {
|
|
|
3833
3993
|
});
|
|
3834
3994
|
else {
|
|
3835
3995
|
const mediaType = contentType.split(";")[0].trim().toLowerCase();
|
|
3836
|
-
if (mediaType !==
|
|
3996
|
+
if (mediaType !== "application/cmcd") issues.push({
|
|
3837
3997
|
message: `Invalid Content-Type '${mediaType}'. Event reports must use '${CMCD_MIME_TYPE}'.`,
|
|
3838
3998
|
severity: CMCD_VALIDATION_SEVERITY_ERROR
|
|
3839
3999
|
});
|
|
@@ -3868,7 +4028,6 @@ function validateCmcdEventReport(request, options) {
|
|
|
3868
4028
|
data: bodyResult.data
|
|
3869
4029
|
};
|
|
3870
4030
|
}
|
|
3871
|
-
|
|
3872
4031
|
//#endregion
|
|
3873
4032
|
//#region src/validateCmcdHeaders.ts
|
|
3874
4033
|
/**
|
|
@@ -3932,7 +4091,6 @@ function validateCmcdHeaders(headers, options) {
|
|
|
3932
4091
|
data: merged
|
|
3933
4092
|
};
|
|
3934
4093
|
}
|
|
3935
|
-
|
|
3936
4094
|
//#endregion
|
|
3937
4095
|
//#region src/validateCmcdRequest.ts
|
|
3938
4096
|
/**
|
|
@@ -4032,7 +4190,7 @@ function extractHeaderRecord(headers) {
|
|
|
4032
4190
|
}
|
|
4033
4191
|
return found ? result : void 0;
|
|
4034
4192
|
}
|
|
4035
|
-
|
|
4036
4193
|
//#endregion
|
|
4037
4194
|
export { CMCD_DEFAULT_TIME_INTERVAL, CMCD_EVENT_AD_BREAK_END, CMCD_EVENT_AD_BREAK_START, CMCD_EVENT_AD_END, CMCD_EVENT_AD_START, CMCD_EVENT_BACKGROUNDED_MODE, CMCD_EVENT_BITRATE_CHANGE, CMCD_EVENT_CONTENT_ID, CMCD_EVENT_CUSTOM_EVENT, CMCD_EVENT_ERROR, CMCD_EVENT_KEYS, CMCD_EVENT_MODE, CMCD_EVENT_MUTE, CMCD_EVENT_PLAYBACK_RATE, CMCD_EVENT_PLAYER_COLLAPSE, CMCD_EVENT_PLAYER_EXPAND, CMCD_EVENT_PLAY_STATE, CMCD_EVENT_RESPONSE_RECEIVED, CMCD_EVENT_SKIP, CMCD_EVENT_TIME_INTERVAL, CMCD_EVENT_UNMUTE, CMCD_FORMATTER_MAP, CMCD_HEADERS, CMCD_HEADER_FIELDS, CMCD_HEADER_MAP, CMCD_JSON, CMCD_KEYS, CMCD_MIME_TYPE, CMCD_OBJECT, CMCD_PARAM, CMCD_QUERY, CMCD_RECORDED_REPORT_MODE_EVENT, CMCD_RECORDED_REPORT_MODE_HEADER, CMCD_RECORDED_REPORT_MODE_QUERY, CMCD_RECORDED_REQUEST_TYPE_EVENT, CMCD_RECORDED_REQUEST_TYPE_MANIFEST, CMCD_RECORDED_REQUEST_TYPE_SEGMENT, CMCD_RECORDED_REQUEST_TYPE_UNKNOWN, CMCD_REQUEST, CMCD_REQUEST_KEYS, CMCD_REQUEST_MODE, CMCD_REQUEST_PROVENANCE, CMCD_RESPONSE_KEYS, CMCD_SESSION, CMCD_STATUS, CMCD_V1, CMCD_V1_KEYS, CMCD_V2, CMCD_VALIDATION_SEVERITY_ERROR, CMCD_VALIDATION_SEVERITY_WARNING, CmcdEventType, CmcdHeaderField, CmcdObjectType, CmcdPlayerState, CmcdRecordedReportMode, CmcdRecordedRequestType, CmcdReportRecorder, CmcdReporter, CmcdReportingMode, CmcdStreamType, CmcdStreamingFormat, CmcdTransmissionMode, CmcdValidationSeverity, appendCmcdHeaders, appendCmcdQuery, createFetchTransport, createXhrTransport, decodeCmcd, encodeCmcd, fromCmcdHeaders, fromCmcdQuery, fromCmcdUrl, groupCmcdHeaders, isCmcdCustomKey, isCmcdEventKey, isCmcdRequestKey, isCmcdResponseReceivedKey, isCmcdV1Data, isCmcdV1Key, isCmcdV2Data, prepareCmcdData, toCmcdHeaders, toCmcdQuery, toCmcdUrl, toCmcdValue, validateCmcd, validateCmcdEventReport, validateCmcdEvents, validateCmcdHeaders, validateCmcdKeys, validateCmcdRequest, validateCmcdStructure, validateCmcdValues };
|
|
4195
|
+
|
|
4038
4196
|
//# sourceMappingURL=index.js.map
|