Skip to content

Commit eb04cab

Browse files
committed
docs: add usage
1 parent 9678e65 commit eb04cab

File tree

3 files changed

+134
-4
lines changed

3 files changed

+134
-4
lines changed

docs/.vitepress/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default defineConfig({
1919
themeConfig: {
2020
// https://vitepress.dev/reference/default-theme-config
2121
nav: [
22-
{ text: 'Home', link: '/' },
2322
{ text: 'Installation', link: '/installation' },
2423
{ text: 'Usage', link: '/usage' },
2524
{ text: 'Examples', link: '/examples' },

docs/usage.md

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ outline: deep
44

55
# Usage
66

7+
## `useMediaRecorder`
8+
79
```vue
810
911
<script setup>
@@ -21,9 +23,138 @@ outline: deep
2123
isMimeTypeSupported,
2224
mimeType,
2325
mediaRecorder,
24-
} = useMediaRecorder({constraints: {audio: true, video: true}})
25-
26+
} = useMediaRecorder({ constraints: { audio: true, video: true } })
27+
2628
start()
2729
</script>
2830
```
2931

32+
## `useMediaRecorder` options
33+
34+
```ts
35+
interface UseMediaRecorderOptions extends ConfigurableNavigator {
36+
/**
37+
* The constraints parameter is a MediaStreamConstraints object specifying the types of media to request, along with any requirements for each type.
38+
*/
39+
constraints?: MaybeRef<MediaStreamConstraints>
40+
/**
41+
* Options to pass to the MediaRecorder constructor.
42+
*/
43+
mediaRecorderOptions?: MaybeRef<MediaRecorderOptions>
44+
}
45+
```
46+
47+
```ts
48+
const defaultOptions: UseMediaRecorderOptions = {
49+
constraints: { audio: false, video: false },
50+
mediaRecorderOptions: {},
51+
}
52+
```
53+
54+
### `constraints`
55+
56+
Type: `constraints?: MaybeRef<MediaStreamConstraints>`
57+
58+
The `constraints` object is passed to the `navigator.mediaDevices.getUserMedia` method. It is used to specify the media
59+
types and settings for the stream.
60+
61+
::: warning
62+
By default, the constraints object is `{audio: false, video: false}`. You should set at least one of the properties to
63+
`true` to get a stream/data.
64+
:::
65+
66+
### `mediaRecorderOptions`
67+
68+
Type: `mediaRecorderOptions?: MaybeRef<MediaRecorderOptions>`
69+
70+
[See MDN](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder#options)
71+
72+
```ts
73+
interface MediaRecorderOptions {
74+
audioBitsPerSecond?: number;
75+
bitsPerSecond?: number;
76+
mimeType?: string;
77+
videoBitsPerSecond?: number;
78+
}
79+
```
80+
81+
## `useMediaRecorder` values
82+
83+
### `data`
84+
85+
- Type: `Ref<Blob[]>`
86+
- Initial value: `ref([])`
87+
88+
An array of Blobs that are created by the MediaRecorder. The Blobs are created when the MediaRecorder is stopped. Or
89+
when the timeslice is set and the timeslice is reached.
90+
91+
### `stream`
92+
93+
- Type: `ShallowRef<MediaStream | undefined>`
94+
- Initial value: `shallowRef()`
95+
96+
### `state`
97+
98+
- Type: `ShallowRef<MediaRecorderState | undefined>`
99+
- Initial value: `shallowRef()`
100+
101+
The current state of the MediaRecorder. The state can be one of the following:
102+
103+
- `undefined` - The MediaRecorder is not initialized.
104+
- `'inactive'` - The MediaRecorder is not recording.
105+
- `'recording'` - The MediaRecorder is recording data.
106+
- `'paused'` - The MediaRecorder is paused.
107+
108+
### `mimeType`
109+
110+
- Type: `ComputedRef<string | undefined>`
111+
- Initial value: `computed(()=>{})`
112+
113+
The mimeType of the MediaRecorder. The mimeType is set when the MediaRecorder is initialized and the stream is
114+
available. You can also set the mimeType manually via [`mediaRecorderOptions.mimeType`](#mediarecorderoptions).
115+
116+
::: warning
117+
If you set the mimeType manually (not recommended), make sure that the mimeType is supported by the browser. You can
118+
check if the mimeType
119+
is supported via [`isMimeTypeSupported`](#ismimetypesupported).
120+
:::
121+
122+
### `isMimeTypeSupported`
123+
124+
- Type: `ComputedRef<boolean>`
125+
126+
If you set the mimeType manually, you can check if the mimeType is supported by the browser via this computed ref.
127+
128+
### `isSupported`
129+
130+
- Type: `ComputedRef<boolean>`
131+
132+
If the MediaRecorder API (and the selected MIME type) is supported by the browser.
133+
134+
### `mediaRecorder`
135+
136+
- Type: `ComputedRef<MediaRecorder | undefined>`
137+
- Initial value: `computed(()=>{})`
138+
139+
The MediaRecorder instance. The MediaRecorder is created when the stream is available.
140+
141+
## `useMediaRecorder` methods
142+
143+
### `start(timeslice: number | undefined): Promise<void>`
144+
145+
- MDN: [MediaRecorder.start()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/start)
146+
147+
Creates the stream and the MediaRecorder instance. The stream is created with the constraints object. The MediaRecorder
148+
is created with the stream and the mediaRecorderOptions object.
149+
150+
### `pause(): void`
151+
152+
- MDN: [MediaRecorder.pause()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/pause)
153+
154+
### `resume(): void`
155+
156+
- MDN: [MediaRecorder.resume()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/resume)
157+
158+
### `stop(): void`
159+
160+
- MDN: [MediaRecorder.stop()](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/stop)

src/useMediaRecorder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function useMediaRecorder(options: UseMediaRecorderOptions = {}) {
111111
state,
112112
isSupported,
113113
isMimeTypeSupported,
114-
mimeType,
114+
mimeType: computed(()=> mimeType.value),
115115
mediaRecorder: computed(() => mediaRecorder.value),
116116
}
117117
}

0 commit comments

Comments
 (0)