stormcloud-video-player 0.8.4 → 0.8.5
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/stormcloud-vp.min.js +2 -2
- package/lib/index.cjs +200 -14
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +10 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +200 -14
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +200 -14
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +7 -1
- package/lib/players/HlsPlayer.cjs +200 -14
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +200 -14
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.d.cts +1 -1
- package/lib/{types-BmF_60m2.d.cts → types-CUKMIqHL.d.cts} +4 -0
- package/lib/ui/StormcloudVideoPlayer.cjs +200 -14
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/lib/utils/vastMacros.cjs +231 -0
- package/lib/utils/vastMacros.cjs.map +1 -0
- package/lib/utils/vastMacros.d.cts +24 -0
- package/package.json +1 -1
|
@@ -2188,6 +2188,166 @@ function initializePolyfills() {
|
|
|
2188
2188
|
polyfillTextEncoder();
|
|
2189
2189
|
polyfillPromiseFinally();
|
|
2190
2190
|
}
|
|
2191
|
+
// src/utils/vastMacros.ts
|
|
2192
|
+
function generateCorrelator() {
|
|
2193
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
2194
|
+
try {
|
|
2195
|
+
var _buf_, _buf_1;
|
|
2196
|
+
var buf = new Uint32Array(2);
|
|
2197
|
+
crypto.getRandomValues(buf);
|
|
2198
|
+
var value = ((_buf_ = buf[0]) !== null && _buf_ !== void 0 ? _buf_ : 0) * 2097152 + (((_buf_1 = buf[1]) !== null && _buf_1 !== void 0 ? _buf_1 : 0) & 2097151);
|
|
2199
|
+
if (value > 0) {
|
|
2200
|
+
return String(value);
|
|
2201
|
+
}
|
|
2202
|
+
} catch (unused) {}
|
|
2203
|
+
}
|
|
2204
|
+
return String(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1);
|
|
2205
|
+
}
|
|
2206
|
+
var UNEXPANDED_MACRO_PATTERN = /^(\[[^\]]*\]|\{[^}]*\}|%%[^%]*%%)$/;
|
|
2207
|
+
function applyVastMacros(baseUrl, ctx) {
|
|
2208
|
+
var url;
|
|
2209
|
+
try {
|
|
2210
|
+
url = new URL(baseUrl);
|
|
2211
|
+
} catch (unused) {
|
|
2212
|
+
return replaceCorrelatorFallback(baseUrl, ctx.correlator);
|
|
2213
|
+
}
|
|
2214
|
+
var params = url.searchParams;
|
|
2215
|
+
params.set("correlator", ctx.correlator);
|
|
2216
|
+
params.set("scor", ctx.streamCorrelator);
|
|
2217
|
+
if (ctx.pod != null) {
|
|
2218
|
+
params.set("pod", String(ctx.pod));
|
|
2219
|
+
}
|
|
2220
|
+
if (ctx.adPosition != null) {
|
|
2221
|
+
params.set("ppos", String(ctx.adPosition));
|
|
2222
|
+
}
|
|
2223
|
+
if (ctx.pageUrl) {
|
|
2224
|
+
params.set("url", ctx.pageUrl);
|
|
2225
|
+
params.set("description_url", ctx.pageUrl);
|
|
2226
|
+
}
|
|
2227
|
+
if (ctx.adWillPlayMuted != null) {
|
|
2228
|
+
params.set("vpmute", ctx.adWillPlayMuted ? "1" : "0");
|
|
2229
|
+
}
|
|
2230
|
+
if (ctx.adWillAutoPlay != null) {
|
|
2231
|
+
params.set("vpa", ctx.adWillAutoPlay ? "auto" : "click");
|
|
2232
|
+
}
|
|
2233
|
+
if (ctx.deviceId && ctx.deviceIdType) {
|
|
2234
|
+
params.set("rdid", ctx.deviceId);
|
|
2235
|
+
params.set("idtype", ctx.deviceIdType);
|
|
2236
|
+
params.set("is_lat", ctx.limitAdTracking ? "1" : "0");
|
|
2237
|
+
} else {
|
|
2238
|
+
params.delete("rdid");
|
|
2239
|
+
params.delete("idtype");
|
|
2240
|
+
params.delete("is_lat");
|
|
2241
|
+
}
|
|
2242
|
+
var consent = ctx.consent;
|
|
2243
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.gdpr) != null) {
|
|
2244
|
+
params.set("gdpr", consent.gdpr);
|
|
2245
|
+
}
|
|
2246
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.gdprConsent) != null) {
|
|
2247
|
+
params.set("gdpr_consent", consent.gdprConsent);
|
|
2248
|
+
}
|
|
2249
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.usPrivacy) != null) {
|
|
2250
|
+
params.set("us_privacy", consent.usPrivacy);
|
|
2251
|
+
}
|
|
2252
|
+
if (ctx.adTest) {
|
|
2253
|
+
params.set("adtest", "on");
|
|
2254
|
+
}
|
|
2255
|
+
var staleKeys = [];
|
|
2256
|
+
params.forEach(function(value, key) {
|
|
2257
|
+
if (UNEXPANDED_MACRO_PATTERN.test(value)) {
|
|
2258
|
+
staleKeys.push(key);
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2261
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2262
|
+
try {
|
|
2263
|
+
for(var _iterator = staleKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2264
|
+
var key = _step.value;
|
|
2265
|
+
params.delete(key);
|
|
2266
|
+
}
|
|
2267
|
+
} catch (err) {
|
|
2268
|
+
_didIteratorError = true;
|
|
2269
|
+
_iteratorError = err;
|
|
2270
|
+
} finally{
|
|
2271
|
+
try {
|
|
2272
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2273
|
+
_iterator.return();
|
|
2274
|
+
}
|
|
2275
|
+
} finally{
|
|
2276
|
+
if (_didIteratorError) {
|
|
2277
|
+
throw _iteratorError;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
return url.toString();
|
|
2282
|
+
}
|
|
2283
|
+
function replaceCorrelatorFallback(baseUrl, correlator) {
|
|
2284
|
+
var correlatorRegex = /([?&])correlator=([^&]*)/;
|
|
2285
|
+
if (correlatorRegex.test(baseUrl)) {
|
|
2286
|
+
return baseUrl.replace(correlatorRegex, "$1correlator=".concat(correlator));
|
|
2287
|
+
}
|
|
2288
|
+
var sep = baseUrl.includes("?") ? "&" : "?";
|
|
2289
|
+
return "".concat(baseUrl).concat(sep, "correlator=").concat(correlator);
|
|
2290
|
+
}
|
|
2291
|
+
function fetchConsentSignals() {
|
|
2292
|
+
var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1500;
|
|
2293
|
+
var signals = {};
|
|
2294
|
+
if (typeof window === "undefined") {
|
|
2295
|
+
return Promise.resolve(signals);
|
|
2296
|
+
}
|
|
2297
|
+
var tasks = [];
|
|
2298
|
+
var tcfApi = window.__tcfapi;
|
|
2299
|
+
if (typeof tcfApi === "function") {
|
|
2300
|
+
tasks.push(new Promise(function(resolve) {
|
|
2301
|
+
var settled = false;
|
|
2302
|
+
try {
|
|
2303
|
+
tcfApi("addEventListener", 2, function(tcData, success) {
|
|
2304
|
+
if (settled) return;
|
|
2305
|
+
if (success && tcData && (tcData.eventStatus === "tcloaded" || tcData.eventStatus === "useractioncomplete")) {
|
|
2306
|
+
settled = true;
|
|
2307
|
+
signals.gdpr = tcData.gdprApplies ? "1" : "0";
|
|
2308
|
+
if (typeof tcData.tcString === "string" && tcData.tcString) {
|
|
2309
|
+
signals.gdprConsent = tcData.tcString;
|
|
2310
|
+
}
|
|
2311
|
+
try {
|
|
2312
|
+
tcfApi("removeEventListener", 2, function() {}, tcData.listenerId);
|
|
2313
|
+
} catch (unused) {}
|
|
2314
|
+
resolve();
|
|
2315
|
+
}
|
|
2316
|
+
});
|
|
2317
|
+
} catch (unused) {
|
|
2318
|
+
resolve();
|
|
2319
|
+
}
|
|
2320
|
+
setTimeout(function() {
|
|
2321
|
+
if (!settled) {
|
|
2322
|
+
settled = true;
|
|
2323
|
+
resolve();
|
|
2324
|
+
}
|
|
2325
|
+
}, timeoutMs);
|
|
2326
|
+
}));
|
|
2327
|
+
}
|
|
2328
|
+
var uspApi = window.__uspapi;
|
|
2329
|
+
if (typeof uspApi === "function") {
|
|
2330
|
+
tasks.push(new Promise(function(resolve) {
|
|
2331
|
+
try {
|
|
2332
|
+
uspApi("getUSPData", 1, function(data, success) {
|
|
2333
|
+
if (success && typeof (data === null || data === void 0 ? void 0 : data.uspString) === "string" && data.uspString) {
|
|
2334
|
+
signals.usPrivacy = data.uspString;
|
|
2335
|
+
}
|
|
2336
|
+
resolve();
|
|
2337
|
+
});
|
|
2338
|
+
} catch (unused) {
|
|
2339
|
+
resolve();
|
|
2340
|
+
}
|
|
2341
|
+
setTimeout(resolve, timeoutMs);
|
|
2342
|
+
}));
|
|
2343
|
+
}
|
|
2344
|
+
if (tasks.length === 0) {
|
|
2345
|
+
return Promise.resolve(signals);
|
|
2346
|
+
}
|
|
2347
|
+
return Promise.all(tasks).then(function() {
|
|
2348
|
+
return signals;
|
|
2349
|
+
});
|
|
2350
|
+
}
|
|
2191
2351
|
// src/utils/browserCompat.ts
|
|
2192
2352
|
function getChromeVersion(ua) {
|
|
2193
2353
|
var match = ua.match(/Chrome\/(\d+)/);
|
|
@@ -2413,6 +2573,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2413
2573
|
this.preloadPoolLoopRunning = false;
|
|
2414
2574
|
this.adDetectSentForCurrentBreak = false;
|
|
2415
2575
|
this.palPlaybackStarted = false;
|
|
2576
|
+
this.streamCorrelator = generateCorrelator();
|
|
2577
|
+
this.consentSignals = {};
|
|
2578
|
+
this.podCounter = 0;
|
|
2579
|
+
this.podAssignedByPrefetch = false;
|
|
2580
|
+
this.adRequestPositionInBreak = 0;
|
|
2416
2581
|
this.continuousFetchLoopRunning = false;
|
|
2417
2582
|
initializePolyfills();
|
|
2418
2583
|
var browserOverrides = getBrowserConfigOverrides();
|
|
@@ -2485,6 +2650,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2485
2650
|
adWillPlayMuted: !!this.config.muted,
|
|
2486
2651
|
continuousPlayback: (_this_config_lowLatencyMode = this.config.lowLatencyMode) !== null && _this_config_lowLatencyMode !== void 0 ? _this_config_lowLatencyMode : false
|
|
2487
2652
|
}).catch(function() {});
|
|
2653
|
+
fetchConsentSignals().then(function(signals) {
|
|
2654
|
+
_this.consentSignals = signals;
|
|
2655
|
+
}).catch(function() {});
|
|
2488
2656
|
this.initializeTracking();
|
|
2489
2657
|
if (!this.shouldUseNativeHls()) return [
|
|
2490
2658
|
3,
|
|
@@ -4781,25 +4949,35 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4781
4949
|
return this.getRemainingAdMs();
|
|
4782
4950
|
}
|
|
4783
4951
|
},
|
|
4952
|
+
{
|
|
4953
|
+
key: "beginNewAdPod",
|
|
4954
|
+
value: function beginNewAdPod() {
|
|
4955
|
+
this.podCounter++;
|
|
4956
|
+
this.adRequestPositionInBreak = 0;
|
|
4957
|
+
}
|
|
4958
|
+
},
|
|
4784
4959
|
{
|
|
4785
4960
|
key: "generateVastUrlsWithCorrelators",
|
|
4786
4961
|
value: function generateVastUrlsWithCorrelators(baseUrl, count) {
|
|
4787
4962
|
var urls = [];
|
|
4788
|
-
var baseTimestamp = Date.now();
|
|
4789
4963
|
for(var i = 0; i < count; i++){
|
|
4790
|
-
|
|
4791
|
-
var
|
|
4792
|
-
var
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4964
|
+
this.adRequestPositionInBreak++;
|
|
4965
|
+
var adWillPlayMuted = this.inAdBreak ? this.adPlayer.getOriginalMutedState() : this.video.muted;
|
|
4966
|
+
var urlWithMacros = applyVastMacros(baseUrl, {
|
|
4967
|
+
correlator: generateCorrelator(),
|
|
4968
|
+
streamCorrelator: this.streamCorrelator,
|
|
4969
|
+
pod: this.podCounter > 0 ? this.podCounter : void 0,
|
|
4970
|
+
adPosition: this.adRequestPositionInBreak,
|
|
4971
|
+
pageUrl: typeof window !== "undefined" ? window.location.href : void 0,
|
|
4972
|
+
adWillPlayMuted: adWillPlayMuted,
|
|
4973
|
+
adWillAutoPlay: !!this.config.autoplay,
|
|
4974
|
+
deviceId: this.config.deviceId,
|
|
4975
|
+
deviceIdType: this.config.deviceIdType,
|
|
4976
|
+
limitAdTracking: this.config.limitAdTracking,
|
|
4977
|
+
adTest: this.config.adTest,
|
|
4978
|
+
consent: this.consentSignals
|
|
4979
|
+
});
|
|
4980
|
+
urls.push(this.palNonce.injectNonce(urlWithMacros));
|
|
4803
4981
|
}
|
|
4804
4982
|
return urls;
|
|
4805
4983
|
}
|
|
@@ -4869,6 +5047,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4869
5047
|
}
|
|
4870
5048
|
return;
|
|
4871
5049
|
}
|
|
5050
|
+
this.beginNewAdPod();
|
|
5051
|
+
this.podAssignedByPrefetch = true;
|
|
4872
5052
|
var urlsToPregenerate = 5;
|
|
4873
5053
|
var generatedUrls = this.generateVastUrlsWithCorrelators(baseVastUrl, urlsToPregenerate);
|
|
4874
5054
|
this.pendingAdBreak = _object_spread_props(_object_spread({
|
|
@@ -4906,6 +5086,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4906
5086
|
}
|
|
4907
5087
|
this.pendingAdBreak = null;
|
|
4908
5088
|
this.pendingScte35CueKey = void 0;
|
|
5089
|
+
this.podAssignedByPrefetch = false;
|
|
4909
5090
|
}
|
|
4910
5091
|
},
|
|
4911
5092
|
{
|
|
@@ -5342,6 +5523,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5342
5523
|
this.continuousFetchingActive = true;
|
|
5343
5524
|
this.isShowingPlaceholder = false;
|
|
5344
5525
|
this.totalAdRequestsInBreak = 0;
|
|
5526
|
+
if (this.podAssignedByPrefetch) {
|
|
5527
|
+
this.podAssignedByPrefetch = false;
|
|
5528
|
+
} else {
|
|
5529
|
+
this.beginNewAdPod();
|
|
5530
|
+
}
|
|
5345
5531
|
currentMuted = this.video.muted;
|
|
5346
5532
|
currentVolume = this.video.volume;
|
|
5347
5533
|
this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
|