@octane-xplat/camera 0.13.0 → 0.14.0
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/README.md +63 -3
- package/dist/linux/CameraView.web.tsrx.js +337 -0
- package/dist/linux/host-movie.web.js +100 -0
- package/dist/linux/index.js +5 -0
- package/dist/linux/layout-child.web.js +29 -0
- package/dist/linux/movie-metadata.web.js +65 -0
- package/dist/linux/octane-client-build.json +8 -0
- package/dist/linux/session-backend.linux.js +479 -0
- package/dist/linux/session-core.js +368 -0
- package/dist/linux/session.js +29 -0
- package/dist/linux/synthetic-session.js +280 -0
- package/dist/linux/types.js +19 -0
- package/dist/native/CameraView.android.js +25 -1
- package/dist/native/CameraView.ios.js +24 -1
- package/dist/native/CameraView.windows.js +173 -0
- package/dist/native/camera-permission.windows.js +43 -0
- package/dist/native/camera-session.windows.js +78 -0
- package/dist/native/cx.windows.js +9 -0
- package/dist/native/index.js +4 -1
- package/dist/native/layout-child.windows.js +53 -0
- package/dist/native/octane-client-build.json +1 -1
- package/dist/native/session-backend.android.js +234 -0
- package/dist/native/session-backend.ios.js +682 -0
- package/dist/native/session-backend.js +55 -0
- package/dist/native/session-backend.windows.js +905 -0
- package/dist/native/session-core.js +368 -0
- package/dist/native/session.js +29 -0
- package/dist/native/synthetic-session.js +280 -0
- package/dist/native/types.js +19 -0
- package/dist/web/CameraView.web.tsrx.js +27 -7
- package/dist/web/host-movie.web.js +100 -0
- package/dist/web/index.js +4 -1
- package/dist/web/movie-metadata.web.js +65 -0
- package/dist/web/movie-storage.web.js +119 -0
- package/dist/web/octane-client-build.json +1 -1
- package/dist/web/session-backend.web.js +490 -0
- package/dist/web/session-core.js +368 -0
- package/dist/web/session.js +29 -0
- package/dist/web/synthetic-session.js +280 -0
- package/dist/web/types.js +19 -0
- package/package.json +22 -4
- package/platforms/android/AndroidManifest.xml +2 -0
- package/platforms/android/include.gradle +1 -0
- package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +4 -0
- package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +363 -0
- package/platforms/ios/Info.plist +2 -0
- package/platforms/macos/src/XplatCameraHost.swift +513 -0
- package/src/CameraView.android.tsrx +21 -1
- package/src/CameraView.ios.tsrx +28 -2
- package/src/CameraView.macos.tsrx +93 -0
- package/src/CameraView.web.tsrx +20 -2
- package/src/CameraView.windows.tsrx +124 -0
- package/src/camera-permission.windows.ts +76 -0
- package/src/camera-session.macos.ts +75 -0
- package/src/camera-session.windows.ts +123 -0
- package/src/cx.macos.ts +5 -0
- package/src/cx.windows.ts +6 -0
- package/src/host-movie.web.ts +180 -0
- package/src/index.ts +31 -0
- package/src/index.web.ts +31 -0
- package/src/layout-child.windows.ts +79 -0
- package/src/movie-metadata.web.ts +84 -0
- package/src/movie-storage.web.ts +164 -0
- package/src/props.ts +7 -1
- package/src/session-backend.android.ts +397 -0
- package/src/session-backend.ios.ts +1092 -0
- package/src/session-backend.linux.ts +869 -0
- package/src/session-backend.macos.ts +624 -0
- package/src/session-backend.ts +57 -0
- package/src/session-backend.web.ts +874 -0
- package/src/session-backend.windows.ts +1517 -0
- package/src/session-core.ts +659 -0
- package/src/session.ts +37 -0
- package/src/synthetic-session.ts +367 -0
- package/src/types.ts +329 -0
- package/types/index.d.ts +43 -0
- package/types/props.d.ts +7 -1
- package/types/session-core.d.ts +129 -0
- package/types/synthetic-session.d.ts +48 -0
- package/types/types.d.ts +263 -0
- package/src/CameraView.windows.ts +0 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attachSessionPreview } from "./session.js";
|
|
1
2
|
import { applyEscapeProps, layoutChildProps } from "./layout-child.web.js";
|
|
2
3
|
import { __s, bag15, bag5, child, clone, delegateEvents, evt2e, evt2u, hookSlots, ifBlock, markDangerouslySetInnerHTMLChildren, queueRefAttach, queueRefDetach, setStyleProperty, snapshotSpread, template, useEffect, useImperativeHandle, useRef } from "octane";
|
|
3
4
|
import { bindSignalHostPropSources, enableSignalBindings, replaceRef, setAttributeIfChanged } from "octane/internal/client";
|
|
@@ -7,8 +8,8 @@ delegateEvents(["playing"]);
|
|
|
7
8
|
var _t$0 = /* @__PURE__ */ template("<video autoplay=\"\" playsinline=\"\" style=\"display: block; width: 100%; height: 100%; object-fit: cover;\"></video>");
|
|
8
9
|
var _t$1 = /* @__PURE__ */ template("<div><!></div>");
|
|
9
10
|
var _hs$ = /* @__PURE__ */ hookSlots(5);
|
|
10
|
-
var __event = (__eventArg,
|
|
11
|
-
if (readyFired.current) return;
|
|
11
|
+
var __event = (__eventArg, props, readyFired) => {
|
|
12
|
+
if (props.session || readyFired.current) return;
|
|
12
13
|
readyFired.current = true;
|
|
13
14
|
props.onReady?.();
|
|
14
15
|
};
|
|
@@ -34,7 +35,7 @@ function __then$0(__props, __s, __extra) {
|
|
|
34
35
|
applyEscapeProps(element, props);
|
|
35
36
|
}, _root);
|
|
36
37
|
(__s.cleanups ??= []).push(() => _b && queueRefDetach(_b.b, _b.a));
|
|
37
|
-
_m4 = evt2e(_root, "$oplaying", __event,
|
|
38
|
+
_m4 = evt2e(_root, "$oplaying", __event, props, readyFired);
|
|
38
39
|
_b = bag5(__s, _root, _root, _m1, void 0, __s, _m4);
|
|
39
40
|
__s.refFields = _rm$1;
|
|
40
41
|
} else {
|
|
@@ -47,7 +48,7 @@ function __then$0(__props, __s, __extra) {
|
|
|
47
48
|
};
|
|
48
49
|
if (_r !== _b.b) _b.b = replaceRef(__s, _b.b, _r, _b.a);
|
|
49
50
|
}
|
|
50
|
-
evt2u(_b.e, __event,
|
|
51
|
+
evt2u(_b.e, __event, props, readyFired);
|
|
51
52
|
}
|
|
52
53
|
_b.c = setAttributeIfChanged(true, _b.c, _b.a, "muted");
|
|
53
54
|
{
|
|
@@ -72,6 +73,21 @@ var CameraView = /* @__PURE__ */ __s(function CameraView(props, __s, __extra) {
|
|
|
72
73
|
useEffect(() => {
|
|
73
74
|
const element = video.current;
|
|
74
75
|
if (!element || !active) return;
|
|
76
|
+
if (props.session) {
|
|
77
|
+
if (props.facing !== void 0) {
|
|
78
|
+
props.onError?.({ message: "camera session conflicts with facing" });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return attachSessionPreview(props.session, element, {
|
|
83
|
+
onReady: props.onReady,
|
|
84
|
+
onError: (issue) => props.onError?.({ message: issue.message })
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
props.onError?.({ message: error?.message ?? "camera session error" });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
75
91
|
const mediaDevices = navigator.mediaDevices;
|
|
76
92
|
if (!mediaDevices?.getUserMedia) {
|
|
77
93
|
props.onError?.({ message: "camera unsupported" });
|
|
@@ -99,7 +115,11 @@ var CameraView = /* @__PURE__ */ __s(function CameraView(props, __s, __extra) {
|
|
|
99
115
|
element.srcObject = null;
|
|
100
116
|
if (stream) for (const track of stream.getTracks()) track.stop();
|
|
101
117
|
};
|
|
102
|
-
}, [
|
|
118
|
+
}, [
|
|
119
|
+
active,
|
|
120
|
+
facing,
|
|
121
|
+
props.session
|
|
122
|
+
], _hs$ + 3);
|
|
103
123
|
useImperativeHandle(props.ref, () => ({ native: hostRef.current }), void 0, _hs$ + 4);
|
|
104
124
|
let _b = __s.slots[0];
|
|
105
125
|
if (_b === void 0) {
|
|
@@ -183,7 +203,7 @@ var CameraView = /* @__PURE__ */ __s(function CameraView(props, __s, __extra) {
|
|
|
183
203
|
"aria-live",
|
|
184
204
|
_m11
|
|
185
205
|
]
|
|
186
|
-
], "b:
|
|
206
|
+
], "b:d3c40afd", true);
|
|
187
207
|
markDangerouslySetInnerHTMLChildren(_root);
|
|
188
208
|
_m14 = child(_root);
|
|
189
209
|
_b = bag15(__s, _root, _m0, _m1, _m2, _m3, _m4, _m5, _m6, _m7, _m8, _m9, _m10, _m11, _root, _m13, _m14);
|
|
@@ -300,7 +320,7 @@ var CameraView = /* @__PURE__ */ __s(function CameraView(props, __s, __extra) {
|
|
|
300
320
|
"aria-live",
|
|
301
321
|
_b.l
|
|
302
322
|
]
|
|
303
|
-
], "b:
|
|
323
|
+
], "b:d3c40afd", true);
|
|
304
324
|
}
|
|
305
325
|
{
|
|
306
326
|
const __ifCondition = active;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { CameraCaptureError } from "./types.js";
|
|
2
|
+
import { createHostClient } from "@octane-xplat/platform/host";
|
|
3
|
+
import { createWebKitTransport } from "@octane-xplat/platform/host/web";
|
|
4
|
+
//#region src/host-movie.web.ts
|
|
5
|
+
var requiredMethods = [
|
|
6
|
+
"permissionStatus",
|
|
7
|
+
"requestPermission",
|
|
8
|
+
"movieDirectory",
|
|
9
|
+
"reserveMoviePath",
|
|
10
|
+
"writeMovieFile",
|
|
11
|
+
"movieFileInfo",
|
|
12
|
+
"readMovieFile",
|
|
13
|
+
"deleteMovieFile"
|
|
14
|
+
];
|
|
15
|
+
var hostProbe;
|
|
16
|
+
/** The camera-capable desktop host client, or null outside a qualified host. */
|
|
17
|
+
function cameraHost() {
|
|
18
|
+
hostProbe ??= (async () => {
|
|
19
|
+
try {
|
|
20
|
+
const transport = createWebKitTransport();
|
|
21
|
+
if (!transport) return null;
|
|
22
|
+
const client = createHostClient(transport);
|
|
23
|
+
const methods = (await client.capabilities().catch(() => null))?.camera;
|
|
24
|
+
if (Array.isArray(methods) && requiredMethods.every((name) => methods.includes(name))) return client;
|
|
25
|
+
client.dispose();
|
|
26
|
+
return null;
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
return hostProbe;
|
|
32
|
+
}
|
|
33
|
+
var error = (kind, message) => new CameraCaptureError({
|
|
34
|
+
kind,
|
|
35
|
+
operation: "storage",
|
|
36
|
+
message
|
|
37
|
+
});
|
|
38
|
+
var blobToBase64 = async (bytes) => {
|
|
39
|
+
const data = new Uint8Array(await bytes.arrayBuffer());
|
|
40
|
+
let binary = "";
|
|
41
|
+
const chunk = 32768;
|
|
42
|
+
for (let offset = 0; offset < data.length; offset += chunk) binary += String.fromCharCode(...data.subarray(offset, offset + chunk));
|
|
43
|
+
return btoa(binary);
|
|
44
|
+
};
|
|
45
|
+
var base64ToBlob = (base64, type) => {
|
|
46
|
+
const binary = atob(base64);
|
|
47
|
+
const data = new Uint8Array(binary.length);
|
|
48
|
+
for (let index = 0; index < binary.length; index++) data[index] = binary.charCodeAt(index);
|
|
49
|
+
return new Blob([data], { type });
|
|
50
|
+
};
|
|
51
|
+
var mimeForFileUrl = (fileUrl) => fileUrl.endsWith(".webm") ? "video/webm" : fileUrl.endsWith(".mov") ? "video/quicktime" : "video/mp4";
|
|
52
|
+
/** Reserve a host-side movie file. `destinationFileUrl` is validated
|
|
53
|
+
* host-side: it must be a new file inside the app-private storage root. */
|
|
54
|
+
var reserveHostMovie = async (host, options) => {
|
|
55
|
+
const { reservation } = await host.call("camera", "reserveMoviePath", {
|
|
56
|
+
fileUrl: options.destinationFileUrl,
|
|
57
|
+
container: options.container
|
|
58
|
+
});
|
|
59
|
+
if (!reservation?.fileUrl) throw error("destinationUnavailable", options.destinationFileUrl ? "destinationFileUrl must be a new file inside the app-private recordings directory" : "The host could not allocate a movie recording file");
|
|
60
|
+
return reservation;
|
|
61
|
+
};
|
|
62
|
+
/** Commit finalized movie bytes to host-side app-private storage. */
|
|
63
|
+
var commitHostMovie = async (host, fileUrl, bytes) => {
|
|
64
|
+
const base64 = await blobToBase64(bytes);
|
|
65
|
+
const { file } = await host.call("camera", "writeMovieFile", {
|
|
66
|
+
fileUrl,
|
|
67
|
+
base64
|
|
68
|
+
});
|
|
69
|
+
if (!file?.uri) throw error("storageFailed", "The host could not write the recorded movie");
|
|
70
|
+
return {
|
|
71
|
+
kind: "nativeFile",
|
|
72
|
+
resourceId: file.uri,
|
|
73
|
+
fileUrl: file.uri
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/** Drop an uncommitted host reservation after a failed attempt. */
|
|
77
|
+
var removeHostReservation = async (host, fileUrl) => {
|
|
78
|
+
await host.call("camera", "deleteMovieFile", { fileUrl }).catch(() => {});
|
|
79
|
+
};
|
|
80
|
+
/** Reopen a host-stored movie as a temporary playback URL. The durable
|
|
81
|
+
* reference remains `fileUrl`; the returned url lives until `release()`. */
|
|
82
|
+
var openHostMovie = async (host, output) => {
|
|
83
|
+
if (output.kind !== "nativeFile" || !output.fileUrl) throw new CameraCaptureError({
|
|
84
|
+
kind: "invalidArgument",
|
|
85
|
+
operation: "openOutput",
|
|
86
|
+
message: "Only file-backed output can be opened through the desktop host"
|
|
87
|
+
});
|
|
88
|
+
const { info } = await host.call("camera", "movieFileInfo", { fileUrl: output.fileUrl });
|
|
89
|
+
if (!info?.exists) throw error("unavailable", `Movie file is missing at ${output.fileUrl}`);
|
|
90
|
+
const { base64 } = await host.call("camera", "readMovieFile", { fileUrl: output.fileUrl });
|
|
91
|
+
if (!base64) throw error("unavailable", `Movie file could not be read at ${output.fileUrl}`);
|
|
92
|
+
const url = URL.createObjectURL(base64ToBlob(base64, mimeForFileUrl(output.fileUrl)));
|
|
93
|
+
return {
|
|
94
|
+
url,
|
|
95
|
+
fileUrl: output.fileUrl,
|
|
96
|
+
release: () => URL.revokeObjectURL(url)
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
export { cameraHost, commitHostMovie, openHostMovie, removeHostReservation, reserveHostMovie };
|
package/dist/web/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
import { CameraCaptureError } from "./types.js";
|
|
2
|
+
import { createCameraSession } from "./session.js";
|
|
1
3
|
import { CameraView } from "./CameraView.web.tsrx.js";
|
|
2
|
-
|
|
4
|
+
import { createMemoryCameraStorage, createSyntheticCameraSession } from "./synthetic-session.js";
|
|
5
|
+
export { CameraCaptureError, CameraView, createCameraSession, createMemoryCameraStorage, createSyntheticCameraSession };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CameraCaptureError } from "./types.js";
|
|
2
|
+
import { BlobSource, Input, MP4, WEBM } from "mediabunny";
|
|
3
|
+
//#region src/movie-metadata.web.ts
|
|
4
|
+
/** Read packet end timestamps and track metadata, never the wall-clock stop time. */
|
|
5
|
+
async function inspectMovie(bytes, audioRequested) {
|
|
6
|
+
if (!bytes.size) throw new CameraCaptureError({
|
|
7
|
+
kind: "noMedia",
|
|
8
|
+
operation: "finalize",
|
|
9
|
+
message: "The recorder produced no movie bytes"
|
|
10
|
+
});
|
|
11
|
+
const input = new Input({
|
|
12
|
+
source: new BlobSource(bytes),
|
|
13
|
+
formats: [WEBM, MP4]
|
|
14
|
+
});
|
|
15
|
+
const read = async () => {
|
|
16
|
+
const video = await input.getPrimaryVideoTrack();
|
|
17
|
+
const audio = await input.getPrimaryAudioTrack();
|
|
18
|
+
if (!video) throw new CameraCaptureError({
|
|
19
|
+
kind: "noMedia",
|
|
20
|
+
operation: "finalize",
|
|
21
|
+
message: "The movie contains no video track"
|
|
22
|
+
});
|
|
23
|
+
const videoDuration = await video.computeDuration();
|
|
24
|
+
const hasAudio = audio !== null && await audio.computeDuration() > 0;
|
|
25
|
+
const durationMs = await input.computeDuration() * 1e3;
|
|
26
|
+
const width = await video.getDisplayWidth();
|
|
27
|
+
const height = await video.getDisplayHeight();
|
|
28
|
+
if (!Number.isFinite(durationMs) || durationMs <= 0 || videoDuration <= 0 || width <= 0 || height <= 0) throw new CameraCaptureError({
|
|
29
|
+
kind: "noMedia",
|
|
30
|
+
operation: "finalize",
|
|
31
|
+
message: "The movie has no usable video media"
|
|
32
|
+
});
|
|
33
|
+
if (audioRequested && !hasAudio) throw new CameraCaptureError({
|
|
34
|
+
kind: "captureFailed",
|
|
35
|
+
operation: "finalize",
|
|
36
|
+
message: "Requested audio is absent from the finalized movie"
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
durationMs,
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
hasAudio,
|
|
43
|
+
mimeType: await input.getMimeType(),
|
|
44
|
+
orientation: "unspecified"
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
let timer;
|
|
48
|
+
try {
|
|
49
|
+
return await Promise.race([read(), new Promise((_resolve, reject) => {
|
|
50
|
+
timer = setTimeout(() => {
|
|
51
|
+
input.dispose();
|
|
52
|
+
reject(new CameraCaptureError({
|
|
53
|
+
kind: "finalizationFailed",
|
|
54
|
+
operation: "metadata",
|
|
55
|
+
message: "Movie metadata verification timed out"
|
|
56
|
+
}));
|
|
57
|
+
}, 3e4);
|
|
58
|
+
})]);
|
|
59
|
+
} finally {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
input.dispose();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { inspectMovie };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { CameraCaptureError } from "./types.js";
|
|
2
|
+
//#region src/movie-storage.web.ts
|
|
3
|
+
var databaseName = "octane-xplat-camera";
|
|
4
|
+
var storeName = "movies";
|
|
5
|
+
var storageError = (cause) => new CameraCaptureError({
|
|
6
|
+
kind: cause instanceof DOMException && cause.name === "QuotaExceededError" ? "insufficientStorage" : "storageFailed",
|
|
7
|
+
operation: "storage",
|
|
8
|
+
message: "The movie could not be committed to origin-local storage",
|
|
9
|
+
cause
|
|
10
|
+
});
|
|
11
|
+
/** Each operation closes its database; playback survives session and page lifetimes. */
|
|
12
|
+
async function transact(mode, operation) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
let database;
|
|
15
|
+
let transaction;
|
|
16
|
+
let result;
|
|
17
|
+
let done = false;
|
|
18
|
+
const finish = (cause) => {
|
|
19
|
+
if (done) return;
|
|
20
|
+
done = true;
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
database?.close();
|
|
23
|
+
if (cause) reject(storageError(cause));
|
|
24
|
+
else resolve(result);
|
|
25
|
+
};
|
|
26
|
+
const timer = setTimeout(() => {
|
|
27
|
+
transaction?.abort();
|
|
28
|
+
finish(/* @__PURE__ */ new Error("Storage transaction timed out"));
|
|
29
|
+
}, 15e3);
|
|
30
|
+
const request = indexedDB.open(databaseName, 1);
|
|
31
|
+
request.onupgradeneeded = () => request.result.createObjectStore(storeName, { keyPath: "id" });
|
|
32
|
+
request.onerror = () => finish(request.error);
|
|
33
|
+
request.onblocked = () => finish(/* @__PURE__ */ new Error("Storage upgrade is blocked by another page"));
|
|
34
|
+
request.onsuccess = () => {
|
|
35
|
+
database = request.result;
|
|
36
|
+
if (done) {
|
|
37
|
+
database.close();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
transaction = database.transaction(storeName, mode, { durability: "strict" });
|
|
42
|
+
transaction.oncomplete = () => finish();
|
|
43
|
+
transaction.onabort = () => finish(transaction?.error ?? /* @__PURE__ */ new Error("Storage transaction aborted"));
|
|
44
|
+
transaction.onerror = () => finish(transaction?.error ?? /* @__PURE__ */ new Error("Storage transaction failed"));
|
|
45
|
+
operation(transaction.objectStore(storeName), (value) => {
|
|
46
|
+
result = value;
|
|
47
|
+
});
|
|
48
|
+
} catch (cause) {
|
|
49
|
+
finish(cause);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function reserveMovie() {
|
|
55
|
+
const estimate = await navigator.storage.estimate();
|
|
56
|
+
if (estimate.quota !== void 0 && estimate.usage !== void 0 && estimate.quota - estimate.usage < 1048576) throw new CameraCaptureError({
|
|
57
|
+
kind: "insufficientStorage",
|
|
58
|
+
operation: "reserve",
|
|
59
|
+
message: "Origin storage has less than 1 MiB free"
|
|
60
|
+
});
|
|
61
|
+
const id = crypto.randomUUID();
|
|
62
|
+
await transact("readwrite", (store) => {
|
|
63
|
+
store.add({ id });
|
|
64
|
+
});
|
|
65
|
+
return id;
|
|
66
|
+
}
|
|
67
|
+
async function commitMovie(id, bytes, clip) {
|
|
68
|
+
if (!await navigator.storage.persisted()) throw new CameraCaptureError({
|
|
69
|
+
kind: "destinationUnavailable",
|
|
70
|
+
operation: "storage",
|
|
71
|
+
message: "Persistent origin storage is no longer granted"
|
|
72
|
+
});
|
|
73
|
+
await transact("readwrite", (store) => {
|
|
74
|
+
store.put({
|
|
75
|
+
id,
|
|
76
|
+
bytes,
|
|
77
|
+
clip
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const stored = await readMovie(id);
|
|
81
|
+
if (!stored.bytes || stored.bytes.size !== bytes.size || !stored.clip) throw storageError(/* @__PURE__ */ new Error("Committed movie cannot be reopened"));
|
|
82
|
+
}
|
|
83
|
+
async function removeReservation(id) {
|
|
84
|
+
await transact("readwrite", (store) => {
|
|
85
|
+
store.delete(id);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function readMovie(id) {
|
|
89
|
+
return transact("readonly", (store, result) => {
|
|
90
|
+
const request = store.get(id);
|
|
91
|
+
request.onsuccess = () => result(request.result ?? { id });
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function openStoredMovie(output) {
|
|
95
|
+
if (output.kind !== "browserStorage" || output.synthetic) throw new CameraCaptureError({
|
|
96
|
+
kind: "invalidArgument",
|
|
97
|
+
operation: "openOutput",
|
|
98
|
+
message: "Expected an origin-local movie reference"
|
|
99
|
+
});
|
|
100
|
+
const stored = await readMovie(output.resourceId);
|
|
101
|
+
if (!stored.bytes || !stored.clip) throw new CameraCaptureError({
|
|
102
|
+
kind: "destinationUnavailable",
|
|
103
|
+
operation: "openOutput",
|
|
104
|
+
message: "Movie is missing or site data was cleared"
|
|
105
|
+
});
|
|
106
|
+
const url = URL.createObjectURL(stored.bytes);
|
|
107
|
+
let released = false;
|
|
108
|
+
return {
|
|
109
|
+
url,
|
|
110
|
+
release: () => {
|
|
111
|
+
if (!released) {
|
|
112
|
+
released = true;
|
|
113
|
+
URL.revokeObjectURL(url);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { commitMovie, openStoredMovie, removeReservation, reserveMovie };
|