Skip to content

Commit

Permalink
docs: add vitepress docs content
Browse files Browse the repository at this point in the history
  • Loading branch information
OrbisK committed Nov 26, 2024
1 parent 88cdacc commit bdcfb7f
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 41 deletions.
20 changes: 14 additions & 6 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from 'vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: '@orbisk/vue-use-media-recorder',
title: 'Vue Use Media Recorder',
description: 'A Vue Composable for MediaRecorder API',
vite: {
resolve: {
Expand All @@ -19,20 +19,28 @@ export default defineConfig({
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Home', link: '/' },
{ text: 'Examples', link: '/api-examples' },
{ text: 'Installation', link: '/installation' },
{ text: 'Usage', link: '/usage' },
{ text: 'Examples', link: '/examples' },
],

sidebar: [
{
text: 'Installation',
link: '/installation',
},
{
text: 'Usage',
link: '/usage',
},
{
text: 'Examples',
items: [
{ text: 'Runtime API Examples', link: '/api-examples' },
],
link: '/examples',
},
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
{ icon: 'github', link: 'https://github.com/OrbisK/vue-use-media-recorder' },
],
},
})
15 changes: 0 additions & 15 deletions docs/api-examples.md

This file was deleted.

64 changes: 64 additions & 0 deletions docs/basic-example.vue
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>
8 changes: 0 additions & 8 deletions docs/example.vue

This file was deleted.

34 changes: 34 additions & 0 deletions docs/examples.md
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}
27 changes: 15 additions & 12 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
layout: home

hero:
name: "vue-composable-starter"
text: "A Vue Composable"
tagline: My great project tagline
name: "@orbisk/vue-use-media-recorder"
text: "A Vue Composable for the MediaRecorder API"
actions:
- theme: brand
text: API Examples
link: /api-examples
text: Installation
link: /installtion
- theme: secondary
text: Usage
link: /usage

features:
- title: Feature A
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature B
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature C
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit

#features:
# - title: Feature A
# details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
# - title: Feature B
# details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
# - title: Feature C
# details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
---
21 changes: 21 additions & 0 deletions docs/installation.md
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']
})
```
70 changes: 70 additions & 0 deletions docs/timeslice-example.vue
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>
29 changes: 29 additions & 0 deletions docs/usage.md
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>
```

0 comments on commit bdcfb7f

Please sign in to comment.