@xiboplayer/cache 0.6.2 → 0.6.3
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/package.json +2 -2
- package/src/widget-html.js +13 -0
- package/src/widget-html.test.js +34 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiboplayer/cache",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Offline caching and download management with parallel chunk downloads",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"spark-md5": "^3.0.2",
|
|
19
|
-
"@xiboplayer/utils": "0.6.
|
|
19
|
+
"@xiboplayer/utils": "0.6.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"vitest": "^2.0.0",
|
package/src/widget-html.js
CHANGED
|
@@ -70,6 +70,19 @@ export async function cacheWidgetHtml(layoutId, regionId, mediaId, html) {
|
|
|
70
70
|
(_, path) => path
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
+
// Inject xiboICTargetId — XIC library reads this global before its IIFE runs
|
|
74
|
+
// to set _lib.targetId, which is included in every IC HTTP request as {id: ...}
|
|
75
|
+
if (!modifiedHtml.includes('xiboICTargetId')) {
|
|
76
|
+
const targetIdScript = `<script>var xiboICTargetId = '${mediaId}';</script>`;
|
|
77
|
+
if (modifiedHtml.includes(baseTag)) {
|
|
78
|
+
modifiedHtml = modifiedHtml.replace(baseTag, baseTag + targetIdScript);
|
|
79
|
+
} else if (modifiedHtml.includes('<head>')) {
|
|
80
|
+
modifiedHtml = modifiedHtml.replace('<head>', '<head>' + targetIdScript);
|
|
81
|
+
} else {
|
|
82
|
+
modifiedHtml = targetIdScript + modifiedHtml;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
73
86
|
// Rewrite Interactive Control hostAddress to SW-interceptable path
|
|
74
87
|
modifiedHtml = modifiedHtml.replace(
|
|
75
88
|
/hostAddress\s*:\s*["']https?:\/\/[^"']+["']/g,
|
package/src/widget-html.test.js
CHANGED
|
@@ -173,6 +173,40 @@ describe('cacheWidgetHtml', () => {
|
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
+
// --- xiboICTargetId injection ---
|
|
177
|
+
|
|
178
|
+
describe('xiboICTargetId injection', () => {
|
|
179
|
+
it('injects xiboICTargetId script with the media ID', async () => {
|
|
180
|
+
await cacheWidgetHtml('472', '223', '193', makeRssTickerHtml());
|
|
181
|
+
|
|
182
|
+
const stored = getStoredWidget();
|
|
183
|
+
expect(stored).toContain("var xiboICTargetId = '193'");
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('injects before XIC library script', async () => {
|
|
187
|
+
await cacheWidgetHtml('472', '223', '193', makeRssTickerHtml());
|
|
188
|
+
|
|
189
|
+
const stored = getStoredWidget();
|
|
190
|
+
const targetIdPos = stored.indexOf('xiboICTargetId');
|
|
191
|
+
const xicInitPos = stored.indexOf('xiboIC.init');
|
|
192
|
+
expect(targetIdPos).toBeLessThan(xicInitPos);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('is idempotent (no double injection)', async () => {
|
|
196
|
+
await cacheWidgetHtml('472', '223', '193', makeRssTickerHtml());
|
|
197
|
+
const firstPass = getStoredWidget();
|
|
198
|
+
|
|
199
|
+
storeContents.clear();
|
|
200
|
+
await cacheWidgetHtml('472', '223', '193', firstPass);
|
|
201
|
+
const secondPass = getStoredWidget();
|
|
202
|
+
|
|
203
|
+
const count = (secondPass.match(/xiboICTargetId/g) || []).length;
|
|
204
|
+
// 1 in the injected script + 1 in the original xiboIC.init options (if any)
|
|
205
|
+
// But the original HTML doesn't have xiboICTargetId, so count should be exactly 1
|
|
206
|
+
expect(count).toBe(1);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
176
210
|
// --- CSS object-position fix ---
|
|
177
211
|
|
|
178
212
|
describe('CSS object-position fix', () => {
|