| 1 | <script setup lang="ts"> |
| 2 | import { useLocalStorage } from '@vueuse/core' |
| 3 | import { onMounted, watch } from 'vue' |
| 4 | import { recorder } from '../logic/recording' |
| 5 | import { currentCamera, showRecordingDialog } from '../state' |
| 6 | import DevicesSelectors from './DevicesSelectors.vue' |
| 7 | import IconButton from './IconButton.vue' |
| 8 | import MenuButton from './MenuButton.vue' |
| 9 | |
| 10 | const { |
| 11 | recording, |
| 12 | showAvatar, |
| 13 | streamCamera, |
| 14 | stopRecording, |
| 15 | toggleAvatar, |
| 16 | } = recorder |
| 17 | |
| 18 | const previousAvatar = useLocalStorage('slidev-webcam-show', false) |
| 19 | watch(showAvatar, () => { |
| 20 | previousAvatar.value = showAvatar.value |
| 21 | }) |
| 22 | |
| 23 | function toggleRecording() { |
| 24 | if (recording.value) |
| 25 | stopRecording() |
| 26 | else |
| 27 | showRecordingDialog.value = true |
| 28 | } |
| 29 | |
| 30 | onMounted(() => { |
| 31 | if (previousAvatar.value && !showAvatar.value) |
| 32 | toggleAvatar() |
| 33 | }) |
| 34 | </script> |
| 35 | |
| 36 | <template> |
| 37 | <IconButton |
| 38 | v-if="currentCamera !== 'none'" |
| 39 | class="<md:hidden" |
| 40 | :class="{ 'text-green-500': Boolean(showAvatar && streamCamera) }" |
| 41 | title="Toggle camera view" |
| 42 | @click="toggleAvatar" |
| 43 | > |
| 44 | <div class="i-carbon:user-avatar" /> |
| 45 | </IconButton> |
| 46 | |
| 47 | <IconButton |
| 48 | :class="{ 'text-red-500': recording }" |
| 49 | :title="recording ? 'Stop record video' : 'Record video'" |
| 50 | @click="toggleRecording" |
| 51 | > |
| 52 | <div v-if="recording" class="i-carbon:stop-outline" /> |
| 53 | <div v-else class="i-carbon:video" /> |
| 54 | </IconButton> |
| 55 | <MenuButton :disabled="recording"> |
| 56 | <template #button> |
| 57 | <IconButton title="Select recording device" class="h-full !text-sm !px-0 aspect-initial"> |
| 58 | <div class="i-carbon:chevron-up opacity-50" /> |
| 59 | </IconButton> |
| 60 | </template> |
| 61 | <template #menu> |
| 62 | <DevicesSelectors /> |
| 63 | </template> |
| 64 | </MenuButton> |
| 65 | </template> |
| 66 |