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
|
@@ -23,6 +23,10 @@ interface StormcloudVideoPlayerConfig {
|
|
|
23
23
|
vmapUrl?: string;
|
|
24
24
|
vastMode?: 'adstorm' | 'default';
|
|
25
25
|
minSegmentsBeforePlay?: number;
|
|
26
|
+
deviceId?: string;
|
|
27
|
+
deviceIdType?: string;
|
|
28
|
+
limitAdTracking?: boolean;
|
|
29
|
+
adTest?: boolean;
|
|
26
30
|
}
|
|
27
31
|
interface AdController {
|
|
28
32
|
initialize: () => void;
|
|
@@ -2226,6 +2226,166 @@ function initializePolyfills() {
|
|
|
2226
2226
|
polyfillTextEncoder();
|
|
2227
2227
|
polyfillPromiseFinally();
|
|
2228
2228
|
}
|
|
2229
|
+
// src/utils/vastMacros.ts
|
|
2230
|
+
function generateCorrelator() {
|
|
2231
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
2232
|
+
try {
|
|
2233
|
+
var _buf_, _buf_1;
|
|
2234
|
+
var buf = new Uint32Array(2);
|
|
2235
|
+
crypto.getRandomValues(buf);
|
|
2236
|
+
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);
|
|
2237
|
+
if (value > 0) {
|
|
2238
|
+
return String(value);
|
|
2239
|
+
}
|
|
2240
|
+
} catch (unused) {}
|
|
2241
|
+
}
|
|
2242
|
+
return String(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1);
|
|
2243
|
+
}
|
|
2244
|
+
var UNEXPANDED_MACRO_PATTERN = /^(\[[^\]]*\]|\{[^}]*\}|%%[^%]*%%)$/;
|
|
2245
|
+
function applyVastMacros(baseUrl, ctx) {
|
|
2246
|
+
var url;
|
|
2247
|
+
try {
|
|
2248
|
+
url = new URL(baseUrl);
|
|
2249
|
+
} catch (unused) {
|
|
2250
|
+
return replaceCorrelatorFallback(baseUrl, ctx.correlator);
|
|
2251
|
+
}
|
|
2252
|
+
var params = url.searchParams;
|
|
2253
|
+
params.set("correlator", ctx.correlator);
|
|
2254
|
+
params.set("scor", ctx.streamCorrelator);
|
|
2255
|
+
if (ctx.pod != null) {
|
|
2256
|
+
params.set("pod", String(ctx.pod));
|
|
2257
|
+
}
|
|
2258
|
+
if (ctx.adPosition != null) {
|
|
2259
|
+
params.set("ppos", String(ctx.adPosition));
|
|
2260
|
+
}
|
|
2261
|
+
if (ctx.pageUrl) {
|
|
2262
|
+
params.set("url", ctx.pageUrl);
|
|
2263
|
+
params.set("description_url", ctx.pageUrl);
|
|
2264
|
+
}
|
|
2265
|
+
if (ctx.adWillPlayMuted != null) {
|
|
2266
|
+
params.set("vpmute", ctx.adWillPlayMuted ? "1" : "0");
|
|
2267
|
+
}
|
|
2268
|
+
if (ctx.adWillAutoPlay != null) {
|
|
2269
|
+
params.set("vpa", ctx.adWillAutoPlay ? "auto" : "click");
|
|
2270
|
+
}
|
|
2271
|
+
if (ctx.deviceId && ctx.deviceIdType) {
|
|
2272
|
+
params.set("rdid", ctx.deviceId);
|
|
2273
|
+
params.set("idtype", ctx.deviceIdType);
|
|
2274
|
+
params.set("is_lat", ctx.limitAdTracking ? "1" : "0");
|
|
2275
|
+
} else {
|
|
2276
|
+
params.delete("rdid");
|
|
2277
|
+
params.delete("idtype");
|
|
2278
|
+
params.delete("is_lat");
|
|
2279
|
+
}
|
|
2280
|
+
var consent = ctx.consent;
|
|
2281
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.gdpr) != null) {
|
|
2282
|
+
params.set("gdpr", consent.gdpr);
|
|
2283
|
+
}
|
|
2284
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.gdprConsent) != null) {
|
|
2285
|
+
params.set("gdpr_consent", consent.gdprConsent);
|
|
2286
|
+
}
|
|
2287
|
+
if ((consent === null || consent === void 0 ? void 0 : consent.usPrivacy) != null) {
|
|
2288
|
+
params.set("us_privacy", consent.usPrivacy);
|
|
2289
|
+
}
|
|
2290
|
+
if (ctx.adTest) {
|
|
2291
|
+
params.set("adtest", "on");
|
|
2292
|
+
}
|
|
2293
|
+
var staleKeys = [];
|
|
2294
|
+
params.forEach(function(value, key) {
|
|
2295
|
+
if (UNEXPANDED_MACRO_PATTERN.test(value)) {
|
|
2296
|
+
staleKeys.push(key);
|
|
2297
|
+
}
|
|
2298
|
+
});
|
|
2299
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2300
|
+
try {
|
|
2301
|
+
for(var _iterator = staleKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2302
|
+
var key = _step.value;
|
|
2303
|
+
params.delete(key);
|
|
2304
|
+
}
|
|
2305
|
+
} catch (err) {
|
|
2306
|
+
_didIteratorError = true;
|
|
2307
|
+
_iteratorError = err;
|
|
2308
|
+
} finally{
|
|
2309
|
+
try {
|
|
2310
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2311
|
+
_iterator.return();
|
|
2312
|
+
}
|
|
2313
|
+
} finally{
|
|
2314
|
+
if (_didIteratorError) {
|
|
2315
|
+
throw _iteratorError;
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
return url.toString();
|
|
2320
|
+
}
|
|
2321
|
+
function replaceCorrelatorFallback(baseUrl, correlator) {
|
|
2322
|
+
var correlatorRegex = /([?&])correlator=([^&]*)/;
|
|
2323
|
+
if (correlatorRegex.test(baseUrl)) {
|
|
2324
|
+
return baseUrl.replace(correlatorRegex, "$1correlator=".concat(correlator));
|
|
2325
|
+
}
|
|
2326
|
+
var sep = baseUrl.includes("?") ? "&" : "?";
|
|
2327
|
+
return "".concat(baseUrl).concat(sep, "correlator=").concat(correlator);
|
|
2328
|
+
}
|
|
2329
|
+
function fetchConsentSignals() {
|
|
2330
|
+
var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1500;
|
|
2331
|
+
var signals = {};
|
|
2332
|
+
if (typeof window === "undefined") {
|
|
2333
|
+
return Promise.resolve(signals);
|
|
2334
|
+
}
|
|
2335
|
+
var tasks = [];
|
|
2336
|
+
var tcfApi = window.__tcfapi;
|
|
2337
|
+
if (typeof tcfApi === "function") {
|
|
2338
|
+
tasks.push(new Promise(function(resolve) {
|
|
2339
|
+
var settled = false;
|
|
2340
|
+
try {
|
|
2341
|
+
tcfApi("addEventListener", 2, function(tcData, success) {
|
|
2342
|
+
if (settled) return;
|
|
2343
|
+
if (success && tcData && (tcData.eventStatus === "tcloaded" || tcData.eventStatus === "useractioncomplete")) {
|
|
2344
|
+
settled = true;
|
|
2345
|
+
signals.gdpr = tcData.gdprApplies ? "1" : "0";
|
|
2346
|
+
if (typeof tcData.tcString === "string" && tcData.tcString) {
|
|
2347
|
+
signals.gdprConsent = tcData.tcString;
|
|
2348
|
+
}
|
|
2349
|
+
try {
|
|
2350
|
+
tcfApi("removeEventListener", 2, function() {}, tcData.listenerId);
|
|
2351
|
+
} catch (unused) {}
|
|
2352
|
+
resolve();
|
|
2353
|
+
}
|
|
2354
|
+
});
|
|
2355
|
+
} catch (unused) {
|
|
2356
|
+
resolve();
|
|
2357
|
+
}
|
|
2358
|
+
setTimeout(function() {
|
|
2359
|
+
if (!settled) {
|
|
2360
|
+
settled = true;
|
|
2361
|
+
resolve();
|
|
2362
|
+
}
|
|
2363
|
+
}, timeoutMs);
|
|
2364
|
+
}));
|
|
2365
|
+
}
|
|
2366
|
+
var uspApi = window.__uspapi;
|
|
2367
|
+
if (typeof uspApi === "function") {
|
|
2368
|
+
tasks.push(new Promise(function(resolve) {
|
|
2369
|
+
try {
|
|
2370
|
+
uspApi("getUSPData", 1, function(data, success) {
|
|
2371
|
+
if (success && typeof (data === null || data === void 0 ? void 0 : data.uspString) === "string" && data.uspString) {
|
|
2372
|
+
signals.usPrivacy = data.uspString;
|
|
2373
|
+
}
|
|
2374
|
+
resolve();
|
|
2375
|
+
});
|
|
2376
|
+
} catch (unused) {
|
|
2377
|
+
resolve();
|
|
2378
|
+
}
|
|
2379
|
+
setTimeout(resolve, timeoutMs);
|
|
2380
|
+
}));
|
|
2381
|
+
}
|
|
2382
|
+
if (tasks.length === 0) {
|
|
2383
|
+
return Promise.resolve(signals);
|
|
2384
|
+
}
|
|
2385
|
+
return Promise.all(tasks).then(function() {
|
|
2386
|
+
return signals;
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2229
2389
|
// src/utils/browserCompat.ts
|
|
2230
2390
|
function getChromeVersion(ua) {
|
|
2231
2391
|
var match = ua.match(/Chrome\/(\d+)/);
|
|
@@ -2451,6 +2611,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2451
2611
|
this.preloadPoolLoopRunning = false;
|
|
2452
2612
|
this.adDetectSentForCurrentBreak = false;
|
|
2453
2613
|
this.palPlaybackStarted = false;
|
|
2614
|
+
this.streamCorrelator = generateCorrelator();
|
|
2615
|
+
this.consentSignals = {};
|
|
2616
|
+
this.podCounter = 0;
|
|
2617
|
+
this.podAssignedByPrefetch = false;
|
|
2618
|
+
this.adRequestPositionInBreak = 0;
|
|
2454
2619
|
this.continuousFetchLoopRunning = false;
|
|
2455
2620
|
initializePolyfills();
|
|
2456
2621
|
var browserOverrides = getBrowserConfigOverrides();
|
|
@@ -2523,6 +2688,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2523
2688
|
adWillPlayMuted: !!this.config.muted,
|
|
2524
2689
|
continuousPlayback: (_this_config_lowLatencyMode = this.config.lowLatencyMode) !== null && _this_config_lowLatencyMode !== void 0 ? _this_config_lowLatencyMode : false
|
|
2525
2690
|
}).catch(function() {});
|
|
2691
|
+
fetchConsentSignals().then(function(signals) {
|
|
2692
|
+
_this.consentSignals = signals;
|
|
2693
|
+
}).catch(function() {});
|
|
2526
2694
|
this.initializeTracking();
|
|
2527
2695
|
if (!this.shouldUseNativeHls()) return [
|
|
2528
2696
|
3,
|
|
@@ -4819,25 +4987,35 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4819
4987
|
return this.getRemainingAdMs();
|
|
4820
4988
|
}
|
|
4821
4989
|
},
|
|
4990
|
+
{
|
|
4991
|
+
key: "beginNewAdPod",
|
|
4992
|
+
value: function beginNewAdPod() {
|
|
4993
|
+
this.podCounter++;
|
|
4994
|
+
this.adRequestPositionInBreak = 0;
|
|
4995
|
+
}
|
|
4996
|
+
},
|
|
4822
4997
|
{
|
|
4823
4998
|
key: "generateVastUrlsWithCorrelators",
|
|
4824
4999
|
value: function generateVastUrlsWithCorrelators(baseUrl, count) {
|
|
4825
5000
|
var urls = [];
|
|
4826
|
-
var baseTimestamp = Date.now();
|
|
4827
5001
|
for(var i = 0; i < count; i++){
|
|
4828
|
-
|
|
4829
|
-
var
|
|
4830
|
-
var
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
5002
|
+
this.adRequestPositionInBreak++;
|
|
5003
|
+
var adWillPlayMuted = this.inAdBreak ? this.adPlayer.getOriginalMutedState() : this.video.muted;
|
|
5004
|
+
var urlWithMacros = applyVastMacros(baseUrl, {
|
|
5005
|
+
correlator: generateCorrelator(),
|
|
5006
|
+
streamCorrelator: this.streamCorrelator,
|
|
5007
|
+
pod: this.podCounter > 0 ? this.podCounter : void 0,
|
|
5008
|
+
adPosition: this.adRequestPositionInBreak,
|
|
5009
|
+
pageUrl: typeof window !== "undefined" ? window.location.href : void 0,
|
|
5010
|
+
adWillPlayMuted: adWillPlayMuted,
|
|
5011
|
+
adWillAutoPlay: !!this.config.autoplay,
|
|
5012
|
+
deviceId: this.config.deviceId,
|
|
5013
|
+
deviceIdType: this.config.deviceIdType,
|
|
5014
|
+
limitAdTracking: this.config.limitAdTracking,
|
|
5015
|
+
adTest: this.config.adTest,
|
|
5016
|
+
consent: this.consentSignals
|
|
5017
|
+
});
|
|
5018
|
+
urls.push(this.palNonce.injectNonce(urlWithMacros));
|
|
4841
5019
|
}
|
|
4842
5020
|
return urls;
|
|
4843
5021
|
}
|
|
@@ -4907,6 +5085,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4907
5085
|
}
|
|
4908
5086
|
return;
|
|
4909
5087
|
}
|
|
5088
|
+
this.beginNewAdPod();
|
|
5089
|
+
this.podAssignedByPrefetch = true;
|
|
4910
5090
|
var urlsToPregenerate = 5;
|
|
4911
5091
|
var generatedUrls = this.generateVastUrlsWithCorrelators(baseVastUrl, urlsToPregenerate);
|
|
4912
5092
|
this.pendingAdBreak = _object_spread_props(_object_spread({
|
|
@@ -4944,6 +5124,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4944
5124
|
}
|
|
4945
5125
|
this.pendingAdBreak = null;
|
|
4946
5126
|
this.pendingScte35CueKey = void 0;
|
|
5127
|
+
this.podAssignedByPrefetch = false;
|
|
4947
5128
|
}
|
|
4948
5129
|
},
|
|
4949
5130
|
{
|
|
@@ -5380,6 +5561,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5380
5561
|
this.continuousFetchingActive = true;
|
|
5381
5562
|
this.isShowingPlaceholder = false;
|
|
5382
5563
|
this.totalAdRequestsInBreak = 0;
|
|
5564
|
+
if (this.podAssignedByPrefetch) {
|
|
5565
|
+
this.podAssignedByPrefetch = false;
|
|
5566
|
+
} else {
|
|
5567
|
+
this.beginNewAdPod();
|
|
5568
|
+
}
|
|
5383
5569
|
currentMuted = this.video.muted;
|
|
5384
5570
|
currentVolume = this.video.volume;
|
|
5385
5571
|
this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
|