@@ -4,6 +4,8 @@ outline: deep
4
4
5
5
# Usage
6
6
7
+ ## ` useMediaRecorder `
8
+
7
9
``` vue
8
10
9
11
<script setup>
@@ -21,9 +23,138 @@ outline: deep
21
23
isMimeTypeSupported,
22
24
mimeType,
23
25
mediaRecorder,
24
- } = useMediaRecorder({constraints: {audio: true, video: true} })
25
-
26
+ } = useMediaRecorder({ constraints: { audio: true, video: true } })
27
+
26
28
start()
27
29
</script>
28
30
```
29
31
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 )
0 commit comments