generated from OrbisK/vue-composable-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
UseMediaRecorder
component
- Loading branch information
Showing
13 changed files
with
406 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
<template> | ||
<ClientOnly> | ||
<RecorderDemo /> | ||
<RecorderDemoComponent /> | ||
</ClientOnly> | ||
</template> |
40 changes: 40 additions & 0 deletions
40
playgrounds/nuxt/app/components/recorder-demo-component.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script setup lang="ts"> | ||
// import { UseMediaRecorder} from '@orbisk/vue-use-media-recorder' // TODO: why? | ||
// function handleStop() { | ||
// stop() | ||
// const blob = new Blob(data.value) | ||
// const blobVideo = new Blob(data.value) | ||
// audio.value.src = URL.createObjectURL(blob) | ||
// video.value.src = URL.createObjectURL(blobVideo) | ||
// } | ||
const stopped = ref(false) | ||
</script> | ||
|
||
<template> | ||
<UseMediaRecorder :constraints="{ audio: true }" @stop="stopped = true" @start="stopped = false"> | ||
<template #default="slotProps"> | ||
<button @click="() => slotProps.start()"> | ||
start | ||
</button> | ||
<button @click="slotProps.pause"> | ||
pause | ||
</button> | ||
<button @click="slotProps.resume"> | ||
resume | ||
</button> | ||
<button @click="slotProps.stop"> | ||
stop | ||
</button> | ||
<audio controls> | ||
<source v-if="stopped" :src="URL.createObjectURL(new Blob(slotProps.data))"> | ||
</audio> | ||
<pre>state: {{ slotProps.state }}</pre> | ||
<pre>supported: {{ slotProps.isSupported }}</pre> | ||
<pre>mime type: {{ slotProps.mimeType }}</pre> | ||
<pre>mime supported: {{ slotProps.isMimeTypeSupported }}</pre> | ||
<pre>data length: {{ slotProps.data?.length }}</pre> | ||
</template> | ||
</UseMediaRecorder> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script setup lang="ts"> | ||
import { useMediaRecorder } from '@orbisk/vue-use-media-recorder' | ||
const props = defineProps({ | ||
constraints: { | ||
type: Object, | ||
required: true, | ||
validator(value: unknown): boolean { | ||
if (!value.audio && !value.video) { | ||
console.error('constraints must have at least one of audio or video') | ||
return false | ||
} | ||
}, | ||
}, | ||
mediaRecorderOptions: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
}) | ||
const emit = defineEmits<{ | ||
start: [ev: Event] | ||
stop: [ev: Event] | ||
pause: [ev: Event] | ||
resume: [ev: Event] | ||
error: [ev: Event] | ||
}>() | ||
const onStart = (...args) => emit('start', ...args) | ||
const onStop = (...args) => emit('stop', ...args) | ||
const onPause = (...args) => emit('pause', ...args) | ||
const onResume = (...args) => emit('resume', ...args) | ||
const onError = (...args) => emit('error', ...args) | ||
const { | ||
data, | ||
stream, | ||
mimeType, | ||
isSupported, | ||
isMimeTypeSupported, | ||
mediaRecorder, | ||
start, | ||
pause, | ||
resume, | ||
stop, | ||
state, | ||
} = useMediaRecorder({ constraints: props.constraints, mediaRecorderOptions: props.mediaRecorderOptions, onStart, onResume, onPause, onStop, onError }) | ||
defineExpose({ | ||
start, | ||
stop, | ||
resume, | ||
pause, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<slot | ||
:data="data" :stream="stream" :mime-type="mimeType" :media-recorder="mediaRecorder" :is-supported="isSupported" | ||
:is-mime-type-supported="isMimeTypeSupported" :state="state" :start="start" :stop="stop" :pause="pause" :resume="resume" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// Components | ||
// export { default as Toggle } from './components/Toggle.vue' | ||
export { default as UseMediaRecorder } from './components/UseMediaRecorder.vue' | ||
|
||
// Plugin | ||
export { default as MediaRecorderPlugin } from './plugin' | ||
|
||
// Types | ||
export type { MediaRecorderPluginOptions } from './types' | ||
|
||
// Composables | ||
export { useMediaRecorder } from './useMediaRecorder' | ||
|
||
// Types | ||
export type {MediaRecorderPluginOptions} from './types' | ||
export type {UseMediaRecorderReturn} from './useMediaRecorder' | ||
export type { UseMediaRecorderReturn } from './useMediaRecorder' |
Oops, something went wrong.