@ziztechnology/dial-library 0.0.6 → 0.0.7
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.mjs +57 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2057,6 +2057,7 @@ const noop = () => {
|
|
|
2057
2057
|
//#endregion
|
|
2058
2058
|
//#region src/sensor/driving_expression_player.ts
|
|
2059
2059
|
const DEBUG_MODULE = "driving_expression_player.ts";
|
|
2060
|
+
const MAX_RETAINED_IMAGES = 3;
|
|
2060
2061
|
const createDrivingExpressionPlayer = (container, options) => {
|
|
2061
2062
|
dialSdkDebugWarn(DEBUG_MODULE, "createDrivingExpressionPlayer", "called", {
|
|
2062
2063
|
container,
|
|
@@ -2086,6 +2087,8 @@ var DefaultDrivingExpressionPlayer = class {
|
|
|
2086
2087
|
this.reusableVideo = null;
|
|
2087
2088
|
this.activeTgs = null;
|
|
2088
2089
|
this.unsubscribePageLifecycle = null;
|
|
2090
|
+
this.retainedImages = /* @__PURE__ */ new Map();
|
|
2091
|
+
this.preloadedHintUrls = /* @__PURE__ */ new Set();
|
|
2089
2092
|
this.handleLifecyclePause = () => {
|
|
2090
2093
|
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleLifecyclePause", "called");
|
|
2091
2094
|
if (this.destroyed || this.lifecycleSuspended) {
|
|
@@ -2215,6 +2218,8 @@ var DefaultDrivingExpressionPlayer = class {
|
|
|
2215
2218
|
this.failedOperation = null;
|
|
2216
2219
|
this.cancelPendingWork();
|
|
2217
2220
|
this.releaseActiveMedia();
|
|
2221
|
+
this.clearRetainedImages();
|
|
2222
|
+
this.preloadedHintUrls.clear();
|
|
2218
2223
|
this.container.replaceChildren();
|
|
2219
2224
|
this.status = null;
|
|
2220
2225
|
this.desiredMedia = null;
|
|
@@ -2315,8 +2320,7 @@ var DefaultDrivingExpressionPlayer = class {
|
|
|
2315
2320
|
try {
|
|
2316
2321
|
switch (media.kind) {
|
|
2317
2322
|
case "image":
|
|
2318
|
-
this.
|
|
2319
|
-
await this.loadImage(media.url, loadAbort.signal, operation);
|
|
2323
|
+
await this.loadImage(status, media, loadAbort.signal, operation);
|
|
2320
2324
|
break;
|
|
2321
2325
|
case "video":
|
|
2322
2326
|
this.renderLoadingPlaceholder(status, media.coverUrl, operation, loadAbort.signal);
|
|
@@ -2361,12 +2365,27 @@ var DefaultDrivingExpressionPlayer = class {
|
|
|
2361
2365
|
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "completed", { operation });
|
|
2362
2366
|
}
|
|
2363
2367
|
}
|
|
2364
|
-
async loadImage(
|
|
2368
|
+
async loadImage(status, media, signal, operation) {
|
|
2369
|
+
const { url } = media;
|
|
2365
2370
|
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "called", {
|
|
2366
|
-
|
|
2371
|
+
status,
|
|
2372
|
+
media,
|
|
2367
2373
|
signal,
|
|
2368
2374
|
operation
|
|
2369
2375
|
});
|
|
2376
|
+
if (isRetainableImage(media)) {
|
|
2377
|
+
const retained = this.takeRetainedImage(url);
|
|
2378
|
+
if (retained !== null) {
|
|
2379
|
+
this.container.replaceChildren(retained);
|
|
2380
|
+
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "resolved retained image", {
|
|
2381
|
+
url,
|
|
2382
|
+
operation,
|
|
2383
|
+
image: retained
|
|
2384
|
+
});
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
this.renderConfiguredFallback(status, false);
|
|
2370
2389
|
const image = this.createImage();
|
|
2371
2390
|
await waitForElementEvent(image, "load", "error", signal, this.loadTimeoutMs, () => {
|
|
2372
2391
|
image.src = url;
|
|
@@ -2375,6 +2394,7 @@ var DefaultDrivingExpressionPlayer = class {
|
|
|
2375
2394
|
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "discarded", { operation });
|
|
2376
2395
|
return;
|
|
2377
2396
|
}
|
|
2397
|
+
if (isRetainableImage(media)) this.retainImage(url, image);
|
|
2378
2398
|
this.container.replaceChildren(image);
|
|
2379
2399
|
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "resolved", {
|
|
2380
2400
|
url,
|
|
@@ -2382,6 +2402,29 @@ var DefaultDrivingExpressionPlayer = class {
|
|
|
2382
2402
|
image
|
|
2383
2403
|
});
|
|
2384
2404
|
}
|
|
2405
|
+
takeRetainedImage(url) {
|
|
2406
|
+
const image = this.retainedImages.get(url) ?? null;
|
|
2407
|
+
if (image === null) return null;
|
|
2408
|
+
this.retainedImages.delete(url);
|
|
2409
|
+
this.retainedImages.set(url, image);
|
|
2410
|
+
return image;
|
|
2411
|
+
}
|
|
2412
|
+
retainImage(url, image) {
|
|
2413
|
+
const previous = this.retainedImages.get(url);
|
|
2414
|
+
if (previous && previous !== image) previous.removeAttribute("src");
|
|
2415
|
+
this.retainedImages.delete(url);
|
|
2416
|
+
this.retainedImages.set(url, image);
|
|
2417
|
+
while (this.retainedImages.size > MAX_RETAINED_IMAGES) {
|
|
2418
|
+
const oldest = this.retainedImages.entries().next().value;
|
|
2419
|
+
if (!oldest) break;
|
|
2420
|
+
this.retainedImages.delete(oldest[0]);
|
|
2421
|
+
oldest[1].removeAttribute("src");
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
clearRetainedImages() {
|
|
2425
|
+
for (const image of this.retainedImages.values()) image.removeAttribute("src");
|
|
2426
|
+
this.retainedImages.clear();
|
|
2427
|
+
}
|
|
2385
2428
|
async loadVideo(url, mimeType, status, media, signal, operation) {
|
|
2386
2429
|
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadVideo", "called", {
|
|
2387
2430
|
url,
|
|
@@ -2705,11 +2748,13 @@ var DefaultDrivingExpressionPlayer = class {
|
|
|
2705
2748
|
const media = normalizeMedia(configured);
|
|
2706
2749
|
const hintUrl = mediaPreloadHint(media);
|
|
2707
2750
|
if (!hintUrl || !isPublicDrivingMediaUrl(hintUrl)) continue;
|
|
2751
|
+
if (this.preloadedHintUrls.has(hintUrl) || this.retainedImages.has(hintUrl)) continue;
|
|
2708
2752
|
try {
|
|
2709
2753
|
const image = this.createImage();
|
|
2710
2754
|
await waitForElementEvent(image, "load", "error", preloadAbort.signal, this.loadTimeoutMs, () => {
|
|
2711
2755
|
image.src = hintUrl;
|
|
2712
2756
|
});
|
|
2757
|
+
this.preloadedHintUrls.add(hintUrl);
|
|
2713
2758
|
image.removeAttribute("src");
|
|
2714
2759
|
dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading.worker", "preloaded", {
|
|
2715
2760
|
status,
|
|
@@ -2917,6 +2962,14 @@ const normalizeMedia = (media) => {
|
|
|
2917
2962
|
});
|
|
2918
2963
|
return result;
|
|
2919
2964
|
};
|
|
2965
|
+
const isRetainableImage = (media) => {
|
|
2966
|
+
if (media.mimeType?.split(";", 1)[0]?.trim().toLowerCase() === "image/gif") return false;
|
|
2967
|
+
try {
|
|
2968
|
+
return !new URL(media.url).pathname.toLowerCase().endsWith(".gif");
|
|
2969
|
+
} catch {
|
|
2970
|
+
return false;
|
|
2971
|
+
}
|
|
2972
|
+
};
|
|
2920
2973
|
const firstInvalidMediaUrl = (media) => {
|
|
2921
2974
|
dialSdkDebugWarn(DEBUG_MODULE, "firstInvalidMediaUrl", "called", { media });
|
|
2922
2975
|
let values;
|