@vidtreo/recorder 0.0.1

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.
@@ -0,0 +1,964 @@
1
+ export declare const FILE_SIZE_UNITS: readonly ["Bytes", "KB", "MB", "GB"];
2
+ export declare const FILE_SIZE_BASE = 1024;
3
+ export declare const TIMESTAMP_REGEX: RegExp;
4
+ export declare const DEFAULT_COUNTDOWN_DURATION = 5000;
5
+ export declare const AUDIO_LEVEL_INTERVAL = 100;
6
+ export declare const AUDIO_LEVEL_BARS = 15;
7
+ export declare const CLEANUP_INTERVAL: number;
8
+ export declare const DEFAULT_BACKEND_URL = "https://api.vidtreo.com";
9
+
10
+ import { DeviceManager as CoreDeviceManager } from "../../core/device/device-manager";
11
+ export declare class DeviceManager extends CoreDeviceManager {
12
+ updateDeviceSelects(shadowRoot: ShadowRoot): void;
13
+ }
14
+
15
+ export declare class AudioLevelVisualizer {
16
+ private barsContainer;
17
+ initializeBars(shadowRoot: ShadowRoot): void;
18
+ updateBars(level: number, isMuted: boolean): void;
19
+ private queryElement;
20
+ private createBar;
21
+ private updateBar;
22
+ private calculateThreshold;
23
+ private setBarHeight;
24
+ private setBarStyle;
25
+ }
26
+
27
+ import type { RecordingState, SourceType, UploadResult } from "../../core/types/recorder-types";
28
+ export declare class UIStateManager {
29
+ private readonly shadowRoot;
30
+ constructor(shadowRoot: ShadowRoot);
31
+ private queryElement;
32
+ private setText;
33
+ private toggleClass;
34
+ private setStyle;
35
+ private setDisplay;
36
+ private setDisabled;
37
+ showError(message: string): void;
38
+ hideError(): void;
39
+ showProgress(): void;
40
+ hideProgress(): void;
41
+ updateProgress(percentage: number, text: string): void;
42
+ updateRecordingTimer(formatted: string): void;
43
+ updateMuteState(muted: boolean, onAudioLevelUpdate: (level: number, isMuted: boolean) => void, audioLevel: number): void;
44
+ updatePauseState(isPaused: boolean): void;
45
+ updateCountdownOverlay(recordingState: RecordingState, countdownRemaining: number): void;
46
+ showSourceTransition(message: string): void;
47
+ hideSourceTransition(): void;
48
+ handleStreamStart(recordingState: RecordingState, onInitializeAudioBars: () => void): void;
49
+ handleStreamStop(onStopAudioTracking: () => void): void;
50
+ handleRecordingStart(isPaused: boolean): void;
51
+ updateRecordingControlsAfterStop(): void;
52
+ updateSwitchButtonText(currentSourceType: SourceType): void;
53
+ toggleSettings(currentState: boolean): boolean;
54
+ showUploadProgress(): void;
55
+ updateUploadProgress(progress: number): void;
56
+ hideUploadProgress(): void;
57
+ showUploadSuccess(result: UploadResult): void;
58
+ showUploadError(message: string): void;
59
+ clearUploadStatus(): void;
60
+ updateVideoPreview(stream: MediaStream | null): void;
61
+ getShadowRoot(): ShadowRoot;
62
+ }
63
+
64
+ export declare function getTemplate(isMuted: boolean, currentSourceType?: "camera" | "screen"): string;
65
+
66
+ export type ConfigFromAttributes = {
67
+ apiKey: string | null;
68
+ backendUrl: string;
69
+ countdownDuration?: number;
70
+ maxRecordingTime?: number;
71
+ userMetadata?: Record<string, unknown>;
72
+ };
73
+ export declare function normalizeBackendUrl(url: string | null | undefined): string;
74
+ export declare function buildConfigFromAttributes(element: HTMLElement, userMetadata: Record<string, unknown>): ConfigFromAttributes;
75
+
76
+ export declare function queryElement<T extends HTMLElement>(shadowRoot: ShadowRoot, selector: string): T;
77
+
78
+ export declare const STYLES: string;
79
+
80
+ import { RecorderController } from "../core/recorder/recorder-controller";
81
+ export declare class VidtreoRecorder extends HTMLElement {
82
+ static observedAttributes: string[];
83
+ private readonly controller;
84
+ private readonly uiStateManager;
85
+ private readonly deviceManager;
86
+ private readonly audioLevelVisualizer;
87
+ private recordedBlob;
88
+ private processedBlob;
89
+ private isProcessing;
90
+ private isMuted;
91
+ private showSettings;
92
+ private readonly userMetadata;
93
+ constructor();
94
+ connectedCallback(): Promise<void>;
95
+ attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
96
+ disconnectedCallback(): void;
97
+ private get shadow();
98
+ checkPendingUploads(): Promise<void>;
99
+ startCamera(): Promise<void>;
100
+ startRecording(): Promise<void>;
101
+ stopRecording(): Promise<void>;
102
+ pauseRecording(): void;
103
+ resumeRecording(): void;
104
+ processVideo(): Promise<void>;
105
+ downloadVideo(): void;
106
+ playVideo(): void;
107
+ toggleMute(): void;
108
+ toggleSource(): Promise<void>;
109
+ toggleSettings(): void;
110
+ handleCameraChange(value: string): Promise<void>;
111
+ handleMicChange(value: string): Promise<void>;
112
+ handleStateChange(state: string, previousState: string): void;
113
+ handleStreamStart(stream: MediaStream): void;
114
+ handleStreamStop(): void;
115
+ handleRecordingStart(): void;
116
+ handleRecordingStop(blob: Blob): Promise<void>;
117
+ updateRecordingTimer(formatted: string): void;
118
+ updateMuteState(muted: boolean): void;
119
+ updateVideoPreview(stream: MediaStream): void;
120
+ showError(message: string): void;
121
+ extractErrorMessage(error: unknown): string;
122
+ getStreamManager(): import("..").CameraStreamManager;
123
+ getShadowRoot(): ShadowRoot;
124
+ getController(): RecorderController;
125
+ getUIStateManager(): UIStateManager;
126
+ getDeviceManager(): DeviceManager;
127
+ getAudioLevelVisualizer(): AudioLevelVisualizer;
128
+ getRecordedBlob(): Blob | null;
129
+ setRecordedBlob(blob: Blob | null): void;
130
+ getProcessedBlob(): Blob | null;
131
+ setProcessedBlob(blob: Blob | null): void;
132
+ getIsProcessing(): boolean;
133
+ setIsProcessing(value: boolean): void;
134
+ getIsMuted(): boolean;
135
+ setIsMuted(value: boolean): void;
136
+ getShowSettings(): boolean;
137
+ setShowSettings(value: boolean): void;
138
+ getUserMetadata(): Record<string, unknown>;
139
+ getNormalizedBackendUrl(url: string | null | undefined): string;
140
+ }
141
+
142
+ export declare function downloadVideo(blob: Blob): void;
143
+ export declare function playVideo(blob: Blob): void;
144
+
145
+ import type { VidtreoRecorder } from "../vidtreo-recorder.wc";
146
+ export declare function handleStartRecording(component: VidtreoRecorder): Promise<void>;
147
+ export declare function handleStopRecording(component: VidtreoRecorder): Promise<Blob>;
148
+ export declare function handlePauseRecording(component: VidtreoRecorder): void;
149
+ export declare function handleResumeRecording(component: VidtreoRecorder): void;
150
+ export declare function handleProcessVideo(component: VidtreoRecorder): Promise<void>;
151
+
152
+ import type { SourceType } from "../../core/types/recorder-types";
153
+ export declare function updatePreviewAfterSourceSwitch(videoPreview: HTMLVideoElement, stream: MediaStream, sourceType: SourceType): Promise<void>;
154
+ export declare function updatePreviewAfterDeviceSwitch(videoPreview: HTMLVideoElement, stream: MediaStream): Promise<void>;
155
+
156
+ import type { VidtreoRecorder } from "../vidtreo-recorder.wc";
157
+ export declare function attachEventListeners(component: VidtreoRecorder): void;
158
+
159
+ import type { RecorderCallbacks } from "../../core/recorder/types";
160
+ import type { VidtreoRecorder } from "../vidtreo-recorder.wc";
161
+ export declare function createRecorderCallbacks(component: VidtreoRecorder): RecorderCallbacks;
162
+
163
+ import type { VidtreoRecorder } from "../vidtreo-recorder.wc";
164
+ export declare function showPreviewSkeleton(shadowRoot: ShadowRoot, message: string): void;
165
+ export declare function hidePreviewSkeleton(shadowRoot: ShadowRoot): void;
166
+ export declare function handleCameraChange(component: VidtreoRecorder, value: string): Promise<void>;
167
+ export declare function handleMicChange(component: VidtreoRecorder, value: string): Promise<void>;
168
+
169
+ import type { CameraStreamManager } from "../../core/stream/stream";
170
+ import type { SourceType } from "../../core/types/recorder-types";
171
+ import type { DeviceManager } from "../managers/device-manager";
172
+ import type { UIStateManager } from "../managers/ui-state-manager";
173
+ export declare class SourceSwitchHandler {
174
+ private currentSourceType;
175
+ private originalCameraStream;
176
+ private readonly streamManager;
177
+ private readonly uiStateManager;
178
+ private readonly deviceManager;
179
+ private readonly onShowError;
180
+ private screenShareTrackEndHandler;
181
+ constructor(streamManager: CameraStreamManager, uiStateManager: UIStateManager, deviceManager: DeviceManager, onShowError: (message: string) => void);
182
+ getCurrentSourceType(): SourceType;
183
+ setCurrentSourceType(type: SourceType): void;
184
+ getOriginalCameraStream(): MediaStream | null;
185
+ setOriginalCameraStream(stream: MediaStream | null): void;
186
+ private stopStreamTracks;
187
+ switchToScreenCapture(): Promise<MediaStream>;
188
+ setupScreenShareTrackHandler(newStream: MediaStream, onSwitchToCamera: () => Promise<void>): void;
189
+ removeScreenShareTrackHandler(stream: MediaStream | null): void;
190
+ getCameraStream(): Promise<MediaStream>;
191
+ switchToCamera(): Promise<void>;
192
+ updatePreviewAfterSourceSwitch(newStream: MediaStream): Promise<void>;
193
+ toggleSource(): Promise<void>;
194
+ cleanup(): void;
195
+ private completePlaySuccess;
196
+ private handlePlayError;
197
+ private retryPlay;
198
+ private completePlayError;
199
+ }
200
+
201
+ import type { VidtreoRecorder } from "../vidtreo-recorder.wc";
202
+ export declare function setupEventListeners(component: VidtreoRecorder): void;
203
+
204
+ export type RecordingState = "idle" | "countdown" | "recording";
205
+ export type SourceType = "camera" | "screen";
206
+ export type AvailableDevices = {
207
+ audioinput: MediaDeviceInfo[];
208
+ videoinput: MediaDeviceInfo[];
209
+ };
210
+ export type UploadResult = {
211
+ videoId: string;
212
+ uploadUrl: string;
213
+ };
214
+
215
+ import type { TranscodeConfig } from "../processor/types";
216
+ export declare class ConfigManager {
217
+ private configService;
218
+ private currentConfig;
219
+ private configFetchPromise;
220
+ initialize(apiKey: string | null, backendUrl: string | null): void;
221
+ fetchConfig(): Promise<void>;
222
+ getConfig(): Promise<TranscodeConfig>;
223
+ clearCache(): void;
224
+ }
225
+
226
+ import type { TranscodeConfig } from "../processor/types";
227
+ export declare const DEFAULT_TRANSCODE_CONFIG: Readonly<TranscodeConfig>;
228
+
229
+ import type { TranscodeConfig } from "../processor/types";
230
+ export type BackendPreset = "sd" | "hd" | "fhd" | "4k";
231
+ export type BackendConfigResponse = {
232
+ presetEncoding: BackendPreset;
233
+ max_width: number;
234
+ max_height: number;
235
+ };
236
+ export declare function mapPresetToConfig(preset: BackendPreset, maxWidth: number, maxHeight: number): TranscodeConfig;
237
+
238
+ import type { TranscodeConfig } from "../processor/types";
239
+ export type ConfigServiceOptions = {
240
+ apiKey: string;
241
+ backendUrl: string;
242
+ cacheTimeout?: number;
243
+ };
244
+ export declare class ConfigService {
245
+ private cachedConfig;
246
+ private cacheTimestamp;
247
+ private readonly cacheTimeout;
248
+ private fetchPromise;
249
+ private readonly options;
250
+ constructor(options: ConfigServiceOptions);
251
+ fetchConfig(): Promise<TranscodeConfig>;
252
+ clearCache(): void;
253
+ getCurrentConfig(): TranscodeConfig;
254
+ private fetchConfigFromBackend;
255
+ }
256
+
257
+ import { StreamProcessor } from "../processor/stream-processor";
258
+ import type { CameraStreamManager } from "../stream/stream";
259
+ import type { RecordingState } from "../types/recorder-types";
260
+ export declare class RecordingManager {
261
+ private recordingState;
262
+ private countdownDuration;
263
+ private countdownRemaining;
264
+ private countdownTimeoutId;
265
+ private countdownIntervalId;
266
+ private countdownStartTime;
267
+ private isPaused;
268
+ private maxRecordingTime;
269
+ private maxTimeTimer;
270
+ private recordingSeconds;
271
+ private recordingIntervalId;
272
+ private pauseStartTime;
273
+ private totalPausedTime;
274
+ private readonly streamManager;
275
+ private readonly callbacks;
276
+ private streamProcessor;
277
+ private originalCameraStream;
278
+ constructor(streamManager: CameraStreamManager, callbacks: RecordingCallbacks);
279
+ setCountdownDuration(duration: number): void;
280
+ setMaxRecordingTime(maxTime: number | null): void;
281
+ getRecordingState(): RecordingState;
282
+ isPausedState(): boolean;
283
+ getRecordingSeconds(): number;
284
+ getStreamProcessor(): StreamProcessor | null;
285
+ setOriginalCameraStream(stream: MediaStream | null): void;
286
+ getOriginalCameraStream(): MediaStream | null;
287
+ startRecording(): Promise<void>;
288
+ private startCountdown;
289
+ private doStartRecording;
290
+ stopRecording(): Promise<Blob>;
291
+ pauseRecording(): void;
292
+ resumeRecording(): void;
293
+ cancelCountdown(): void;
294
+ cleanup(): void;
295
+ private resetRecordingState;
296
+ private resetPauseState;
297
+ private updatePausedDuration;
298
+ private startRecordingTimer;
299
+ private clearTimer;
300
+ private handleError;
301
+ }
302
+
303
+ import type { TranscodeConfig } from "../processor/types";
304
+ import type { RecordingState } from "../types/recorder-types";
305
+ export type RecordingCallbacks = {
306
+ onStateChange: (state: RecordingState) => void;
307
+ onCountdownUpdate: (state: RecordingState, remaining: number) => void;
308
+ onTimerUpdate: (formatted: string) => void;
309
+ onError: (error: Error) => void;
310
+ onRecordingComplete: (blob: Blob) => void;
311
+ onClearUploadStatus: () => void;
312
+ onStopAudioTracking: () => void;
313
+ onGetConfig: () => Promise<TranscodeConfig>;
314
+ };
315
+
316
+ export type CameraConstraints = {
317
+ width?: number | {
318
+ ideal?: number;
319
+ min?: number;
320
+ max?: number;
321
+ };
322
+ height?: number | {
323
+ ideal?: number;
324
+ min?: number;
325
+ max?: number;
326
+ };
327
+ frameRate?: number | {
328
+ ideal?: number;
329
+ min?: number;
330
+ max?: number;
331
+ };
332
+ };
333
+ export type StreamConfig = {
334
+ video: boolean | CameraConstraints;
335
+ audio: boolean | MediaTrackConstraints;
336
+ };
337
+ export type RecordingOptions = {
338
+ mimeType?: string;
339
+ videoBitsPerSecond?: number;
340
+ audioBitsPerSecond?: number;
341
+ bitsPerSecond?: number;
342
+ };
343
+ export type StreamState = "idle" | "starting" | "active" | "recording" | "stopping" | "error";
344
+ export type StreamEventMap = {
345
+ statechange: {
346
+ state: StreamState;
347
+ previousState: StreamState;
348
+ };
349
+ streamstart: {
350
+ stream: MediaStream;
351
+ };
352
+ streamstop: undefined;
353
+ recordingstart: {
354
+ recorder: MediaRecorder | null;
355
+ };
356
+ recordingstop: {
357
+ blob: Blob;
358
+ mimeType: string;
359
+ };
360
+ recordingdata: {
361
+ data: Blob;
362
+ };
363
+ error: {
364
+ error: Error;
365
+ };
366
+ recordingtimeupdate: {
367
+ elapsed: number;
368
+ formatted: string;
369
+ };
370
+ recordingbufferupdate: {
371
+ size: number;
372
+ formatted: string;
373
+ };
374
+ audiomutetoggle: {
375
+ muted: boolean;
376
+ };
377
+ videosourcechange: {
378
+ stream: MediaStream;
379
+ };
380
+ };
381
+ export type StreamEventListener<T extends keyof StreamEventMap> = (data: StreamEventMap[T]) => void;
382
+
383
+ export declare const DEFAULT_CAMERA_CONSTRAINTS: Readonly<CameraConstraints>;
384
+ export declare const DEFAULT_STREAM_CONFIG: Readonly<StreamConfig>;
385
+ export declare const DEFAULT_RECORDING_OPTIONS: Readonly<RecordingOptions>;
386
+
387
+ import type { SourceType } from "../types/recorder-types";
388
+ export type SourceSwitchCallbacks = {
389
+ onSourceChange?: (sourceType: SourceType) => void;
390
+ onPreviewUpdate?: (stream: MediaStream) => Promise<void>;
391
+ onError?: (error: Error) => void;
392
+ onTransitionStart?: (message: string) => void;
393
+ onTransitionEnd?: () => void;
394
+ getSelectedCameraDeviceId?: () => string | null;
395
+ getSelectedMicDeviceId?: () => string | null;
396
+ };
397
+ export declare class SourceSwitchManager {
398
+ private currentSourceType;
399
+ private originalCameraStream;
400
+ private originalCameraConstraints;
401
+ private screenShareStream;
402
+ private screenShareTrackEndHandler;
403
+ private readonly streamManager;
404
+ private callbacks;
405
+ constructor(streamManager: CameraStreamManager, callbacks?: SourceSwitchCallbacks);
406
+ getCurrentSourceType(): SourceType;
407
+ getOriginalCameraStream(): MediaStream | null;
408
+ private stopStreamTracks;
409
+ private isTrackLive;
410
+ private areTracksLive;
411
+ private storeOriginalCameraConstraints;
412
+ private storeOriginalCameraStream;
413
+ private createError;
414
+ private waitForTracksToEnd;
415
+ switchToScreenCapture(): Promise<MediaStream>;
416
+ private setupScreenShareTrackHandler;
417
+ removeScreenShareTrackHandler(stream: MediaStream | null): void;
418
+ private canReuseOriginalStream;
419
+ private canReuseManagerStream;
420
+ private buildVideoConstraints;
421
+ private buildAudioConstraints;
422
+ private createNewCameraStreamForRecording;
423
+ getCameraStream(): Promise<MediaStream>;
424
+ switchToCamera(): Promise<void>;
425
+ private notifyTransitionStart;
426
+ private notifyTransitionEnd;
427
+ private handleScreenShareStop;
428
+ private applyCameraStream;
429
+ toggleSource(): Promise<void>;
430
+ private switchToScreen;
431
+ private handleToggleError;
432
+ handleRecordingStop(): Promise<void>;
433
+ cleanup(): void;
434
+ setCallbacks(callbacks: SourceSwitchCallbacks): void;
435
+ }
436
+
437
+ import type { StreamProcessor } from "../processor/stream-processor";
438
+ import type { TranscodeConfig } from "../processor/types";
439
+ export declare class CameraStreamManager {
440
+ private mediaStream;
441
+ private mediaRecorder;
442
+ private recordedChunks;
443
+ private recordedMimeType;
444
+ private state;
445
+ private recordingStartTime;
446
+ private recordingTimer;
447
+ private pauseStartTime;
448
+ private totalPausedTime;
449
+ private readonly eventListeners;
450
+ private readonly streamConfig;
451
+ private readonly recordingOptions;
452
+ private streamProcessor;
453
+ private bufferSizeUpdateInterval;
454
+ private selectedAudioDeviceId;
455
+ private selectedVideoDeviceId;
456
+ constructor(streamConfig?: Partial<StreamConfig>, recordingOptions?: Partial<RecordingOptions>);
457
+ getState(): StreamState;
458
+ getStream(): MediaStream | null;
459
+ getAudioStreamForAnalysis(): MediaStream | null;
460
+ getRecorder(): MediaRecorder | null;
461
+ isRecording(): boolean;
462
+ isActive(): boolean;
463
+ on<T extends keyof StreamEventMap>(event: T, listener: StreamEventListener<T>): () => void;
464
+ off<T extends keyof StreamEventMap>(event: T, listener: StreamEventListener<T>): void;
465
+ once<T extends keyof StreamEventMap>(event: T, listener: StreamEventListener<T>): () => void;
466
+ private emit;
467
+ private setState;
468
+ setAudioDevice(deviceId: string | null): void;
469
+ setVideoDevice(deviceId: string | null): void;
470
+ getAudioDevice(): string | null;
471
+ getVideoDevice(): string | null;
472
+ getAvailableDevices(): Promise<{
473
+ audioinput: MediaDeviceInfo[];
474
+ videoinput: MediaDeviceInfo[];
475
+ }>;
476
+ private buildVideoConstraints;
477
+ private buildAudioConstraints;
478
+ startStream(): Promise<MediaStream>;
479
+ stopStream(): void;
480
+ private stopStreamTracks;
481
+ private isTrackLive;
482
+ private tryReplaceTrack;
483
+ private recreateStreamWithNewTrack;
484
+ switchVideoDevice(deviceId: string | null): Promise<MediaStream>;
485
+ switchAudioDevice(deviceId: string | null): Promise<MediaStream>;
486
+ startRecordingWithMediaRecorder(): void;
487
+ stopRecordingWithMediaRecorder(): void;
488
+ startRecording(processor: StreamProcessor, config: TranscodeConfig): Promise<void>;
489
+ stopRecording(): Promise<Blob>;
490
+ pauseRecording(): void;
491
+ resumeRecording(): void;
492
+ toggleMute(): void;
493
+ private setAudioTracksEnabled;
494
+ muteAudio(): void;
495
+ unmuteAudio(): void;
496
+ isMuted(): boolean;
497
+ switchVideoSource(newStream: MediaStream): Promise<void>;
498
+ setMediaStream(stream: MediaStream): void;
499
+ getCurrentVideoSource(): MediaStream;
500
+ private formatTimeElapsed;
501
+ private startRecordingTimer;
502
+ private clearRecordingTimer;
503
+ private clearBufferSizeInterval;
504
+ private resetRecordingState;
505
+ private resetPauseState;
506
+ getRecordedBlob(): Blob;
507
+ destroy(): void;
508
+ }
509
+
510
+ export declare class CanvasRenderer {
511
+ private readonly canvasContext;
512
+ constructor(canvasContext: OffscreenCanvasRenderingContext2D);
513
+ clear(): void;
514
+ drawFrame(videoElement: HTMLVideoElement): void;
515
+ getContext(): OffscreenCanvasRenderingContext2D;
516
+ }
517
+
518
+ export declare class StreamProcessor {
519
+ private readonly outputManager;
520
+ private canvasSource;
521
+ private offscreenCanvas;
522
+ private readonly videoElementManager;
523
+ private canvasRenderer;
524
+ private readonly frameCapturer;
525
+ private readonly audioTrackManager;
526
+ private currentVideoStream;
527
+ private onSourceChange?;
528
+ constructor();
529
+ startProcessing(stream: MediaStream, config: TranscodeConfig): Promise<void>;
530
+ pause(): void;
531
+ resume(): void;
532
+ isPausedState(): boolean;
533
+ finalize(): Promise<StreamProcessorResult>;
534
+ toggleMute(): void;
535
+ isMutedState(): boolean;
536
+ getClonedAudioTrack(): MediaStreamTrack | null;
537
+ getAudioStreamForAnalysis(): MediaStream | null;
538
+ switchVideoSource(newStream: MediaStream): Promise<void>;
539
+ getCurrentVideoSource(): MediaStream | null;
540
+ getBufferSize(): number;
541
+ setOnMuteStateChange(callback: (muted: boolean) => void): void;
542
+ setOnSourceChange(callback: (stream: MediaStream) => void): void;
543
+ cancel(): Promise<void>;
544
+ }
545
+
546
+ export type TranscodeConfig = {
547
+ format: "mp4";
548
+ fps: number;
549
+ width: number;
550
+ height: number;
551
+ bitrate: number;
552
+ audioCodec: "aac";
553
+ preset: "medium";
554
+ packetCount: number;
555
+ audioBitrate?: number;
556
+ };
557
+ export type TranscodeInput = Blob | File | string;
558
+ export type TranscodeResult = {
559
+ buffer: ArrayBuffer;
560
+ blob: Blob;
561
+ };
562
+ export type StreamProcessorResult = {
563
+ blob: Blob;
564
+ totalSize: number;
565
+ };
566
+ export type StreamProcessorOptions = Record<string, never>;
567
+
568
+ import { Output } from "mediabunny";
569
+ export declare class OutputManager {
570
+ private output;
571
+ private readonly chunks;
572
+ private totalSize;
573
+ create(): Output;
574
+ getOutput(): Output;
575
+ getChunks(): Array<{
576
+ data: Uint8Array;
577
+ position: number;
578
+ }>;
579
+ finalize(): Promise<StreamProcessorResult>;
580
+ cancel(): Promise<void>;
581
+ getTotalSize(): number;
582
+ }
583
+
584
+ export declare function transcodeVideo(input: TranscodeInput, config?: Partial<TranscodeConfig>, onProgress?: (progress: number) => void): Promise<TranscodeResult>;
585
+
586
+ export declare class VideoElementManager {
587
+ private videoElement;
588
+ private isActive;
589
+ private isIntentionallyPaused;
590
+ create(stream: MediaStream): HTMLVideoElement;
591
+ waitForReady(): Promise<void>;
592
+ switchSource(newStream: MediaStream): Promise<void>;
593
+ getElement(): HTMLVideoElement | null;
594
+ setActive(active: boolean): void;
595
+ pause(): void;
596
+ resume(): void;
597
+ cleanup(): void;
598
+ private waitForVideoReady;
599
+ }
600
+
601
+ import type { CanvasSource } from "mediabunny";
602
+ export declare class FrameCapturer {
603
+ private timeoutId;
604
+ private isActive;
605
+ private isPaused;
606
+ private frameCount;
607
+ private lastFrameTimestamp;
608
+ private currentFrameRate;
609
+ private canvasSource;
610
+ private canvasRenderer;
611
+ private videoElement;
612
+ private pendingFrameAdd;
613
+ start(canvasSource: CanvasSource, canvasRenderer: CanvasRenderer, videoElement: HTMLVideoElement, frameRate: number): void;
614
+ pause(): void;
615
+ resume(): void;
616
+ isPausedState(): boolean;
617
+ getLastFrameTimestamp(): number;
618
+ waitForPendingFrames(): Promise<void>;
619
+ stop(): void;
620
+ private captureFrame;
621
+ private canCaptureFrame;
622
+ private isVideoReady;
623
+ private renderFrame;
624
+ private addFrameToSource;
625
+ private scheduleNextFrame;
626
+ }
627
+
628
+ import { AudioSampleSource } from "mediabunny";
629
+ export declare class AudioTrackManager {
630
+ private originalAudioTrack;
631
+ private audioContext;
632
+ private audioWorkletNode;
633
+ private mediaStreamSource;
634
+ private gainNode;
635
+ private audioSource;
636
+ private lastAudioTimestamp;
637
+ private isMuted;
638
+ private isPaused;
639
+ private onMuteStateChange?;
640
+ setupAudioTrack(stream: MediaStream, config: TranscodeConfig): Promise<AudioSampleSource | null>;
641
+ toggleMute(): void;
642
+ isMutedState(): boolean;
643
+ pause(): void;
644
+ resume(): AudioSampleSource | null;
645
+ isPausedState(): boolean;
646
+ getClonedAudioTrack(): MediaStreamTrack | null;
647
+ getAudioSource(): AudioSampleSource | null;
648
+ getAudioStreamForAnalysis(): MediaStream | null;
649
+ getLastAudioTimestamp(): number;
650
+ setOnMuteStateChange(callback: (muted: boolean) => void): void;
651
+ cleanup(): void;
652
+ }
653
+
654
+ export declare function calculateBarColor(position: number): string;
655
+
656
+ export declare const FILE_SIZE_UNITS: readonly ["Bytes", "KB", "MB", "GB"];
657
+ export declare const FILE_SIZE_BASE = 1024;
658
+ export declare function formatFileSize(bytes: number): string;
659
+ export declare function formatTime(totalSeconds: number): string;
660
+
661
+ export declare function extractErrorMessage(error: unknown): string;
662
+
663
+ export type PendingUpload = {
664
+ id: string;
665
+ blob: Blob;
666
+ apiKey: string;
667
+ backendUrl: string;
668
+ filename: string;
669
+ duration?: number;
670
+ metadata?: Record<string, unknown>;
671
+ userMetadata?: Record<string, unknown>;
672
+ status: "pending" | "uploading" | "failed" | "completed";
673
+ retryCount: number;
674
+ lastError?: string;
675
+ createdAt: number;
676
+ updatedAt: number;
677
+ };
678
+ export declare class VideoStorageService {
679
+ private db;
680
+ init(): Promise<void>;
681
+ isInitialized(): boolean;
682
+ savePendingUpload(upload: Omit<PendingUpload, "id" | "createdAt" | "updatedAt" | "status" | "retryCount">): Promise<string>;
683
+ getPendingUploads(status?: PendingUpload["status"]): Promise<PendingUpload[]>;
684
+ updateUploadStatus(id: string, updates: Partial<PendingUpload>): Promise<void>;
685
+ deleteUpload(id: string): Promise<void>;
686
+ cleanupPermanentlyFailedUploads(retentionHours?: number): Promise<number>;
687
+ getTotalStorageSize(): Promise<number>;
688
+ private generateUploadId;
689
+ private executeTransaction;
690
+ }
691
+
692
+ import type { UploadResult } from "../types/recorder-types";
693
+ export type UploadCallbacks = {
694
+ onUploadProgress: (id: string, progress: number) => void;
695
+ onUploadComplete: (id: string, result: UploadResult) => void;
696
+ onUploadError: (id: string, error: Error) => void;
697
+ };
698
+
699
+ import { UploadQueueManager } from "../upload/upload-queue-manager";
700
+ import type { VideoUploadService } from "../upload/video-upload-service";
701
+ export declare class StorageManager {
702
+ private storageService;
703
+ private uploadQueueManager;
704
+ private cleanupIntervalId;
705
+ initialize(uploadService: VideoUploadService | null, callbacks: UploadCallbacks, onCleanupError: (error: string) => void): Promise<void>;
706
+ checkPendingUploads(): Promise<{
707
+ pending: number;
708
+ uploading: number;
709
+ }>;
710
+ performCleanup(): Promise<void>;
711
+ getUploadQueueManager(): UploadQueueManager | null;
712
+ getStorageService(): VideoStorageService | null;
713
+ destroy(): void;
714
+ }
715
+
716
+ export type StorageQuota = {
717
+ usage: number;
718
+ quota: number;
719
+ available: number;
720
+ percentage: number;
721
+ };
722
+ export declare class QuotaManager {
723
+ getQuota(): Promise<StorageQuota>;
724
+ hasSpaceFor(sizeInBytes: number): Promise<boolean>;
725
+ requestPersistentStorage(): Promise<boolean>;
726
+ isPersistent(): Promise<boolean>;
727
+ formatBytes(bytes: number): string;
728
+ shouldWarn(threshold?: number): Promise<boolean>;
729
+ isCritical(threshold?: number): Promise<boolean>;
730
+ private checkThreshold;
731
+ }
732
+
733
+ export type AudioLevelCallbacks = {
734
+ onLevelUpdate: (level: number, isMuted: boolean) => void;
735
+ };
736
+
737
+ export declare class AudioLevelAnalyzer {
738
+ private audioContext;
739
+ private analyser;
740
+ private audioLevelIntervalId;
741
+ private audioLevel;
742
+ private getMutedState;
743
+ private currentStream;
744
+ startTracking(stream: MediaStream, callbacks: AudioLevelCallbacks, getMutedState?: () => boolean): void;
745
+ stopTracking(): void;
746
+ getAudioLevel(): number;
747
+ private getAudioContextClass;
748
+ private calculateAudioLevel;
749
+ private checkMutedState;
750
+ }
751
+
752
+ import type { AudioLevelCallbacks } from "../audio/types";
753
+ import type { DeviceCallbacks } from "../device/types";
754
+ import type { RecordingCallbacks } from "../recording/types";
755
+ import type { UploadCallbacks as StorageUploadCallbacks } from "../storage/types";
756
+ import type { SourceType } from "../types/recorder-types";
757
+ import type { UploadCallbacks } from "../upload/types";
758
+ export type RecorderConfig = {
759
+ apiKey?: string | null;
760
+ backendUrl?: string | null;
761
+ countdownDuration?: number;
762
+ maxRecordingTime?: number | null;
763
+ userMetadata?: Record<string, unknown>;
764
+ };
765
+ export type RecorderCallbacks = {
766
+ recording?: RecordingCallbacks;
767
+ audioLevel?: AudioLevelCallbacks;
768
+ device?: DeviceCallbacks;
769
+ upload?: UploadCallbacks;
770
+ storage?: StorageUploadCallbacks;
771
+ sourceSwitch?: {
772
+ onSourceChange?: (sourceType: SourceType) => void;
773
+ onPreviewUpdate?: (stream: MediaStream) => Promise<void>;
774
+ onError?: (error: Error) => void;
775
+ onTransitionStart?: (message: string) => void;
776
+ onTransitionEnd?: () => void;
777
+ };
778
+ stream?: {
779
+ onStreamStart?: (stream: MediaStream) => void;
780
+ onStreamStop?: () => void;
781
+ onError?: (error: Error) => void;
782
+ };
783
+ onStorageCleanupError?: (error: string) => void;
784
+ };
785
+
786
+ import type { AudioLevelAnalyzer } from "../audio/audio-level-analyzer";
787
+ import type { ConfigManager } from "../config/config-manager";
788
+ import type { DeviceManager } from "../device/device-manager";
789
+ import type { RecordingCallbacks } from "../recording/types";
790
+ import type { SourceSwitchCallbacks } from "../stream/source-switch";
791
+ export declare function createRecordingCallbacks(callbacks: RecorderCallbacks, audioLevelAnalyzer: AudioLevelAnalyzer, configManager: ConfigManager): RecordingCallbacks;
792
+ export declare function createSourceSwitchCallbacks(callbacks: RecorderCallbacks, deviceManager: DeviceManager): SourceSwitchCallbacks;
793
+
794
+ import type { AudioLevelCallbacks } from "../audio/types";
795
+ import { DeviceManager } from "../device/device-manager";
796
+ import { CameraStreamManager } from "../stream/stream";
797
+ import type { SourceType } from "../types/recorder-types";
798
+ export declare class RecorderController {
799
+ private readonly streamManager;
800
+ private readonly configManager;
801
+ private readonly storageManager;
802
+ private readonly deviceManager;
803
+ private readonly audioLevelAnalyzer;
804
+ private readonly uploadManager;
805
+ private readonly recordingManager;
806
+ private readonly sourceSwitchManager;
807
+ private readonly uploadService;
808
+ private readonly muteStateManager;
809
+ private isInitialized;
810
+ constructor(callbacks?: RecorderCallbacks);
811
+ initialize(config: RecorderConfig): Promise<void>;
812
+ startStream(): Promise<void>;
813
+ stopStream(): Promise<void>;
814
+ switchVideoDevice(deviceId: string | null): Promise<MediaStream>;
815
+ switchAudioDevice(deviceId: string | null): Promise<MediaStream>;
816
+ startRecording(): Promise<void>;
817
+ stopRecording(): Promise<Blob>;
818
+ pauseRecording(): void;
819
+ resumeRecording(): void;
820
+ switchSource(_sourceType: SourceType): Promise<void>;
821
+ setCameraDevice(deviceId: string | null): void;
822
+ setMicDevice(deviceId: string | null): void;
823
+ getAvailableDevices(): Promise<import("../..").AvailableDevices>;
824
+ muteAudio(): void;
825
+ unmuteAudio(): void;
826
+ toggleMute(): void;
827
+ getIsMuted(): boolean;
828
+ startAudioLevelTracking(stream: MediaStream, callbacks?: AudioLevelCallbacks): Promise<void>;
829
+ stopAudioLevelTracking(): void;
830
+ getAudioLevel(): number;
831
+ uploadVideo(blob: Blob, apiKey: string, backendUrl: string, metadata: Record<string, unknown>): Promise<void>;
832
+ getStream(): MediaStream | null;
833
+ getRecordingState(): import("../..").RecordingState;
834
+ isPaused(): boolean;
835
+ getCurrentSourceType(): SourceType;
836
+ getOriginalCameraStream(): MediaStream | null;
837
+ getStreamManager(): CameraStreamManager;
838
+ getAudioStreamForAnalysis(): MediaStream | null;
839
+ getDeviceManager(): DeviceManager;
840
+ getConfig(): Promise<import("../..").TranscodeConfig>;
841
+ isRecording(): boolean;
842
+ isActive(): boolean;
843
+ cleanup(): void;
844
+ }
845
+
846
+ import type { CameraStreamManager } from "../stream/stream";
847
+ export declare class MuteStateManager {
848
+ private isMuted;
849
+ private readonly streamManager;
850
+ constructor(streamManager: CameraStreamManager);
851
+ mute(): void;
852
+ unmute(): void;
853
+ toggle(): void;
854
+ getIsMuted(): boolean;
855
+ getMutedStateCallback(): () => boolean;
856
+ }
857
+
858
+ import type { CameraStreamManager } from "../stream/stream";
859
+ import type { AvailableDevices } from "../types/recorder-types";
860
+ export declare class DeviceManager {
861
+ private readonly streamManager;
862
+ private readonly callbacks?;
863
+ private availableDevices;
864
+ private selectedCameraDeviceId;
865
+ private selectedMicDeviceId;
866
+ constructor(streamManager: CameraStreamManager, callbacks?: DeviceCallbacks);
867
+ getAvailableDevices(): Promise<AvailableDevices>;
868
+ setCameraDevice(deviceId: string | null): void;
869
+ setMicDevice(deviceId: string | null): void;
870
+ getSelectedCameraDeviceId(): string | null;
871
+ getSelectedMicDeviceId(): string | null;
872
+ getAvailableDevicesList(): AvailableDevices;
873
+ }
874
+
875
+ import type { AvailableDevices } from "../types/recorder-types";
876
+ export type DeviceCallbacks = {
877
+ onDevicesChanged: (devices: AvailableDevices) => void;
878
+ onDeviceSelected: (type: "camera" | "mic", deviceId: string | null) => void;
879
+ };
880
+
881
+ import type { UploadResult } from "../types/recorder-types";
882
+ export declare class UploadManager {
883
+ private readonly callbacks;
884
+ private uploadQueueManager;
885
+ constructor(callbacks: UploadCallbacks);
886
+ setUploadQueueManager(uploadQueueManager: UploadQueueManager | null): void;
887
+ uploadVideo(blob: Blob, apiKey: string, backendUrl: string, userMetadata: Record<string, unknown>): Promise<void>;
888
+ updateProgress(progress: number): void;
889
+ showSuccess(result: UploadResult): void;
890
+ showError(message: string): void;
891
+ clearStatus(): void;
892
+ }
893
+
894
+ import type { PendingUpload, VideoStorageService } from "../storage/video-storage";
895
+ type UploadCallbacks = {
896
+ onUploadProgress?: (id: string, progress: number) => void;
897
+ onUploadComplete?: (id: string, result: VideoUploadResult) => void;
898
+ onUploadError?: (id: string, error: Error) => void;
899
+ };
900
+ export declare class UploadQueueManager {
901
+ private readonly storageService;
902
+ private readonly uploadService;
903
+ private readonly processingIntervalId;
904
+ private readonly networkOnlineHandler;
905
+ private isProcessing;
906
+ private retryTimeoutId;
907
+ private callbacks;
908
+ constructor(storageService: VideoStorageService, uploadService: VideoUploadService);
909
+ destroy(): void;
910
+ setCallbacks(callbacks: UploadCallbacks): void;
911
+ queueUpload(upload: Omit<PendingUpload, "id" | "createdAt" | "updatedAt" | "status" | "retryCount">): Promise<string>;
912
+ processQueue(): Promise<void>;
913
+ getPendingUploads(): Promise<PendingUpload[]>;
914
+ getStats(): Promise<{
915
+ pending: number;
916
+ uploading: number;
917
+ failed: number;
918
+ total: number;
919
+ }>;
920
+ private getOldestUpload;
921
+ private getOldestFailedUpload;
922
+ private processUpload;
923
+ private calculateRetryDelay;
924
+ private scheduleRetry;
925
+ private clearTimer;
926
+ }
927
+ export {};
928
+
929
+ export declare function extractVideoDuration(blob: Blob): Promise<number>;
930
+
931
+ import type { UploadResult } from "../types/recorder-types";
932
+ export type UploadCallbacks = {
933
+ onProgress: (progress: number) => void;
934
+ onSuccess: (result: UploadResult) => void;
935
+ onError: (error: Error) => void;
936
+ onClearStatus: () => void;
937
+ };
938
+
939
+ export type VideoUploadOptions = {
940
+ apiKey: string;
941
+ backendUrl: string;
942
+ filename?: string;
943
+ metadata?: Record<string, unknown>;
944
+ userMetadata?: Record<string, unknown>;
945
+ duration?: number;
946
+ onProgress?: (progress: number) => void;
947
+ };
948
+ export type VideoUploadInitResponse = {
949
+ videoId: string;
950
+ uploadUrl: string;
951
+ };
952
+ export type VideoUploadResult = {
953
+ videoId: string;
954
+ status: string;
955
+ uploadUrl: string;
956
+ };
957
+ export declare class VideoUploadService {
958
+ uploadVideo(blob: Blob, options: VideoUploadOptions): Promise<VideoUploadResult>;
959
+ private initVideoUpload;
960
+ private extractErrorFromResponse;
961
+ private uploadVideoFile;
962
+ private parseSuccessResponse;
963
+ private parseErrorResponse;
964
+ }