@camera.ui/browser 0.0.184 → 0.0.185
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.js +59 -39
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -419,9 +419,44 @@ var snapshotCache = /* @__PURE__ */ new Map();
|
|
|
419
419
|
var timestampCache = /* @__PURE__ */ new Map();
|
|
420
420
|
var urlCache = /* @__PURE__ */ new Map();
|
|
421
421
|
var subscribers = /* @__PURE__ */ new Map();
|
|
422
|
+
var pendingLoads$2 = /* @__PURE__ */ new Map();
|
|
422
423
|
function notify(cameraId) {
|
|
423
424
|
subscribers.get(cameraId)?.forEach((cb) => cb());
|
|
424
425
|
}
|
|
426
|
+
function fetchSnapshotShared(deviceManager, id, forceFresh = false) {
|
|
427
|
+
const pending = pendingLoads$2.get(id);
|
|
428
|
+
if (pending) return pending;
|
|
429
|
+
const promise = (async () => {
|
|
430
|
+
const device = await acquireCameraDevice(deviceManager, id);
|
|
431
|
+
try {
|
|
432
|
+
if (!device) return void 0;
|
|
433
|
+
const result = await device.fetchSnapshot(void 0, forceFresh ? true : void 0);
|
|
434
|
+
if (result) setSnapshot(id, result);
|
|
435
|
+
return result ?? void 0;
|
|
436
|
+
} finally {
|
|
437
|
+
if (device) releaseCameraDevice(id);
|
|
438
|
+
}
|
|
439
|
+
})().finally(() => pendingLoads$2.delete(id));
|
|
440
|
+
pendingLoads$2.set(id, promise);
|
|
441
|
+
return promise;
|
|
442
|
+
}
|
|
443
|
+
var reconnectHooked = false;
|
|
444
|
+
function hookReconnectRefresh(cameraUi, deviceManager) {
|
|
445
|
+
if (reconnectHooked) return;
|
|
446
|
+
reconnectHooked = true;
|
|
447
|
+
cameraUi.on("reconnected", () => {
|
|
448
|
+
let delay = 0;
|
|
449
|
+
for (const id of subscribers.keys()) {
|
|
450
|
+
if ((subscribers.get(id)?.size ?? 0) === 0) continue;
|
|
451
|
+
const cameraId = id;
|
|
452
|
+
setTimeout(() => {
|
|
453
|
+
if ((subscribers.get(cameraId)?.size ?? 0) === 0) return;
|
|
454
|
+
fetchSnapshotShared(deviceManager, cameraId).catch(() => void 0);
|
|
455
|
+
}, delay);
|
|
456
|
+
delay += 150;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
}
|
|
425
460
|
function deferRevoke(url) {
|
|
426
461
|
setTimeout(() => URL.revokeObjectURL(url), REVOKE_DELAY_MS);
|
|
427
462
|
}
|
|
@@ -468,6 +503,7 @@ function useSnapshot(cameraIdOrName) {
|
|
|
468
503
|
const snapshot = shallowRef();
|
|
469
504
|
const _isLoading = ref(false);
|
|
470
505
|
const initialLoadDone = ref(false);
|
|
506
|
+
hookReconnectRefresh(cameraUi, deviceManager);
|
|
471
507
|
const snapshotSrc = computed(() => {
|
|
472
508
|
if (!snapshot.value) return void 0;
|
|
473
509
|
const idOrName = toValue(cameraIdOrName);
|
|
@@ -524,18 +560,8 @@ function useSnapshot(cameraIdOrName) {
|
|
|
524
560
|
}
|
|
525
561
|
_isLoading.value = true;
|
|
526
562
|
try {
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
if (device) {
|
|
530
|
-
const result = await device.fetchSnapshot();
|
|
531
|
-
if (result) {
|
|
532
|
-
setSnapshot(id, result);
|
|
533
|
-
snapshot.value = result;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
} finally {
|
|
537
|
-
if (device) releaseCameraDevice(id);
|
|
538
|
-
}
|
|
563
|
+
const result = await fetchSnapshotShared(deviceManager, id);
|
|
564
|
+
if (result) snapshot.value = result;
|
|
539
565
|
} catch {} finally {
|
|
540
566
|
_isLoading.value = false;
|
|
541
567
|
initialLoadDone.value = true;
|
|
@@ -551,18 +577,8 @@ function useSnapshot(cameraIdOrName) {
|
|
|
551
577
|
if (isCameraDisabled(cameraIdName)) return;
|
|
552
578
|
_isLoading.value = true;
|
|
553
579
|
try {
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
if (device) {
|
|
557
|
-
const result = await device.fetchSnapshot(void 0, true);
|
|
558
|
-
if (result) {
|
|
559
|
-
setSnapshot(id, result);
|
|
560
|
-
snapshot.value = result;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
} finally {
|
|
564
|
-
if (device) releaseCameraDevice(id);
|
|
565
|
-
}
|
|
580
|
+
const result = await fetchSnapshotShared(deviceManager, id, true);
|
|
581
|
+
if (result) snapshot.value = result;
|
|
566
582
|
} catch {} finally {
|
|
567
583
|
_isLoading.value = false;
|
|
568
584
|
initialLoadDone.value = true;
|
|
@@ -589,15 +605,7 @@ function useSnapshot(cameraIdOrName) {
|
|
|
589
605
|
snapshot.value = void 0;
|
|
590
606
|
}
|
|
591
607
|
}, { immediate: true });
|
|
592
|
-
const onReconnected = () => {
|
|
593
|
-
const idOrName = toValue(cameraIdOrName);
|
|
594
|
-
if (isCameraDisabled(idOrName)) return;
|
|
595
|
-
const id = typeof idOrName === "string" ? idOrName : idOrName._id;
|
|
596
|
-
if (id) loadSnapshot(id, true);
|
|
597
|
-
};
|
|
598
|
-
cameraUi.on("reconnected", onReconnected);
|
|
599
608
|
tryOnScopeDispose(() => {
|
|
600
|
-
cameraUi.off("reconnected", onReconnected);
|
|
601
609
|
unsubscribe?.();
|
|
602
610
|
releaseHeldDevice();
|
|
603
611
|
});
|
|
@@ -1778,18 +1786,25 @@ function useClassifierSensors(camera) {
|
|
|
1778
1786
|
//#endregion
|
|
1779
1787
|
//#region src/composables/resolvePluginId.ts
|
|
1780
1788
|
var pluginIdCache = /* @__PURE__ */ new Map();
|
|
1789
|
+
var pendingResolves = /* @__PURE__ */ new Map();
|
|
1781
1790
|
function clearPluginIdCache() {
|
|
1782
1791
|
pluginIdCache.clear();
|
|
1783
1792
|
}
|
|
1784
1793
|
async function resolvePluginId(rpcRef, pluginName) {
|
|
1785
1794
|
const cached = pluginIdCache.get(pluginName);
|
|
1786
1795
|
if (cached) return cached;
|
|
1787
|
-
const
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1796
|
+
const pending = pendingResolves.get(pluginName);
|
|
1797
|
+
if (pending) return pending;
|
|
1798
|
+
const promise = (async () => {
|
|
1799
|
+
const namespaces = NamespaceManager.coreManagerNamespaces();
|
|
1800
|
+
const pluginInfo = await rpcCall(rpcRef, (rpc) => rpc.createProxy(namespaces.coreManagerRpc).getPlugin(pluginName));
|
|
1801
|
+
if (pluginInfo) {
|
|
1802
|
+
pluginIdCache.set(pluginName, pluginInfo.id);
|
|
1803
|
+
return pluginInfo.id;
|
|
1804
|
+
}
|
|
1805
|
+
})().finally(() => pendingResolves.delete(pluginName));
|
|
1806
|
+
pendingResolves.set(pluginName, promise);
|
|
1807
|
+
return promise;
|
|
1793
1808
|
}
|
|
1794
1809
|
//#endregion
|
|
1795
1810
|
//#region src/composables/useStorage.ts
|
|
@@ -1797,11 +1812,16 @@ function createReactiveStorage(proxy) {
|
|
|
1797
1812
|
const config = shallowRef();
|
|
1798
1813
|
const isLoading = ref(false);
|
|
1799
1814
|
const error = ref();
|
|
1815
|
+
let inFlightConfig = null;
|
|
1800
1816
|
async function getConfig() {
|
|
1817
|
+
if (inFlightConfig) return inFlightConfig;
|
|
1801
1818
|
isLoading.value = true;
|
|
1802
1819
|
error.value = void 0;
|
|
1803
1820
|
try {
|
|
1804
|
-
|
|
1821
|
+
inFlightConfig = proxy.getConfig().finally(() => {
|
|
1822
|
+
inFlightConfig = null;
|
|
1823
|
+
});
|
|
1824
|
+
config.value = await inFlightConfig;
|
|
1805
1825
|
return config.value;
|
|
1806
1826
|
} catch (err) {
|
|
1807
1827
|
error.value = err instanceof Error ? err : new Error(String(err));
|