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.
- Loading branch information
Showing
9 changed files
with
247 additions
and
41 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 was deleted.
Oops, something went wrong.
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,64 @@ | ||
<script setup> | ||
import { useMediaRecorder } from '@orbisk/vue-use-media-recorder' | ||
import { computed } from 'vue' | ||
const { | ||
data, | ||
start, | ||
stop, | ||
pause, | ||
resume, | ||
state, | ||
} = useMediaRecorder({ constraints: { audio: true, video: true } }) | ||
const length = computed(() => { | ||
return data.value.length ?? 0 | ||
}) | ||
const startBtnText = computed(() => { | ||
switch (state.value) { | ||
case 'recording': | ||
return 'Pause' | ||
case 'paused': | ||
return 'Resume' | ||
default: | ||
return 'Start' | ||
} | ||
}) | ||
function handleStartClick() { | ||
switch (state.value) { | ||
case 'recording': | ||
pause() | ||
break | ||
case 'paused': | ||
resume() | ||
break | ||
default: | ||
start() | ||
} | ||
} | ||
const audio = computed(() => { | ||
if (!data.value?.length || state.value !== 'inactive') | ||
return | ||
const blob = new Blob(data.value) | ||
return URL.createObjectURL(blob) | ||
}) | ||
</script> | ||
<template> | ||
<div style="display: flex; flex-direction: column"> | ||
<button style="border-radius: 5px; background-color: greenyellow; color: black" @click="handleStartClick"> | ||
{{ startBtnText }} | ||
</button> | ||
<button style="border-radius: 5px; background-color: orangered; color: white" @click="stop"> | ||
Stop | ||
</button> | ||
<pre>state: {{ state ? state : 'undefined (no interaction)' }}</pre> | ||
<pre>recorded data (array length): {{ length }}</pre> | ||
<audio v-if="audio" controls> | ||
<source :src="audio"> | ||
</audio> | ||
</div> | ||
</template> |
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# Examples | ||
|
||
## Basic Example | ||
|
||
This is a basic example of how to use the `<script setup>` syntax in a Vue component. | ||
|
||
|
||
<script setup> | ||
import BasicExample from './basic-example.vue' | ||
import TimesliceExample from './timeslice-example.vue' | ||
</script> | ||
|
||
<BasicExample /> | ||
|
||
### Code | ||
|
||
<<< @/basic-example.vue | ||
|
||
|
||
## Set timeslice | ||
|
||
You can control the timeslice of the data Blob creation. See [ | ||
`MediaRecorder.start(timeslice)`](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/start#syntax) for more | ||
information. The default value is `undefined` (this means that the timeslice is not set -> `data.value` will be set when | ||
stopping). | ||
|
||
<TimesliceExample /> | ||
|
||
|
||
<<< @/timeslice-example.vue {40} |
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,21 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# Installation | ||
|
||
## Install the package | ||
|
||
```bash | ||
pnpm add -D @orbisk/vue-use-media-recorder | ||
``` | ||
|
||
### Nuxt | ||
|
||
- Auto import for Nuxt is supported. Just add the module to your `nuxt.config`: | ||
|
||
```ts | ||
export default defineNuxtConfig({ | ||
modules: ['@orbisk/vue-use-media-recorder/nuxt'] | ||
}) | ||
``` |
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,70 @@ | ||
<script setup> | ||
import { useMediaRecorder } from '@orbisk/vue-use-media-recorder' | ||
import { computed, ref } from 'vue' | ||
const { | ||
data, | ||
start, | ||
stop, | ||
pause, | ||
resume, | ||
state, | ||
} = useMediaRecorder({ constraints: { audio: true, video: true } }) | ||
const timeslice = ref(1000) | ||
const length = computed(() => { | ||
return data.value.length ?? 0 | ||
}) | ||
const startBtnText = computed(() => { | ||
switch (state.value) { | ||
case 'recording': | ||
return 'Pause' | ||
case 'paused': | ||
return 'Resume' | ||
default: | ||
return 'Start' | ||
} | ||
}) | ||
function handleStartClick() { | ||
switch (state.value) { | ||
case 'recording': | ||
pause() | ||
break | ||
case 'paused': | ||
resume() | ||
break | ||
default: | ||
start(timeslice.value) | ||
} | ||
} | ||
const audio = computed(() => { | ||
if (!data.value?.length || state.value !== 'inactive') | ||
return | ||
const blob = new Blob(data.value) | ||
return URL.createObjectURL(blob) | ||
}) | ||
</script> | ||
<template> | ||
<div style="display: flex; flex-direction: column"> | ||
<label for="timeslice"> | ||
Timeslice (ms): | ||
<input id="timeslice" type="number" v-model="timeslice"/> | ||
</label> | ||
<button style="border-radius: 5px; background-color: greenyellow; color: black" @click="handleStartClick"> | ||
{{ startBtnText }} | ||
</button> | ||
<button style="border-radius: 5px; background-color: orangered; color: white" @click="stop"> | ||
Stop | ||
</button> | ||
<pre>state: {{ state ? state : 'undefined (no interaction)' }}</pre> | ||
<pre>recorded data (array length): {{ length }}</pre> | ||
<audio v-if="audio" controls> | ||
<source :src="audio"> | ||
</audio> | ||
</div> | ||
</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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
outline: deep | ||
--- | ||
|
||
# Usage | ||
|
||
```vue | ||
<script setup> | ||
import { useMediaRecorder } from '@orbisk/vue-use-media-recorder' | ||
const { | ||
data, | ||
stream, | ||
start, | ||
pause, | ||
resume, | ||
stop, | ||
state, | ||
isSupported, | ||
isMimeTypeSupported, | ||
mimeType, | ||
mediaRecorder, | ||
} = useMediaRecorder({constraints: {audio: true, video: true}}) | ||
start() | ||
</script> | ||
``` | ||
|