@trillboards/ads-sdk 2.2.1 → 2.3.1
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.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +66 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -6
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +66 -6
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +66 -6
- package/dist/react.mjs.map +1 -1
- package/dist/trillboards-lite.global.js +1 -1
- package/dist/trillboards-lite.global.js.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -321,10 +321,17 @@ var ApiClient = class {
|
|
|
321
321
|
}
|
|
322
322
|
const data = await response.json();
|
|
323
323
|
const newEtag = response.headers.get("ETag");
|
|
324
|
+
const hbs = data.data?.header_bidding_settings;
|
|
324
325
|
const result = {
|
|
325
326
|
ads: data.data?.ads ?? [],
|
|
326
327
|
settings: data.data?.settings ?? {},
|
|
327
|
-
programmatic:
|
|
328
|
+
programmatic: hbs ? {
|
|
329
|
+
...hbs,
|
|
330
|
+
sources: (hbs.vast_waterfall?.sources ?? []).map((s) => ({
|
|
331
|
+
...s,
|
|
332
|
+
enabled: s.enabled !== false
|
|
333
|
+
}))
|
|
334
|
+
} : null,
|
|
328
335
|
screenId: data.data?.screen_id ?? null,
|
|
329
336
|
screenOrientation: data.data?.screen_orientation ?? null,
|
|
330
337
|
screenDimensions: data.data?.screen_dimensions ?? null,
|
|
@@ -922,7 +929,7 @@ var WaterfallEngine = class {
|
|
|
922
929
|
*/
|
|
923
930
|
getNextSource(sources) {
|
|
924
931
|
if (!sources || sources.length === 0) return null;
|
|
925
|
-
const sorted = [...sources].filter((s) => s.enabled).sort((a, b) => a.priority - b.priority || Math.random() - 0.5);
|
|
932
|
+
const sorted = [...sources].filter((s) => s.enabled !== false).sort((a, b) => a.priority - b.priority || Math.random() - 0.5);
|
|
926
933
|
for (const source of sorted) {
|
|
927
934
|
if (this.circuitBreaker.isAvailable(source.name)) {
|
|
928
935
|
return { source, vastUrl: source.vast_url };
|
|
@@ -937,7 +944,7 @@ var WaterfallEngine = class {
|
|
|
937
944
|
*/
|
|
938
945
|
getAvailableSources(sources) {
|
|
939
946
|
if (!sources || sources.length === 0) return [];
|
|
940
|
-
return sources.filter((s) => s.enabled && this.circuitBreaker.isAvailable(s.name)).sort((a, b) => a.priority - b.priority || Math.random() - 0.5).map((source) => ({ source, vastUrl: source.vast_url }));
|
|
947
|
+
return sources.filter((s) => s.enabled !== false && this.circuitBreaker.isAvailable(s.name)).sort((a, b) => a.priority - b.priority || Math.random() - 0.5).map((source) => ({ source, vastUrl: source.vast_url }));
|
|
941
948
|
}
|
|
942
949
|
/** Record a successful ad fill for a source. */
|
|
943
950
|
recordSuccess(sourceName) {
|
|
@@ -950,7 +957,7 @@ var WaterfallEngine = class {
|
|
|
950
957
|
};
|
|
951
958
|
|
|
952
959
|
// src/player/ProgrammaticPlayer.ts
|
|
953
|
-
var
|
|
960
|
+
var _ProgrammaticPlayer = class _ProgrammaticPlayer {
|
|
954
961
|
constructor(events, timeoutMs = 12e3) {
|
|
955
962
|
// ── Public state ──────────────────────────────────────────
|
|
956
963
|
this.vastTagUrl = null;
|
|
@@ -1037,8 +1044,11 @@ var ProgrammaticPlayer = class {
|
|
|
1037
1044
|
this.telemetry.recordRequest();
|
|
1038
1045
|
const correlator = Date.now();
|
|
1039
1046
|
const finalUrl = vastUrl.includes("correlator=") ? vastUrl.replace(/correlator=[^&]*/, `correlator=${correlator}`) : `${vastUrl}${vastUrl.includes("?") ? "&" : "?"}correlator=${correlator}`;
|
|
1040
|
-
|
|
1041
|
-
|
|
1047
|
+
const imaReady = await this.ensureImaSdk();
|
|
1048
|
+
if (!imaReady) {
|
|
1049
|
+
const msg = "Google IMA SDK not loaded";
|
|
1050
|
+
this.events.emit("programmatic_error", { error: msg, code: void 0 });
|
|
1051
|
+
onError(msg);
|
|
1042
1052
|
this.telemetry.recordError();
|
|
1043
1053
|
this.waterfallEngine.recordFailure(sourceName);
|
|
1044
1054
|
return;
|
|
@@ -1055,6 +1065,50 @@ var ProgrammaticPlayer = class {
|
|
|
1055
1065
|
onError(err instanceof Error ? err.message : String(err));
|
|
1056
1066
|
}
|
|
1057
1067
|
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Ensure Google IMA SDK is available. If already loaded, resolves
|
|
1070
|
+
* immediately. Otherwise injects the `<script>` tag and waits.
|
|
1071
|
+
* Matches the Lite SDK's `loadImaScript()` pattern.
|
|
1072
|
+
*/
|
|
1073
|
+
async ensureImaSdk() {
|
|
1074
|
+
if (typeof google !== "undefined" && google?.ima) return true;
|
|
1075
|
+
if (typeof document === "undefined") return false;
|
|
1076
|
+
const existing = document.querySelector(
|
|
1077
|
+
`script[src="${_ProgrammaticPlayer.IMA_SDK_URL}"]`
|
|
1078
|
+
);
|
|
1079
|
+
if (existing) {
|
|
1080
|
+
return new Promise((resolve) => {
|
|
1081
|
+
const start = Date.now();
|
|
1082
|
+
const check = () => {
|
|
1083
|
+
if (typeof google !== "undefined" && google?.ima) {
|
|
1084
|
+
resolve(true);
|
|
1085
|
+
} else if (Date.now() - start > 5e3) {
|
|
1086
|
+
resolve(false);
|
|
1087
|
+
} else {
|
|
1088
|
+
setTimeout(check, 100);
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
check();
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
if (!_ProgrammaticPlayer.imaLoadPromise) {
|
|
1095
|
+
_ProgrammaticPlayer.imaLoadPromise = new Promise((resolve) => {
|
|
1096
|
+
const script = document.createElement("script");
|
|
1097
|
+
script.src = _ProgrammaticPlayer.IMA_SDK_URL;
|
|
1098
|
+
script.async = true;
|
|
1099
|
+
script.onload = () => {
|
|
1100
|
+
_ProgrammaticPlayer.imaLoadPromise = null;
|
|
1101
|
+
resolve(true);
|
|
1102
|
+
};
|
|
1103
|
+
script.onerror = () => {
|
|
1104
|
+
_ProgrammaticPlayer.imaLoadPromise = null;
|
|
1105
|
+
resolve(false);
|
|
1106
|
+
};
|
|
1107
|
+
document.head.appendChild(script);
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
return _ProgrammaticPlayer.imaLoadPromise;
|
|
1111
|
+
}
|
|
1058
1112
|
// ── IMA request / playback lifecycle ──────────────────────
|
|
1059
1113
|
async requestAdsViaIMA(vastUrl, onComplete, onError) {
|
|
1060
1114
|
return new Promise((resolve) => {
|
|
@@ -1256,6 +1310,12 @@ var ProgrammaticPlayer = class {
|
|
|
1256
1310
|
this.telemetry.reset();
|
|
1257
1311
|
}
|
|
1258
1312
|
};
|
|
1313
|
+
// ── IMA SDK loader ──────────────────────────────────────────
|
|
1314
|
+
/** IMA script URL */
|
|
1315
|
+
_ProgrammaticPlayer.IMA_SDK_URL = "https://imasdk.googleapis.com/js/sdkloader/ima3.js";
|
|
1316
|
+
/** Singleton load promise so concurrent calls don't insert multiple scripts. */
|
|
1317
|
+
_ProgrammaticPlayer.imaLoadPromise = null;
|
|
1318
|
+
var ProgrammaticPlayer = _ProgrammaticPlayer;
|
|
1259
1319
|
|
|
1260
1320
|
// src/player/Player.ts
|
|
1261
1321
|
var MAX_AD_DURATION_SECONDS = 300;
|