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