Files
feuerwerk/src/editor/recordingUploads.ts
T
adminandClaude Opus 5.5 ba01d146e9 Choose size, rate and what follows when recording the editor
The editor recording had fixed settings: the canvas size at 60 fps,
always converted and imported. Recording in 4K needs a choice, and the
server shrank every video to 1080p anyway. Start recording... now opens
a dialog, and a recording always goes to the server as it is.

- The dialog holds name, resolution (Screen, 1080p, 1440p, 4K), fps
  (60 or 30), mouse pointer, sound, Convert and Import after
  conversion. Import is greyed out while Convert is off. The browser
  keeps the last choice, not the name.
- A larger resolution makes the editor draw finer while it records,
  so 4K is sharp, not stretched. It is never below the screen's own
  resolution and goes back after Stop.
- Stop always uploads. Without Convert the file only stays on the
  server. Without Import it is converted but no asset is added. Both
  are found in the video picker.
- The server keeps the original next to each MP4 for every upload, so
  Download in the video tab and the picker gives the original. Videos
  from before have none, they still download their MP4.
- A file left unconverted shows in the picker as not converted, with
  a Convert button. POST videos/{file}/convert queues it, and upload
  takes convert=0.
- The worker now caps a video at 3840x2160 instead of 1920x1080. Videos
  converted before stay as they are.

Tests:
- PHP videos.test.php: 81 checks green, with the original, convert=0,
  a later Convert and the 4K cap.
- Unit recording: 5 new, green. Red without the rule that a recording
  is never below the screen's resolution.
- e2e 67e-ii: the video tab downloads the .source.mkv, a Matroska
  file. 67f: 1440p from a 1280x800 window gives 2304x1440 at 30 fps
  without sound, kept and not imported, then converted in the picker.
  Both red with the MP4 download and without the finer drawing.
- The README names 2045 e2e checks.
- Gate on melektaus-atx: 304 files, 4699 tests green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 17:01:55 +02:00

106 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { UploadedVideo } from '../core/store/VideoStore';
import type { MadeRecording } from '../viewport/RecordingTake';
import type { RecordingUploadOptions } from './EditorRecorder';
import { adoptVideo, type VideoImportDeps } from './videoImport';
/** How often the server is asked whether a recording is converted, as the video picker does. */
const POLL_MS = 1000;
/** `kept`: uploaded without converting it; `converted`: converted, but not to be imported. */
type UploadState = 'uploading' | 'converting' | 'added' | 'kept' | 'converted' | 'elsewhere' | 'failed';
/** What became of a recording on its way into the project (test hook). */
export interface RecordingUpload {
name: string;
state: UploadState;
/** The name the server gave it, once it is up. */
file: string;
assetId: string;
bytes: number;
error: string;
}
/**
* Brings a recording of the game view (#405) or of the editor into the project: up to the server,
* which converts it like any video, then an asset named after the recording once it is ready. Only
* while the editor is not playing: a run plays a copy of the project that is thrown away, and so
* would the asset be. An editor recording may stop short of either step ("Start recording…"): it
* is always uploaded, and the video picker has it.
*/
export class RecordingUploads {
private readonly uploads: RecordingUpload[] = [];
constructor(private readonly deps: VideoImportDeps) {}
add(recording: MadeRecording, options: RecordingUploadOptions = { convert: true, adopt: true }): void {
const upload: RecordingUpload = {
name: recording.name,
state: 'uploading',
file: '',
assetId: '',
bytes: recording.blob.size,
error: '',
};
this.uploads.push(upload);
void this.bring(recording, upload, options).catch((error: unknown) => {
upload.state = 'failed';
upload.error = error instanceof Error ? error.message : String(error);
this.deps.state.setNotice(`Could not save the recording "${recording.name}": ${upload.error}`, 'error');
});
}
info(): RecordingUpload[] {
return this.uploads.map((upload) => ({ ...upload }));
}
private async bring(
recording: MadeRecording,
upload: RecordingUpload,
options: RecordingUploadOptions,
): Promise<void> {
const { state, videos } = this.deps;
const projectId = state.project.id;
state.setNotice(`Uploading the recording "${recording.name}"…`);
let video: UploadedVideo = await videos.upload(
recording.blob,
'application/octet-stream',
`${recording.name}.mkv`,
{ convert: options.convert },
);
upload.file = video.file;
if (!options.convert) {
upload.state = 'kept';
state.setNotice(
`Uploaded the recording "${recording.name}" without converting it – the video picker has it.`,
);
return;
}
upload.state = 'converting';
while (video.status !== 'ready') {
if (video.status === 'failed') throw new Error(video.error ?? 'the server could not convert it');
await wait(POLL_MS);
video = (await videos.list()).find((v) => v.file === upload.file) ?? video;
}
if (!options.adopt) {
upload.state = 'converted';
state.setNotice(`The recording "${recording.name}" is converted – the video picker has it.`);
return;
}
while (state.mode !== 'edit') await wait(POLL_MS);
if (state.project.id !== projectId) {
upload.state = 'elsewhere';
state.setNotice(`The recording "${recording.name}" is ready – the video picker has it.`);
return;
}
const outcome = adoptVideo(video, recording.name, this.deps);
if (!outcome.assetId) throw new Error(outcome.error ?? 'the project did not take it');
upload.state = 'added';
upload.assetId = outcome.assetId;
state.setNotice(`Added the recording "${recording.name}" to the project.`);
}
}
function wait(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}