useRecordService.uts 980 Bytes
/**
 * 录音服务 Composable Hook
 * 提供响应式的录音服务访问方式
 * 
 * 使用方式:
 * const { recordService, isRecording } = useRecordService()
 */

import { computed, type ComputedRef } from "vue";
import { RecordService } from "@/services/recorder/RecordService.uts";

/**
 * 录音服务返回值类型
 */
class UseRecordServiceResult {
	recordService: RecordService;
	isRecording: ComputedRef<boolean>;
	
	constructor(recordService: RecordService, isRecording: ComputedRef<boolean>) {
		this.recordService = recordService;
		this.isRecording = isRecording;
	}
}

/**
 * 获取录音服务实例
 * @returns 录音服务单例
 */
export function useRecordService(): UseRecordServiceResult {
	const recordService = RecordService.getInstance();
	
	// 响应式计算属性:是否正在录音
	const isRecording = computed((): boolean => {
		return recordService.isReceptioning();
	});
	
	return new UseRecordServiceResult(recordService, isRecording);
}