Skip to content

Expose types for MediaRecorder API #44397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions lib/lib.dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ interface BiquadFilterOptions extends AudioNodeOptions {
type?: BiquadFilterType;
}

interface BlobEventInit extends EventInit {
data: Blob;
timecode?: DOMHighResTimeStamp;
}

interface BlobPropertyBag {
endings?: EndingType;
type?: string;
Expand Down Expand Up @@ -727,6 +732,18 @@ interface MediaQueryListEventInit extends EventInit {
media?: string;
}

interface MediaRecorderErrorEventInit extends EventInit {
error: DOMException;
}

interface MediaRecorderOptions {
mimeType?: string;
audioBitsPerSecond?: number;
videoBitsPerSecond?: number;
bitsPerSecond?: number;
audioBitrateMode?: BitrateMode;
}

interface MediaStreamAudioSourceOptions {
mediaStream: MediaStream;
}
Expand Down Expand Up @@ -2619,6 +2636,16 @@ declare var Blob: {
new(blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
};

interface BlobEvent extends Event {
readonly data: Blob;
readonly timecode: DOMHighResTimeStamp;
}

declare var BlobEvent: {
prototype: BlobEvent;
new(type: string, eventInitDict: BlobEventInit): BlobEvent;
}

interface Body {
readonly body: ReadableStream<Uint8Array> | null;
readonly bodyUsed: boolean;
Expand Down Expand Up @@ -4720,6 +4747,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad
createEvent(eventInterface: "AnimationPlaybackEvent"): AnimationPlaybackEvent;
createEvent(eventInterface: "AudioProcessingEvent"): AudioProcessingEvent;
createEvent(eventInterface: "BeforeUnloadEvent"): BeforeUnloadEvent;
createEvent(eventInterface: "BlobEvent"): BlobEvent;
createEvent(eventInterface: "ClipboardEvent"): ClipboardEvent;
createEvent(eventInterface: "CloseEvent"): CloseEvent;
createEvent(eventInterface: "CompositionEvent"): CompositionEvent;
Expand All @@ -4746,6 +4774,7 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad
createEvent(eventInterface: "MediaEncryptedEvent"): MediaEncryptedEvent;
createEvent(eventInterface: "MediaKeyMessageEvent"): MediaKeyMessageEvent;
createEvent(eventInterface: "MediaQueryListEvent"): MediaQueryListEvent;
createEvent(eventInterface: "MediaRecorderErrorEvent"): MediaRecorderErrorEvent;
createEvent(eventInterface: "MediaStreamErrorEvent"): MediaStreamErrorEvent;
createEvent(eventInterface: "MediaStreamEvent"): MediaStreamEvent;
createEvent(eventInterface: "MediaStreamTrackEvent"): MediaStreamTrackEvent;
Expand Down Expand Up @@ -4970,6 +4999,7 @@ interface DocumentEvent {
createEvent(eventInterface: "AnimationPlaybackEvent"): AnimationPlaybackEvent;
createEvent(eventInterface: "AudioProcessingEvent"): AudioProcessingEvent;
createEvent(eventInterface: "BeforeUnloadEvent"): BeforeUnloadEvent;
createEvent(eventInterface: "BlobEvent"): BlobEvent;
createEvent(eventInterface: "ClipboardEvent"): ClipboardEvent;
createEvent(eventInterface: "CloseEvent"): CloseEvent;
createEvent(eventInterface: "CompositionEvent"): CompositionEvent;
Expand All @@ -4996,6 +5026,7 @@ interface DocumentEvent {
createEvent(eventInterface: "MediaEncryptedEvent"): MediaEncryptedEvent;
createEvent(eventInterface: "MediaKeyMessageEvent"): MediaKeyMessageEvent;
createEvent(eventInterface: "MediaQueryListEvent"): MediaQueryListEvent;
createEvent(eventInterface: "MediaRecorderErrorEvent"): MediaRecorderErrorEvent;
createEvent(eventInterface: "MediaStreamErrorEvent"): MediaStreamErrorEvent;
createEvent(eventInterface: "MediaStreamEvent"): MediaStreamEvent;
createEvent(eventInterface: "MediaStreamTrackEvent"): MediaStreamTrackEvent;
Expand Down Expand Up @@ -10322,6 +10353,58 @@ declare var MediaQueryListEvent: {
new(type: string, eventInitDict?: MediaQueryListEventInit): MediaQueryListEvent;
};

interface MediaRecorderEventMap {
"dataavailable": BlobEvent;
"error": MediaRecorderErrorEvent;
"pause": Event;
"resume": Event;
"start": Event;
"stop": Event;
}

interface MediaRecorder extends EventTarget {
readonly stream: MediaStream;
readonly mimeType: string;
readonly state: RecordingState;
readonly videoBitsPerSecond: number;
readonly audioBitsPerSecond: number;
readonly audioBitrateMode: BitrateMode;

ondataavailable: ((event: BlobEvent) => void) | null;
onerror: ((event: MediaRecorderErrorEvent) => void) | null;
onpause: EventListener | null;
onresume: EventListener | null;
onstart: EventListener | null;
onstop: EventListener | null;

addEventListener<K extends keyof MediaRecorderEventMap>(type: K, listener: (this: MediaRecorder, ev: MediaRecorderEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof MediaRecorderEventMap>(type: K, listener: (this: MediaRecorder, ev: MediaRecorderEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;

start(timeslice?: number): void;
stop(): void;
resume(): void;
pause(): void;
requestData(): void;
}

declare var MediaRecorder: {
prototype: MediaRecorder;
new(stream: MediaStream): MediaRecorder;
new(stream: MediaStream, options: MediaRecorderOptions): MediaRecorder;
isTypeSupported(type: string): boolean;
}

interface MediaRecorderErrorEvent extends Event {
readonly error: DOMException;
}

declare var MediaRecorderErrorEvent: {
prototype: MediaRecorderErrorEvent;
new (type: string, eventInitDict: MediaRecorderErrorEventInit): MediaRecorderErrorEvent;
}

interface MediaSourceEventMap {
"sourceclose": Event;
"sourceended": Event;
Expand Down Expand Up @@ -20099,6 +20182,7 @@ type AutoKeyword = "auto";
type AutomationRate = "a-rate" | "k-rate";
type BinaryType = "arraybuffer" | "blob";
type BiquadFilterType = "allpass" | "bandpass" | "highpass" | "highshelf" | "lowpass" | "lowshelf" | "notch" | "peaking";
type BitrateMode = 'vbr' | 'cbr';
type CanPlayTypeResult = "" | "maybe" | "probably";
type CanvasDirection = "inherit" | "ltr" | "rtl";
type CanvasFillRule = "evenodd" | "nonzero";
Expand Down Expand Up @@ -20166,6 +20250,7 @@ type PremultiplyAlpha = "default" | "none" | "premultiply";
type PublicKeyCredentialType = "public-key";
type PushEncryptionKeyName = "auth" | "p256dh";
type PushPermissionState = "denied" | "granted" | "prompt";
type RecordingState = 'inactive' | 'recording' | 'paused';
type RTCBundlePolicy = "balanced" | "max-bundle" | "max-compat";
type RTCDataChannelState = "closed" | "closing" | "connecting" | "open";
type RTCDegradationPreference = "balanced" | "maintain-framerate" | "maintain-resolution";
Expand Down