@streamlayer/feature-advertisement 1.1.0 → 1.1.1-rc.1343
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/classic/package.json +5 -0
- package/lib/advertisement.d.ts +6 -6
- package/lib/advertisement.js +8 -8
- package/lib/cjs/advertisement.d.ts +64 -0
- package/lib/cjs/advertisement.js +307 -0
- package/lib/cjs/index.d.ts +19 -0
- package/lib/cjs/index.js +39 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/units/external-ad.d.ts +58 -0
- package/lib/cjs/units/external-ad.js +390 -0
- package/lib/cjs/units/external-pause-ad.d.ts +50 -0
- package/lib/cjs/units/external-pause-ad.js +253 -0
- package/lib/cjs/units/gam.d.ts +16 -0
- package/lib/cjs/units/gam.js +104 -0
- package/lib/cjs/units/parse-vast-extensions.d.ts +17 -0
- package/lib/cjs/units/parse-vast-extensions.js +52 -0
- package/lib/cjs/units/pause-ad-card.d.ts +49 -0
- package/lib/cjs/units/pause-ad-card.js +136 -0
- package/lib/cjs/units/pause-ad.d.ts +16 -0
- package/lib/cjs/units/pause-ad.js +52 -0
- package/lib/cjs/units/ssai-ad-break.d.ts +21 -0
- package/lib/cjs/units/ssai-ad-break.js +11 -0
- package/lib/cjs/units/ssai-creative.d.ts +89 -0
- package/lib/cjs/units/ssai-creative.js +136 -0
- package/lib/cjs/units/ssai-detector.d.ts +180 -0
- package/lib/cjs/units/ssai-detector.js +1156 -0
- package/lib/cjs/units/ssai-preload.d.ts +20 -0
- package/lib/cjs/units/ssai-preload.js +62 -0
- package/lib/cjs/units/ssai-providers.d.ts +117 -0
- package/lib/cjs/units/ssai-providers.js +263 -0
- package/lib/cjs/units/vast-tracker.d.ts +45 -0
- package/lib/cjs/units/vast-tracker.js +64 -0
- package/lib/classic/_virtual/_rollupPluginBabelHelpers.js +71 -0
- package/lib/classic/advertisement.js +331 -0
- package/lib/classic/cjs/_virtual/_rollupPluginBabelHelpers.js +77 -0
- package/lib/classic/cjs/advertisement.js +333 -0
- package/lib/classic/cjs/index.js +47 -0
- package/lib/classic/cjs/package.json +1 -0
- package/lib/classic/cjs/units/external-ad.js +453 -0
- package/lib/classic/cjs/units/external-pause-ad.js +274 -0
- package/lib/classic/cjs/units/gam.js +110 -0
- package/lib/classic/cjs/units/parse-vast-extensions.js +56 -0
- package/lib/classic/cjs/units/pause-ad-card.js +134 -0
- package/lib/classic/cjs/units/pause-ad.js +72 -0
- package/lib/classic/cjs/units/ssai-ad-break.js +11 -0
- package/lib/classic/cjs/units/ssai-creative.js +142 -0
- package/lib/classic/cjs/units/ssai-detector.js +1170 -0
- package/lib/classic/cjs/units/ssai-preload.js +72 -0
- package/lib/classic/cjs/units/ssai-providers.js +299 -0
- package/lib/classic/cjs/units/vast-tracker.js +81 -0
- package/lib/classic/index.js +28 -0
- package/lib/classic/units/external-ad.js +447 -0
- package/lib/classic/units/external-pause-ad.js +271 -0
- package/lib/classic/units/gam.js +108 -0
- package/lib/classic/units/parse-vast-extensions.js +54 -0
- package/lib/classic/units/pause-ad-card.js +131 -0
- package/lib/classic/units/pause-ad.js +70 -0
- package/lib/classic/units/ssai-ad-break.js +9 -0
- package/lib/classic/units/ssai-creative.js +140 -0
- package/lib/classic/units/ssai-detector.js +1167 -0
- package/lib/classic/units/ssai-preload.js +68 -0
- package/lib/classic/units/ssai-providers.js +289 -0
- package/lib/classic/units/vast-tracker.js +77 -0
- package/lib/index.d.ts +13 -13
- package/lib/index.js +8 -8
- package/lib/units/external-ad.d.ts +2 -2
- package/lib/units/external-ad.js +2 -2
- package/lib/units/pause-ad.d.ts +1 -1
- package/lib/units/pause-ad.js +1 -1
- package/lib/units/ssai-ad-break.d.ts +1 -1
- package/lib/units/ssai-creative.d.ts +1 -1
- package/lib/units/ssai-creative.js +1 -1
- package/lib/units/ssai-detector.d.ts +1 -1
- package/lib/units/ssai-preload.d.ts +1 -1
- package/lib/units/ssai-providers.d.ts +1 -1
- package/lib/units/vast-tracker.d.ts +1 -1
- package/package.json +41 -8
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
|
|
4
|
+
require('core-js/modules/es.array.iterator.js');
|
|
5
|
+
require('core-js/modules/es.promise.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
require('core-js/modules/web.dom-collections.for-each.js');
|
|
9
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
10
|
+
var ssaiProviders = require('./ssai-providers.js');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Per-instance cache + impression-firing wrapper around a SsaiCreativeProvider.
|
|
14
|
+
* Caches resolved creatives by creativeId so repeated active-ad polls and pod
|
|
15
|
+
* repeats don't refetch. In-flight fetches are cancellable via AbortController.
|
|
16
|
+
*/
|
|
17
|
+
class SsaiCreativeCache {
|
|
18
|
+
constructor(provider) {
|
|
19
|
+
_rollupPluginBabelHelpers.defineProperty(this, "provider", void 0);
|
|
20
|
+
_rollupPluginBabelHelpers.defineProperty(this, "cache", new Map());
|
|
21
|
+
_rollupPluginBabelHelpers.defineProperty(this, "inflight", new Map());
|
|
22
|
+
/**
|
|
23
|
+
* The already-resolved creative, or undefined — synchronous on purpose: a
|
|
24
|
+
* prefetched creative lets the ad break flip straight to 'ready' with no
|
|
25
|
+
* async gap (which the UI would render as a blink between two ads of a pod).
|
|
26
|
+
*/
|
|
27
|
+
_rollupPluginBabelHelpers.defineProperty(this, "peek", creativeId => this.cache.get(creativeId));
|
|
28
|
+
_rollupPluginBabelHelpers.defineProperty(this, "resolve", creativeId => {
|
|
29
|
+
const cached = this.cache.get(creativeId);
|
|
30
|
+
if (cached) {
|
|
31
|
+
return Promise.resolve(cached);
|
|
32
|
+
}
|
|
33
|
+
const existing = this.inflight.get(creativeId);
|
|
34
|
+
if (existing) {
|
|
35
|
+
return existing.promise;
|
|
36
|
+
}
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const promise = this.provider.resolve(creativeId, controller.signal).then(creative => {
|
|
39
|
+
this.cache.set(creativeId, creative);
|
|
40
|
+
this.inflight.delete(creativeId);
|
|
41
|
+
return creative;
|
|
42
|
+
}).catch(error => {
|
|
43
|
+
this.inflight.delete(creativeId);
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
this.inflight.set(creativeId, {
|
|
47
|
+
promise,
|
|
48
|
+
controller
|
|
49
|
+
});
|
|
50
|
+
return promise;
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Cancel an in-flight fetch (e.g. the break ended before it resolved).
|
|
54
|
+
*/
|
|
55
|
+
_rollupPluginBabelHelpers.defineProperty(this, "cancel", creativeId => {
|
|
56
|
+
const existing = this.inflight.get(creativeId);
|
|
57
|
+
if (existing) {
|
|
58
|
+
existing.controller.abort();
|
|
59
|
+
this.inflight.delete(creativeId);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Fire the impression for a creative. Delegates to the provider's
|
|
64
|
+
* `fireImpression` when present, otherwise the shared default (first
|
|
65
|
+
* trackingEvent named 'impression' via sendBeacon/fetch). Called once per
|
|
66
|
+
* visible appearance of the bar (the UI dedupes the ~250ms active-poll so a
|
|
67
|
+
* single continuous appearance fires exactly one impression). Each genuine pod
|
|
68
|
+
* insertion of the same creative is a distinct impression and re-fires.
|
|
69
|
+
*/
|
|
70
|
+
_rollupPluginBabelHelpers.defineProperty(this, "fireImpression", creative => {
|
|
71
|
+
if (this.provider.fireImpression) {
|
|
72
|
+
this.provider.fireImpression(creative);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
ssaiProviders.fireDefaultImpression(creative);
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Fire the impression for an already-resolved creativeId. No-op if the
|
|
79
|
+
* creative isn't cached yet (the bar only renders once resolved, so by the
|
|
80
|
+
* time the UI calls this the creative is present).
|
|
81
|
+
*/
|
|
82
|
+
_rollupPluginBabelHelpers.defineProperty(this, "fireImpressionById", creativeId => {
|
|
83
|
+
const creative = this.cache.get(creativeId);
|
|
84
|
+
if (creative) {
|
|
85
|
+
this.fireImpression(creative);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* Fire a lifecycle / click beacon. Delegates to the provider's `fireTracking`
|
|
90
|
+
* when it defines one, otherwise fires every matching `trackingEvents` URL.
|
|
91
|
+
*/
|
|
92
|
+
_rollupPluginBabelHelpers.defineProperty(this, "fireTracking", (creative, event) => {
|
|
93
|
+
if (this.provider.fireTracking) {
|
|
94
|
+
this.provider.fireTracking(creative, event);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
ssaiProviders.fireTrackingEvents(creative, event);
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* Fire a beacon for a creativeId that may still be resolving.
|
|
101
|
+
*
|
|
102
|
+
* `start` in particular lands the instant the break opens, which is usually
|
|
103
|
+
* BEFORE the metadata request has come back — dropping it would silently lose
|
|
104
|
+
* the first beacon of every ad. Resolution is already in flight by then and
|
|
105
|
+
* `resolve` returns that same promise, so this attaches to it rather than
|
|
106
|
+
* issuing a second request. A creative that never resolves fires nothing,
|
|
107
|
+
* which is the correct outcome: there are no URLs to fire.
|
|
108
|
+
*/
|
|
109
|
+
_rollupPluginBabelHelpers.defineProperty(this, "fireTrackingById", (creativeId, event) => {
|
|
110
|
+
const cached = this.cache.get(creativeId);
|
|
111
|
+
if (cached) {
|
|
112
|
+
this.fireTracking(cached, event);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
this.resolve(creativeId).then(creative => this.fireTracking(creative, event)).catch(() => undefined);
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Fire the companion's `clickTracking` beacons. Separate from
|
|
119
|
+
* {@link fireTracking} because these live on the companion, not in
|
|
120
|
+
* `trackingEvents` — a provider's `fireTracking` override has no say over them.
|
|
121
|
+
*/
|
|
122
|
+
_rollupPluginBabelHelpers.defineProperty(this, "fireCompanionClickById", creativeId => {
|
|
123
|
+
var _this$cache$get;
|
|
124
|
+
const companion = (_this$cache$get = this.cache.get(creativeId)) === null || _this$cache$get === void 0 ? void 0 : _this$cache$get.companion;
|
|
125
|
+
if (!companion) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
for (const url of companion.clickTracking) {
|
|
129
|
+
ssaiProviders.fireBeacon(url);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
_rollupPluginBabelHelpers.defineProperty(this, "destroy", () => {
|
|
133
|
+
this.inflight.forEach(entry => entry.controller.abort());
|
|
134
|
+
this.inflight.clear();
|
|
135
|
+
this.cache.clear();
|
|
136
|
+
});
|
|
137
|
+
this.provider = provider;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
exports.DEFAULT_CREATIVE_API_BASE = ssaiProviders.DEFAULT_CREATIVE_API_BASE;
|
|
142
|
+
exports.SsaiCreativeCache = SsaiCreativeCache;
|