import { ref } from 'vue'; import { AudioPlayBackDevice } from '@trtc/call-engine-lite-wx'; import { TUIStore, StoreName, TUICallKitServer, NAME, } from './TUICallService/index'; import { DeviceStatus } from '../constants/call'; const microphoneStatus = ref(DeviceStatus.OFF); const cameraStatus = ref(DeviceStatus.OFF); const isFrontCamera = ref(true); const currentAudioRoute = ref(AudioPlayBackDevice.EAR); // const localVideoQuality = ref(); const openLocalCamera = async () => await TUICallKitServer.openCamera('localVideo'); const closeLocalCamera = async () => await TUICallKitServer.closeCamera(); const switchCamera = async () => await TUICallKitServer.switchCamera(); const openLocalMicrophone = async () => await TUICallKitServer.openMicrophone(); const closeLocalMicrophone = async () => await TUICallKitServer.closeMicrophone(); const setAudioRoute = async () => await TUICallKitServer.setSoundMode(); TUIStore?.watch(StoreName.CALL, { [NAME.CAMERA_POSITION]: _handleCameraPositionChange, [NAME.IS_EAR_PHONE]: _handleIsEarPhoneChange, }); function _handleCameraPositionChange(value: boolean) { isFrontCamera.value = value; } function _handleIsEarPhoneChange(value: boolean) { currentAudioRoute.value = value ? AudioPlayBackDevice.EAR : AudioPlayBackDevice.SPEAKER; } function useDeviceState() { return { // state microphoneStatus, cameraStatus, // localVideoQuality, isFrontCamera, currentAudioRoute, // captureVolume, // networkInfo, // actions openLocalMicrophone, closeLocalMicrophone, openLocalCamera, closeLocalCamera, switchCamera, setAudioRoute, }; } export { useDeviceState };