diff --git a/demo/src/useTethr.ts b/demo/src/useTethr.ts index 3af08ee..7038656 100644 --- a/demo/src/useTethr.ts +++ b/demo/src/useTethr.ts @@ -12,23 +12,23 @@ import {reactive, readonly, Ref, ref, shallowRef, watch} from 'vue' const TransparentPng = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=' -export interface TethrConfig { +export interface TethrConfig { writable: boolean value: T | null update: (value: T) => void option?: ConfigDescOption } -export function useTethrConfig( +export function useTethrConfig( camera: Ref, - name: Name + name: N ) { const config = reactive({ writable: false, value: null, update: () => null, option: undefined, - }) as TethrConfig + }) as TethrConfig watch( camera, @@ -46,11 +46,9 @@ export function useTethrConfig( config.value = desc.value config.option = desc.option - config.update = async (value: any) => { - cam.set(name, value) - } + config.update = (value: ConfigType[N]) => cam.set(name, value) - cam.on(`${name}Changed` as any, (desc: ConfigDesc) => { + cam.on(`${name}Changed` as any, (desc: ConfigDesc) => { config.value = desc.value config.writable = desc.writable config.option = desc.option @@ -64,8 +62,11 @@ export function useTethrConfig( export function useTethr(onSave: (object: TethrObject) => void) { const camera = shallowRef(null) + const liveviewMediaStream = ref(null) + const photoURL = ref(TransparentPng) + async function toggleCameraConnection() { if (camera.value && camera.value.opened) { await camera.value.close() @@ -95,8 +96,8 @@ export function useTethr(onSave: (object: TethrObject) => void) { liveviewMediaStream.value = ms }) } - ;(window as any).cam = camera.value } + async function takePhoto() { if (!camera.value) return const result = await camera.value.takePhoto() @@ -109,9 +110,11 @@ export function useTethr(onSave: (object: TethrObject) => void) { } } } + async function runAutoFocus() { await camera.value?.runAutoFocus() } + async function toggleLiveview() { if (!camera.value) return const enabled = await camera.value.get('liveviewEnabled') @@ -125,6 +128,7 @@ export function useTethr(onSave: (object: TethrObject) => void) { } } } + return { camera, // DPC