@xiboplayer/cache 0.6.4 → 0.6.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiboplayer/cache",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
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.4"
19
+ "@xiboplayer/utils": "0.6.6"
20
20
  },
21
21
  "devDependencies": {
22
22
  "vitest": "^2.0.0",
@@ -488,12 +488,18 @@ describe('FileDownload - Progressive Streaming', () => {
488
488
  chunkCalls.push({ index, size: blob.size, total });
489
489
  });
490
490
 
491
+ // Process tasks sequentially — onTaskComplete is async (awaits
492
+ // onChunkDownloaded), so concurrent fire-and-forget causes _resolve()
493
+ // to race ahead of pending callbacks.
491
494
  const mockQueue = {
492
- enqueueChunkTasks: vi.fn((tasks) => {
495
+ enqueueChunkTasks: vi.fn(async (tasks) => {
493
496
  for (const task of tasks) {
494
- task.start()
495
- .then(() => task._parentFile.onTaskComplete(task))
496
- .catch(err => task._parentFile.onTaskFailed(task, err));
497
+ try {
498
+ await task.start();
499
+ await task._parentFile.onTaskComplete(task);
500
+ } catch (err) {
501
+ task._parentFile.onTaskFailed(task, err);
502
+ }
497
503
  }
498
504
  })
499
505
  };
package/src/test-utils.js CHANGED
@@ -103,13 +103,23 @@ export function mockChunkedFetch(sourceBlob) {
103
103
  * Create test blob of specified size
104
104
  */
105
105
  export function createTestBlob(size = 1024, type = 'application/octet-stream') {
106
- const buffer = new ArrayBuffer(size);
107
- // Fill with non-zero data so chunks are distinguishable
108
- const view = new Uint8Array(buffer);
109
- for (let i = 0; i < size; i++) {
110
- view[i] = i % 256;
106
+ // For large blobs, repeat a small pattern to avoid allocating huge ArrayBuffers
107
+ const CHUNK = 64 * 1024; // 64KB pattern block
108
+ const pattern = new Uint8Array(Math.min(size, CHUNK));
109
+ for (let i = 0; i < pattern.length; i++) {
110
+ pattern[i] = i % 256;
111
111
  }
112
- return new Blob([buffer], { type });
112
+ if (size <= CHUNK) {
113
+ return new Blob([pattern.slice(0, size)], { type });
114
+ }
115
+ const parts = [];
116
+ let remaining = size;
117
+ while (remaining > 0) {
118
+ const len = Math.min(remaining, CHUNK);
119
+ parts.push(len === CHUNK ? pattern : pattern.slice(0, len));
120
+ remaining -= len;
121
+ }
122
+ return new Blob(parts, { type });
113
123
  }
114
124
 
115
125
  /**
@@ -62,6 +62,15 @@ export async function cacheWidgetHtml(layoutId, regionId, mediaId, html) {
62
62
  }
63
63
  }
64
64
 
65
+ // Replace CMS placeholders left for "client-side SDK handling"
66
+ modifiedHtml = modifiedHtml.replace(/\[\[ViewPortWidth]]/g, 'device-width');
67
+
68
+ // Route HLS streams through local proxy (adds CORS headers, rewrites segments)
69
+ modifiedHtml = modifiedHtml.replace(
70
+ /https?:\/\/[^\s"')<]+\.m3u8\b/gi,
71
+ (url) => '/stream-proxy?url=' + encodeURIComponent(url)
72
+ );
73
+
65
74
  // Rewrite dependency URLs to local mirror paths. CMS sends absolute URLs
66
75
  // like https://cms.example.com${PLAYER_API}/dependencies/bundle.min.js
67
76
  // which fail due to CORS/auth. Replace with local PLAYER_API/dependencies/...