|
| 1 | +declare module 'media-recorder-js' { |
| 2 | + interface QBMediaRecorderConstructorProps { |
| 3 | + /** Preferred MIME type */ |
| 4 | + mimeType?: string |
| 5 | + workerPath?: string |
| 6 | + /** |
| 7 | + * The minimum number of milliseconds of data to return |
| 8 | + * in a single Blob, fire 'ondataavaible' callback |
| 9 | + * (isn't need to use with 'audio/wav' of 'audio/mp3') |
| 10 | + * |
| 11 | + * @default 1000 |
| 12 | + */ |
| 13 | + timeslice?: number |
| 14 | + /** |
| 15 | + * What to do with a muted input MediaStreamTrack, |
| 16 | + * e.g. insert black frames/zero audio volume in the recording |
| 17 | + * or ignore altogether |
| 18 | + * |
| 19 | + * @default true |
| 20 | + */ |
| 21 | + ignoreMutedMedia?: boolean |
| 22 | + /** Recording start event handler */ |
| 23 | + onstart?: VoidFunction |
| 24 | + /** Recording stop event handler */ |
| 25 | + onstop?: (file: Blob) => void |
| 26 | + /** Recording pause event handler */ |
| 27 | + onpause?: VoidFunction |
| 28 | + /** Recording resume event handler */ |
| 29 | + onresume?: VoidFunction |
| 30 | + /** Error event handler */ |
| 31 | + onerror?: (error: unknown) => void |
| 32 | + /** |
| 33 | + * `dataavailable` event handler. |
| 34 | + * The Blob of recorded data is contained in this event (callback |
| 35 | + * isn't supported if use 'audio/wav' of 'audio/mp3' for recording) |
| 36 | + */ |
| 37 | + ondataavailable?: (event: { data: Blob }) => void |
| 38 | + } |
| 39 | + |
| 40 | + class QBMediaRecorder { |
| 41 | + constructor(config: QBMediaRecorderConstructorProps) |
| 42 | + |
| 43 | + /** |
| 44 | + * Switch recording Blob objects to the specified |
| 45 | + * MIME type if `MediaRecorder` support it. |
| 46 | + */ |
| 47 | + toggleMimeType(mimeType: string): void |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns current `MediaRecorder` state |
| 51 | + */ |
| 52 | + getState(): 'inactive' | 'recording' | 'paused' |
| 53 | + |
| 54 | + /** |
| 55 | + * Starts recording a stream. |
| 56 | + * Fires `onstart` callback. |
| 57 | + */ |
| 58 | + start(stream: MediaStream): void |
| 59 | + |
| 60 | + /** |
| 61 | + * Stops recording a stream |
| 62 | + * |
| 63 | + * @fires `onstop` callback and passing there Blob recorded |
| 64 | + */ |
| 65 | + stop(): void |
| 66 | + |
| 67 | + /** Pausing stream recording */ |
| 68 | + pause(): void |
| 69 | + |
| 70 | + /** Resumes stream recording */ |
| 71 | + resume(): void |
| 72 | + |
| 73 | + /** |
| 74 | + * Change record source |
| 75 | + */ |
| 76 | + change(stream: MediaStream): void |
| 77 | + |
| 78 | + /** |
| 79 | + * Create a file from blob and download as file. |
| 80 | + * This method will call `stop` if recording is in progress. |
| 81 | + * |
| 82 | + * @param {string} filename Name of video file to be downloaded |
| 83 | + * (default to `Date.now()`) |
| 84 | + */ |
| 85 | + download(filename?: string): void |
| 86 | + |
| 87 | + _getBlobRecorded(): Blob |
| 88 | + |
| 89 | + callbacks: Pick< |
| 90 | + QBMediaRecorderConstructorProps, |
| 91 | + | 'onstart' |
| 92 | + | 'onstop' |
| 93 | + | 'onpause' |
| 94 | + | 'onresume' |
| 95 | + | 'ondataavailable' |
| 96 | + | 'onerror' |
| 97 | + > |
| 98 | + |
| 99 | + /** |
| 100 | + * Checks capability of recording in the environment. |
| 101 | + * Checks `MediaRecorder`, `MediaRecorder.isTypeSupported` and `Blob`. |
| 102 | + */ |
| 103 | + static isAvailable(): boolean |
| 104 | + |
| 105 | + /** |
| 106 | + * Checks if AudioContext API is available. |
| 107 | + * Checks `window.AudioContext` or `window.webkitAudioContext`. |
| 108 | + */ |
| 109 | + static isAudioContext(): boolean |
| 110 | + /** |
| 111 | + * The `QBMediaRecorder.isTypeSupported()` static method returns |
| 112 | + * a Boolean which is true if the MIME type specified is one |
| 113 | + * the user agent should be able to successfully record. |
| 114 | + * @param mimeType The MIME media type to check. |
| 115 | + * |
| 116 | + * @returns true if the `MediaRecorder` implementation is capable of |
| 117 | + * recording `Blob` objects for the specified MIME type. Recording may |
| 118 | + * still fail if there are insufficient resources to support the |
| 119 | + * recording and encoding process. If the value is false, the user |
| 120 | + * agent is incapable of recording the specified format. |
| 121 | + */ |
| 122 | + |
| 123 | + static isTypeSupported(mimeType: string): boolean |
| 124 | + |
| 125 | + /** |
| 126 | + * Return supported mime types |
| 127 | + * @param type video or audio (dafault to 'video') |
| 128 | + */ |
| 129 | + static getSupportedMimeTypes(type: 'audio' | 'video' = 'video'): string[] |
| 130 | + } |
| 131 | + |
| 132 | + export default QBMediaRecorder |
| 133 | +} |
0 commit comments