Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(recorder-core): add recorder types and constants
Richie McIlroy8d12772ba49f
diff --git a/packages/recorder-core/src/recorder-constants.ts b/packages/recorder-core/src/recorder-constants.tsnew file mode 100644index 000000000..249a030e7--- /dev/null+++ b/packages/recorder-core/src/recorder-constants.ts@@ -0,0 +1,99 @@+export const NO_MICROPHONE = "No Microphone";+export const NO_MICROPHONE_VALUE = "__no_microphone__";+export const NO_CAMERA = "No Camera";+export const NO_CAMERA_VALUE = "__no_camera__";++// Single source for the capture resolution defaults; consumers that need the+// raw numbers (e.g. fallback stream dimensions) read these instead of+// re-hardcoding them next to the constraints object.+export const DISPLAY_MEDIA_IDEAL = {+ width: 1920,+ height: 1080,+ frameRate: 30,+} as const;++export const DISPLAY_MEDIA_VIDEO_CONSTRAINTS: MediaTrackConstraints = {+ frameRate: { ideal: DISPLAY_MEDIA_IDEAL.frameRate },+ width: { ideal: DISPLAY_MEDIA_IDEAL.width },+ height: { ideal: DISPLAY_MEDIA_IDEAL.height },+};++export type ExtendedDisplayMediaStreamOptions = DisplayMediaStreamOptions & {+ monitorTypeSurfaces?: "include" | "exclude";+ surfaceSwitching?: "include" | "exclude";+ selfBrowserSurface?: "include" | "exclude";+ preferCurrentTab?: boolean;+ systemAudio?: "include" | "exclude";+};++export type DetectedDisplayRecordingMode = "fullscreen" | "window" | "tab";++export type DisplaySurfacePreference =+ | "monitor"+ | "window"+ | "browser"+ | "application";++export const DISPLAY_MODE_PREFERENCES: Record<+ DetectedDisplayRecordingMode,+ Partial<ExtendedDisplayMediaStreamOptions>+> = {+ fullscreen: {+ monitorTypeSurfaces: "include",+ selfBrowserSurface: "exclude",+ surfaceSwitching: "exclude",+ preferCurrentTab: false,+ },+ window: {+ monitorTypeSurfaces: "exclude",+ selfBrowserSurface: "exclude",+ surfaceSwitching: "exclude",+ preferCurrentTab: false,+ },+ tab: {+ monitorTypeSurfaces: "exclude",+ selfBrowserSurface: "include",+ surfaceSwitching: "exclude",+ preferCurrentTab: true,+ },+};++export const DISPLAY_SURFACE_TO_RECORDING_MODE: Record<+ string,+ DetectedDisplayRecordingMode+> = {+ monitor: "fullscreen",+ screen: "fullscreen",+ window: "window",+ application: "window",+ browser: "tab",+ tab: "tab",+};++export const RECORDING_MODE_TO_DISPLAY_SURFACE: Record<+ DetectedDisplayRecordingMode,+ DisplaySurfacePreference+> = {+ fullscreen: "monitor",+ window: "window",+ tab: "browser",+};++export const MP4_MIME_TYPES = {+ withAudio: [+ 'video/mp4;codecs="avc1.42E01E,mp4a.40.2"',+ 'video/mp4;codecs="avc1.4d401e,mp4a.40.2"',+ ],+ videoOnly: [+ 'video/mp4;codecs="avc1.42E01E"',+ 'video/mp4;codecs="avc1.4d401e"',+ "video/mp4",+ ],+} as const;++export const WEBM_MIME_TYPES = {+ withAudio: ["video/webm;codecs=vp9,opus", "video/webm;codecs=vp8,opus"],+ videoOnly: ["video/webm;codecs=vp9", "video/webm;codecs=vp8", "video/webm"],+} as const;++export const DETECTION_RETRY_DELAYS = [120, 450, 1000];diff --git a/packages/recorder-core/src/recorder-types.ts b/packages/recorder-core/src/recorder-types.tsnew file mode 100644index 000000000..68fe3bebf--- /dev/null+++ b/packages/recorder-core/src/recorder-types.ts@@ -0,0 +1,65 @@+import type { Storage, Video } from "@cap/web-domain";++export type RecorderPhase =+ | "idle"+ | "recording"+ | "paused"+ | "creating"+ | "converting"+ | "uploading"+ | "completed"+ | "error";++export type RecorderErrorEvent = Event & { error?: DOMException };++// Derived from the server schema so contract drift fails to compile instead+// of surfacing at runtime.+export type UploadTarget = Storage.UploadTarget;++export type UploadStatus =+ | {+ status: "parsing";+ }+ | {+ status: "creating";+ }+ | {+ status: "converting";+ capId: string;+ progress: number;+ }+ | {+ status: "uploadingThumbnail";+ capId: string;+ progress: number;+ }+ | {+ status: "uploadingVideo";+ capId: string;+ progress: number;+ thumbnailUrl: string | undefined;+ }+ | {+ status: "serverProcessing";+ capId: string;+ };++export type VideoId = Video.VideoId;++export type ChunkUploadState = {+ partNumber: number;+ sizeBytes: number;+ uploadedBytes: number;+ progress: number;+ status: "queued" | "uploading" | "complete" | "error";+};++export type RecordingFailureDownload = {+ url: string;+ fileName: string;+};++export type RecoveredRecordingDownload = RecordingFailureDownload & {+ id: string;+ createdAt: number;+};