feat(recordings): add phase6 recording finalization pipeline and simulator support
This commit is contained in:
@@ -159,6 +159,8 @@
|
||||
<button id="requestStreamBtn">Request On-Demand Stream</button>
|
||||
<button id="fetchPlaybackBtn" class="alt">Fetch Playback Token (Latest)</button>
|
||||
<button id="fetchSubscribeBtn" class="alt">Fetch Subscribe Credentials</button>
|
||||
<button id="listRecordingsBtn" class="alt">List Recordings</button>
|
||||
<button id="downloadLatestRecordingBtn" class="alt">Download URL (Latest)</button>
|
||||
<pre id="clientState"></pre>
|
||||
</section>
|
||||
|
||||
@@ -167,6 +169,7 @@
|
||||
<button id="startMotionBtn" class="warn">Start Motion Event</button>
|
||||
<button id="endMotionBtn" class="danger">End Last Motion Event</button>
|
||||
<button id="fetchPublishBtn" class="alt">Fetch Publish Credentials</button>
|
||||
<button id="finalizeRecordingBtn" class="alt">Finalize Recording (Latest)</button>
|
||||
<pre id="cameraState"></pre>
|
||||
</section>
|
||||
</div>
|
||||
@@ -185,6 +188,7 @@
|
||||
socket: null,
|
||||
lastMotionEventId: null,
|
||||
lastStreamSessionId: null,
|
||||
lastRecordingId: null,
|
||||
};
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
@@ -203,7 +207,11 @@
|
||||
const render = () => {
|
||||
$('deviceState').textContent = JSON.stringify({ device: state.device, hasToken: Boolean(state.deviceToken) }, null, 2);
|
||||
$('clientState').textContent = JSON.stringify({ lastStreamSessionId: state.lastStreamSessionId }, null, 2);
|
||||
$('cameraState').textContent = JSON.stringify({ lastMotionEventId: state.lastMotionEventId }, null, 2);
|
||||
$('cameraState').textContent = JSON.stringify(
|
||||
{ lastMotionEventId: state.lastMotionEventId, lastRecordingId: state.lastRecordingId },
|
||||
null,
|
||||
2,
|
||||
);
|
||||
};
|
||||
|
||||
const authFetch = async (url, options = {}) => {
|
||||
@@ -425,6 +433,29 @@
|
||||
}
|
||||
});
|
||||
|
||||
$('listRecordingsBtn').addEventListener('click', async () => {
|
||||
try {
|
||||
const payload = await deviceFetch('/recordings/me/list');
|
||||
if (payload.recordings?.length > 0) {
|
||||
state.lastRecordingId = payload.recordings[0].id;
|
||||
render();
|
||||
}
|
||||
log('recordings', payload);
|
||||
} catch (error) {
|
||||
log('list recordings failed', { error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
$('downloadLatestRecordingBtn').addEventListener('click', async () => {
|
||||
try {
|
||||
if (!state.lastRecordingId) throw new Error('No recording id available');
|
||||
const payload = await deviceFetch(`/recordings/${state.lastRecordingId}/download-url`);
|
||||
log('recording download url', payload);
|
||||
} catch (error) {
|
||||
log('recording download failed', { error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
$('fetchSubscribeBtn').addEventListener('click', async () => {
|
||||
try {
|
||||
if (!state.lastStreamSessionId) throw new Error('No known stream session');
|
||||
@@ -475,6 +506,34 @@
|
||||
}
|
||||
});
|
||||
|
||||
$('finalizeRecordingBtn').addEventListener('click', async () => {
|
||||
try {
|
||||
if (!state.lastStreamSessionId) throw new Error('No stream session yet');
|
||||
|
||||
const listPayload = await deviceFetch('/recordings/me/list');
|
||||
const target = listPayload.recordings?.find((r) => r.streamSessionId === state.lastStreamSessionId) ?? listPayload.recordings?.[0];
|
||||
|
||||
if (!target) throw new Error('No recording placeholder exists');
|
||||
|
||||
state.lastRecordingId = target.id;
|
||||
render();
|
||||
|
||||
const payload = await deviceFetch(`/recordings/${target.id}/finalize`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
objectKey: `recordings/${target.id}.mp4`,
|
||||
bucket: 'videos',
|
||||
durationSeconds: 12,
|
||||
sizeBytes: 1024 * 1024 * 8,
|
||||
}),
|
||||
});
|
||||
|
||||
log('recording finalized', payload);
|
||||
} catch (error) {
|
||||
log('finalize recording failed', { error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
render();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user