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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as StormcloudVideoPlayerConfig } from '../types-
|
|
1
|
+
import { S as StormcloudVideoPlayerConfig } from '../types-CUKMIqHL.cjs';
|
|
2
2
|
|
|
3
3
|
declare class StormcloudVideoPlayer {
|
|
4
4
|
private readonly video;
|
|
@@ -78,6 +78,11 @@ declare class StormcloudVideoPlayer {
|
|
|
78
78
|
private adDetectSentForCurrentBreak;
|
|
79
79
|
private palNonce;
|
|
80
80
|
private palPlaybackStarted;
|
|
81
|
+
private readonly streamCorrelator;
|
|
82
|
+
private consentSignals;
|
|
83
|
+
private podCounter;
|
|
84
|
+
private podAssignedByPrefetch;
|
|
85
|
+
private adRequestPositionInBreak;
|
|
81
86
|
constructor(config: StormcloudVideoPlayerConfig);
|
|
82
87
|
private createAdPlayer;
|
|
83
88
|
load(): Promise<void>;
|
|
@@ -141,6 +146,7 @@ declare class StormcloudVideoPlayer {
|
|
|
141
146
|
getCurrentAdIndex(): number;
|
|
142
147
|
getTotalAdsInBreak(): number;
|
|
143
148
|
getAdRemainingMs(): number;
|
|
149
|
+
private beginNewAdPod;
|
|
144
150
|
private generateVastUrlsWithCorrelators;
|
|
145
151
|
isAdPlaying(): boolean;
|
|
146
152
|
isShowingAds(): boolean;
|
|
@@ -2240,6 +2240,166 @@ function initializePolyfills() {
|
|
|
2240
2240
|
polyfillTextEncoder();
|
|
2241
2241
|
polyfillPromiseFinally();
|
|
2242
2242
|
}
|
|
2243
|
+
// src/utils/vastMacros.ts
|
|
2244
|
+
function generateCorrelator() {
|
|
2245
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
2246
|
+
try {
|
|
2247
|
+
var _buf_, _buf_1;
|
|
2248
|
+
var buf = new Uint32Array(2);
|
|
2249
|
+
crypto.getRandomValues(buf);
|
|
2250
|
+
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);
|
|
2251
|
+
if (value > 0) {
|
|
2252
|
+
return String(value);
|
|
2253
|
+
}
|
|
2254
|
+
} catch (unused) {}
|
|
2255
|
+
}
|
|
2256
|
+
return String(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1);
|
|
2257
|
+
}
|
|
2258
|
+
var UNEXPANDED_MACRO_PATTERN = /^(\[[^\]]*\]|\{[^}]*\}|%%[^%]*%%)$/;
|
|
2259
|
+
function applyVastMacros(baseUrl, ctx) {
|
|
2260
|
+
var url;
|
|
2261
|
+
try {
|
|
2262
|
+
url = new URL(baseUrl);
|
|
2263
|
+
} catch (unused) {
|
|
2264
|
+
return replaceCorrelatorFallback(baseUrl, ctx.correlator);
|
|
2265
|
+
}
|
|
2266
|
+
var params = url.searchParams;
|
|
2267
|
+
params.set("correlator", ctx.correlator);
|
|
2268
|
+
params.set("scor", ctx.streamCorrelator);
|
|
2269
|
+
if (ctx.pod != null) {
|
|
2270
|
+
params.set("pod", String(ctx.pod));
|
|
2271
|
+
}
|
|
2272
|
+
if (ctx.adPosition != null) {
|
|
2273
|
+
params.set("ppos", String(ctx.adPosition));
|
|
2274
|
+
}
|
|
2275
|
+
if (ctx.pageUrl) {
|
|
2276
|
+
params.set("url", ctx.pageUrl);
|
|
2277
|
+
params.set("description_url", ctx.pageUrl);
|
|
2278
|
+
}
|
|
2279
|
+
if (ctx.adWillPlayMuted != null) {
|
|
2280
|
+
params.set("vpmute", ctx.adWillPlayMuted ? "1" : "0");
|
|
2281
|
+
}
|
|
2282
|
+
if (ctx.adWillAutoPlay != null) {
|
|
2283
|
+
params.set("vpa", ctx.adWillAutoPlay ? "auto" : "click");
|
|
2284
|
+
}
|
|
2285
|
+
if (ctx.deviceId && ctx.deviceIdType) {
|
|
2286
|
+
params.set("rdid", ctx.deviceId);
|
|
2287
|
+
params.set("idtype", ctx.deviceIdType);
|
|
2288
|
+
params.set("is_lat", ctx.limitAdTracking ? "1" : "0");
|
|
2289
|
+
} else {
|
|
2290
|
+
params.delete("rdid");
|
|
2291
|
+
params.delete("idtype");
|
|
2292
|
+
params.delete("is_lat");
|
|
2293
|
+
}
|
|
2294
|
+
var consent = ctx.consent;
|
|
2295
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.gdpr) != null) {
|
|
2296
|
+
params.set("gdpr", consent.gdpr);
|
|
2297
|
+
}
|
|
2298
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.gdprConsent) != null) {
|
|
2299
|
+
params.set("gdpr_consent", consent.gdprConsent);
|
|
2300
|
+
}
|
|
2301
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.usPrivacy) != null) {
|
|
2302
|
+
params.set("us_privacy", consent.usPrivacy);
|
|
2303
|
+
}
|
|
2304
|
+
if (ctx.adTest) {
|
|
2305
|
+
params.set("adtest", "on");
|
|
2306
|
+
}
|
|
2307
|
+
var staleKeys = [];
|
|
2308
|
+
params.forEach(function(value, key) {
|
|
2309
|
+
if (UNEXPANDED_MACRO_PATTERN.test(value)) {
|
|
2310
|
+
staleKeys.push(key);
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2314
|
+
try {
|
|
2315
|
+
for(var _iterator = staleKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2316
|
+
var key = _step.value;
|
|
2317
|
+
params.delete(key);
|
|
2318
|
+
}
|
|
2319
|
+
} catch (err) {
|
|
2320
|
+
_didIteratorError = true;
|
|
2321
|
+
_iteratorError = err;
|
|
2322
|
+
} finally{
|
|
2323
|
+
try {
|
|
2324
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2325
|
+
_iterator.return();
|
|
2326
|
+
}
|
|
2327
|
+
} finally{
|
|
2328
|
+
if (_didIteratorError) {
|
|
2329
|
+
throw _iteratorError;
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
return url.toString();
|
|
2334
|
+
}
|
|
2335
|
+
function replaceCorrelatorFallback(baseUrl, correlator) {
|
|
2336
|
+
var correlatorRegex = /([?&])correlator=([^&]*)/;
|
|
2337
|
+
if (correlatorRegex.test(baseUrl)) {
|
|
2338
|
+
return baseUrl.replace(correlatorRegex, "$1correlator=".concat(correlator));
|
|
2339
|
+
}
|
|
2340
|
+
var sep = baseUrl.includes("?") ? "&" : "?";
|
|
2341
|
+
return "".concat(baseUrl).concat(sep, "correlator=").concat(correlator);
|
|
2342
|
+
}
|
|
2343
|
+
function fetchConsentSignals() {
|
|
2344
|
+
var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1500;
|
|
2345
|
+
var signals = {};
|
|
2346
|
+
if (typeof window === "undefined") {
|
|
2347
|
+
return Promise.resolve(signals);
|
|
2348
|
+
}
|
|
2349
|
+
var tasks = [];
|
|
2350
|
+
var tcfApi = window.__tcfapi;
|
|
2351
|
+
if (typeof tcfApi === "function") {
|
|
2352
|
+
tasks.push(new Promise(function(resolve) {
|
|
2353
|
+
var settled = false;
|
|
2354
|
+
try {
|
|
2355
|
+
tcfApi("addEventListener", 2, function(tcData, success) {
|
|
2356
|
+
if (settled) return;
|
|
2357
|
+
if (success && tcData && (tcData.eventStatus === "tcloaded" || tcData.eventStatus === "useractioncomplete")) {
|
|
2358
|
+
settled = true;
|
|
2359
|
+
signals.gdpr = tcData.gdprApplies ? "1" : "0";
|
|
2360
|
+
if (typeof tcData.tcString === "string" && tcData.tcString) {
|
|
2361
|
+
signals.gdprConsent = tcData.tcString;
|
|
2362
|
+
}
|
|
2363
|
+
try {
|
|
2364
|
+
tcfApi("removeEventListener", 2, function() {}, tcData.listenerId);
|
|
2365
|
+
} catch (unused) {}
|
|
2366
|
+
resolve();
|
|
2367
|
+
}
|
|
2368
|
+
});
|
|
2369
|
+
} catch (unused) {
|
|
2370
|
+
resolve();
|
|
2371
|
+
}
|
|
2372
|
+
setTimeout(function() {
|
|
2373
|
+
if (!settled) {
|
|
2374
|
+
settled = true;
|
|
2375
|
+
resolve();
|
|
2376
|
+
}
|
|
2377
|
+
}, timeoutMs);
|
|
2378
|
+
}));
|
|
2379
|
+
}
|
|
2380
|
+
var uspApi = window.__uspapi;
|
|
2381
|
+
if (typeof uspApi === "function") {
|
|
2382
|
+
tasks.push(new Promise(function(resolve) {
|
|
2383
|
+
try {
|
|
2384
|
+
uspApi("getUSPData", 1, function(data, success) {
|
|
2385
|
+
if (success && typeof (data === null || data === void 0 ? void 0 : data.uspString) === "string" && data.uspString) {
|
|
2386
|
+
signals.usPrivacy = data.uspString;
|
|
2387
|
+
}
|
|
2388
|
+
resolve();
|
|
2389
|
+
});
|
|
2390
|
+
} catch (unused) {
|
|
2391
|
+
resolve();
|
|
2392
|
+
}
|
|
2393
|
+
setTimeout(resolve, timeoutMs);
|
|
2394
|
+
}));
|
|
2395
|
+
}
|
|
2396
|
+
if (tasks.length === 0) {
|
|
2397
|
+
return Promise.resolve(signals);
|
|
2398
|
+
}
|
|
2399
|
+
return Promise.all(tasks).then(function() {
|
|
2400
|
+
return signals;
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2243
2403
|
// src/utils/browserCompat.ts
|
|
2244
2404
|
function getChromeVersion(ua) {
|
|
2245
2405
|
var match = ua.match(/Chrome\/(\d+)/);
|
|
@@ -2465,6 +2625,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2465
2625
|
this.preloadPoolLoopRunning = false;
|
|
2466
2626
|
this.adDetectSentForCurrentBreak = false;
|
|
2467
2627
|
this.palPlaybackStarted = false;
|
|
2628
|
+
this.streamCorrelator = generateCorrelator();
|
|
2629
|
+
this.consentSignals = {};
|
|
2630
|
+
this.podCounter = 0;
|
|
2631
|
+
this.podAssignedByPrefetch = false;
|
|
2632
|
+
this.adRequestPositionInBreak = 0;
|
|
2468
2633
|
this.continuousFetchLoopRunning = false;
|
|
2469
2634
|
initializePolyfills();
|
|
2470
2635
|
var browserOverrides = getBrowserConfigOverrides();
|
|
@@ -2537,6 +2702,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2537
2702
|
adWillPlayMuted: !!this.config.muted,
|
|
2538
2703
|
continuousPlayback: (_this_config_lowLatencyMode = this.config.lowLatencyMode) !== null && _this_config_lowLatencyMode !== void 0 ? _this_config_lowLatencyMode : false
|
|
2539
2704
|
}).catch(function() {});
|
|
2705
|
+
fetchConsentSignals().then(function(signals) {
|
|
2706
|
+
_this.consentSignals = signals;
|
|
2707
|
+
}).catch(function() {});
|
|
2540
2708
|
this.initializeTracking();
|
|
2541
2709
|
if (!this.shouldUseNativeHls()) return [
|
|
2542
2710
|
3,
|
|
@@ -4833,25 +5001,35 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4833
5001
|
return this.getRemainingAdMs();
|
|
4834
5002
|
}
|
|
4835
5003
|
},
|
|
5004
|
+
{
|
|
5005
|
+
key: "beginNewAdPod",
|
|
5006
|
+
value: function beginNewAdPod() {
|
|
5007
|
+
this.podCounter++;
|
|
5008
|
+
this.adRequestPositionInBreak = 0;
|
|
5009
|
+
}
|
|
5010
|
+
},
|
|
4836
5011
|
{
|
|
4837
5012
|
key: "generateVastUrlsWithCorrelators",
|
|
4838
5013
|
value: function generateVastUrlsWithCorrelators(baseUrl, count) {
|
|
4839
5014
|
var urls = [];
|
|
4840
|
-
var baseTimestamp = Date.now();
|
|
4841
5015
|
for(var i = 0; i < count; i++){
|
|
4842
|
-
|
|
4843
|
-
var
|
|
4844
|
-
var
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
5016
|
+
this.adRequestPositionInBreak++;
|
|
5017
|
+
var adWillPlayMuted = this.inAdBreak ? this.adPlayer.getOriginalMutedState() : this.video.muted;
|
|
5018
|
+
var urlWithMacros = applyVastMacros(baseUrl, {
|
|
5019
|
+
correlator: generateCorrelator(),
|
|
5020
|
+
streamCorrelator: this.streamCorrelator,
|
|
5021
|
+
pod: this.podCounter > 0 ? this.podCounter : void 0,
|
|
5022
|
+
adPosition: this.adRequestPositionInBreak,
|
|
5023
|
+
pageUrl: typeof window !== "undefined" ? window.location.href : void 0,
|
|
5024
|
+
adWillPlayMuted: adWillPlayMuted,
|
|
5025
|
+
adWillAutoPlay: !!this.config.autoplay,
|
|
5026
|
+
deviceId: this.config.deviceId,
|
|
5027
|
+
deviceIdType: this.config.deviceIdType,
|
|
5028
|
+
limitAdTracking: this.config.limitAdTracking,
|
|
5029
|
+
adTest: this.config.adTest,
|
|
5030
|
+
consent: this.consentSignals
|
|
5031
|
+
});
|
|
5032
|
+
urls.push(this.palNonce.injectNonce(urlWithMacros));
|
|
4855
5033
|
}
|
|
4856
5034
|
return urls;
|
|
4857
5035
|
}
|
|
@@ -4921,6 +5099,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4921
5099
|
}
|
|
4922
5100
|
return;
|
|
4923
5101
|
}
|
|
5102
|
+
this.beginNewAdPod();
|
|
5103
|
+
this.podAssignedByPrefetch = true;
|
|
4924
5104
|
var urlsToPregenerate = 5;
|
|
4925
5105
|
var generatedUrls = this.generateVastUrlsWithCorrelators(baseVastUrl, urlsToPregenerate);
|
|
4926
5106
|
this.pendingAdBreak = _object_spread_props(_object_spread({
|
|
@@ -4958,6 +5138,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4958
5138
|
}
|
|
4959
5139
|
this.pendingAdBreak = null;
|
|
4960
5140
|
this.pendingScte35CueKey = void 0;
|
|
5141
|
+
this.podAssignedByPrefetch = false;
|
|
4961
5142
|
}
|
|
4962
5143
|
},
|
|
4963
5144
|
{
|
|
@@ -5394,6 +5575,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5394
5575
|
this.continuousFetchingActive = true;
|
|
5395
5576
|
this.isShowingPlaceholder = false;
|
|
5396
5577
|
this.totalAdRequestsInBreak = 0;
|
|
5578
|
+
if (this.podAssignedByPrefetch) {
|
|
5579
|
+
this.podAssignedByPrefetch = false;
|
|
5580
|
+
} else {
|
|
5581
|
+
this.beginNewAdPod();
|
|
5582
|
+
}
|
|
5397
5583
|
currentMuted = this.video.muted;
|
|
5398
5584
|
currentVolume = this.video.volume;
|
|
5399
5585
|
this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
|