|
| 1 | +--- |
| 2 | +outline: deep |
| 3 | +--- |
| 4 | + |
| 5 | +# API |
| 6 | + |
| 7 | +## Props |
| 8 | + |
| 9 | +### `constraints` |
| 10 | + |
| 11 | +- Type: `MediaStreamConstraints` |
| 12 | +- Required: `true` |
| 13 | + |
| 14 | +The constraints parameter is a MediaStreamConstraints object specifying the types of media to request, along with any |
| 15 | +requirements for each type. |
| 16 | + |
| 17 | +### `mediaRecorderOptions` |
| 18 | + |
| 19 | +- Type: `MediaRecorderOptions` |
| 20 | +- Default: `{}` |
| 21 | + |
| 22 | +Options to pass to the MediaRecorder constructor. [See MDN](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder#options) |
| 23 | + |
| 24 | +## Events |
| 25 | + |
| 26 | +```ts |
| 27 | +defineEmits<{ |
| 28 | + start: [ev: Event] |
| 29 | + stop: [ev: Event] |
| 30 | + pause: [ev: Event] |
| 31 | + resume: [ev: Event] |
| 32 | + error: [ev: Event] |
| 33 | +}>() |
| 34 | +``` |
| 35 | + |
| 36 | +Analog to the MediaRecorder events (`onstart`, `onpause`,...). |
| 37 | + |
| 38 | +### `@start` |
| 39 | + |
| 40 | +Emitted when the MediaRecorder starts recording. |
| 41 | + |
| 42 | +### `@pause` |
| 43 | + |
| 44 | +Emitted when the MediaRecorder pauses recording. |
| 45 | + |
| 46 | +### `@resume` |
| 47 | + |
| 48 | +Emitted when the MediaRecorder resumes recording. |
| 49 | + |
| 50 | +### `@stop` |
| 51 | + |
| 52 | +Emitted when the MediaRecorder stops recording. |
| 53 | + |
| 54 | +### `@error` |
| 55 | + |
| 56 | +Emitted when an error occurs. |
| 57 | + |
| 58 | +## Slots |
| 59 | + |
| 60 | +### `default` |
| 61 | + |
| 62 | +The default slot is used to render the component's content. |
| 63 | + |
| 64 | +#### slopProps |
| 65 | + |
| 66 | +##### `data` |
| 67 | + |
| 68 | +- Type: `Ref<Blob[]>` |
| 69 | +- Initial value: `ref([])` |
| 70 | + |
| 71 | +An array of Blobs that are created by the MediaRecorder. The Blobs are created when the MediaRecorder is stopped. Or |
| 72 | +when the timeslice is set and the timeslice is reached. |
| 73 | + |
| 74 | +##### `stream` |
| 75 | + |
| 76 | +- Type: `ShallowRef<MediaStream | undefined>` |
| 77 | +- Initial value: `shallowRef()` |
| 78 | + |
| 79 | +##### `state` |
| 80 | + |
| 81 | +- Type: `ShallowRef<MediaRecorderState | undefined>` |
| 82 | +- Initial value: `shallowRef()` |
| 83 | + |
| 84 | +The current state of the MediaRecorder. The state can be one of the following: |
| 85 | + |
| 86 | +- `undefined` - The MediaRecorder is not initialized. |
| 87 | +- `'inactive'` - The MediaRecorder is not recording. |
| 88 | +- `'recording'` - The MediaRecorder is recording data. |
| 89 | +- `'paused'` - The MediaRecorder is paused. |
| 90 | + |
| 91 | +##### `mimeType` |
| 92 | + |
| 93 | +- Type: `ComputedRef<string | undefined>` |
| 94 | +- Initial value: `computed(()=>{})` |
| 95 | + |
| 96 | +The mimeType of the MediaRecorder. The mimeType is set when the MediaRecorder is initialized and the stream is |
| 97 | +available. You can also set the mimeType manually via [`mediaRecorderOptions.mimeType`](#mediarecorderoptions). |
| 98 | + |
| 99 | +::: warning |
| 100 | +If you set the mimeType manually (not recommended), make sure that the mimeType is supported by the browser. You can |
| 101 | +check if the mimeType |
| 102 | +is supported via [`isMimeTypeSupported`](#ismimetypesupported). |
| 103 | +::: |
| 104 | + |
| 105 | +##### `isMimeTypeSupported` |
| 106 | + |
| 107 | +- Type: `ComputedRef<boolean>` |
| 108 | + |
| 109 | +If you set the mimeType manually, you can check if the mimeType is supported by the browser via this computed ref. |
| 110 | + |
| 111 | +##### `isSupported` |
| 112 | + |
| 113 | +- Type: `ComputedRef<boolean>` |
| 114 | + |
| 115 | +If the MediaRecorder API (and the selected MIME type) is supported by the browser. |
| 116 | + |
| 117 | +##### `mediaRecorder` |
| 118 | + |
| 119 | +- Type: `ComputedRef<MediaRecorder | undefined>` |
| 120 | +- Initial value: `computed(()=>{})` |
| 121 | + |
| 122 | +The MediaRecorder instance. The MediaRecorder is created when the stream is available. |
| 123 | + |
| 124 | +##### `start` |
| 125 | + |
| 126 | +- Type: `(timeslice: number | undefined) => Promise<void>` |
| 127 | +- MDN: [MediaRecorder.start()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/start) |
| 128 | + |
| 129 | +Creates the stream and the MediaRecorder instance. The stream is created with the constraints object. The MediaRecorder |
| 130 | +is created with the stream and the mediaRecorderOptions object. |
| 131 | + |
| 132 | +##### `pause` |
| 133 | + |
| 134 | +- Type: `() => void` |
| 135 | +- MDN: [MediaRecorder.pause()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/pause) |
| 136 | + |
| 137 | +##### `resume` |
| 138 | + |
| 139 | +- Type: `() => void` |
| 140 | +- MDN: [MediaRecorder.resume()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/resume) |
| 141 | + |
| 142 | +##### `stop` |
| 143 | + |
| 144 | +- Type: `() => void` |
| 145 | +- MDN: [MediaRecorder.stop()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/stop) |
| 146 | + |
| 147 | +## Methods |
| 148 | + |
| 149 | +`UseMediaRecorder` does expose the following methods: |
| 150 | + |
| 151 | +### `start(timeslice: number | undefined): Promise<void>` |
| 152 | + |
| 153 | +- MDN: [MediaRecorder.start()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/start) |
| 154 | + |
| 155 | +Creates the stream and the MediaRecorder instance. The stream is created with the constraints object. The MediaRecorder |
| 156 | +is created with the stream and the mediaRecorderOptions object. |
| 157 | + |
| 158 | +### `pause(): void` |
| 159 | + |
| 160 | +- MDN: [MediaRecorder.pause()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/pause) |
| 161 | + |
| 162 | +### `resume(): void` |
| 163 | + |
| 164 | +- MDN: [MediaRecorder.resume()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/resume) |
| 165 | + |
| 166 | +### `stop(): void` |
| 167 | + |
| 168 | +- MDN: [MediaRecorder.stop()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/stop) |
| 169 | + |
| 170 | +### Usage |
| 171 | + |
| 172 | +```vue |
| 173 | +<script setup> |
| 174 | +import { ref } from 'vue' |
| 175 | +const mr = ref() // or template ref |
| 176 | +
|
| 177 | +mr.value.start() |
| 178 | +</script> |
| 179 | +
|
| 180 | +<template> |
| 181 | + <UseMediaRecorder ref="mr" /> |
| 182 | +</template> |
| 183 | +``` |
0 commit comments